#29-add-admin-role #2
2 changed files with 14 additions and 11 deletions
|
@ -1,7 +1,7 @@
|
|||
"""Everything to do with Apps"""
|
||||
|
||||
from database import db
|
||||
from .models import App
|
||||
from .models import App, AppRole
|
||||
|
||||
class LITApp(App):
|
||||
"""
|
||||
|
@ -29,4 +29,4 @@ class LITApp(App):
|
|||
"installed": "",
|
||||
"ready": "",
|
||||
"message": "",
|
||||
}
|
||||
}
|
|
@ -30,17 +30,21 @@ def hydra_callback():
|
|||
|
||||
token = HydraOauth.get_token(state, code)
|
||||
user_info = HydraOauth.get_user_info()
|
||||
|
||||
access_token = create_access_token(
|
||||
identity=token, expires_delta=timedelta(days=365),
|
||||
#additional_claims={"user_id": identity["id"]}
|
||||
)
|
||||
identity=token, expires_delta=timedelta(days=365))
|
||||
|
||||
isAdmin = "admin" in user_info["groups"]
|
||||
app_roles = [
|
||||
{
|
||||
"name": "dashboard",
|
||||
"role_id": 1 if isAdmin else 2
|
||||
},
|
||||
]
|
||||
print(app_roles)
|
||||
# apps = App.query.all()
|
||||
# app_roles = []
|
||||
# for app in apps:
|
||||
# tmp_app_role = AppRole.query.filter_by(
|
||||
# user_id=identity["id"], app_id=app.id
|
||||
# user_id=user_info["sub"], app_id=app.id
|
||||
# ).first()
|
||||
# app_roles.append(
|
||||
# {
|
||||
|
@ -48,7 +52,6 @@ def hydra_callback():
|
|||
# "role_id": tmp_app_role.role_id if tmp_app_role else None,
|
||||
# }
|
||||
# )
|
||||
|
||||
return jsonify(
|
||||
{
|
||||
"accessToken": access_token,
|
||||
|
@ -57,7 +60,7 @@ def hydra_callback():
|
|||
"email": user_info["email"],
|
||||
"name": user_info["name"],
|
||||
"preferredUsername": user_info["preferred_username"],
|
||||
# "app_roles": app_roles,
|
||||
},
|
||||
"app_roles": app_roles
|
||||
}
|
||||
}
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue