#29-add-admin-role #2
1 changed files with 20 additions and 21 deletions
|
@ -30,39 +30,38 @@ def hydra_callback():
|
|||
token = HydraOauth.get_token(state, code)
|
||||
user_info = HydraOauth.get_user_info()
|
||||
# Match Kratos identity with Hydra
|
||||
# identities = KratosApi.get("/identities")
|
||||
# identity = None
|
||||
# for i in identities.json():
|
||||
# if i["traits"]["email"] == user_info["email"]:
|
||||
# identity = i
|
||||
identities = KratosApi.get("/identities")
|
||||
identity = None
|
||||
for i in identities.json():
|
||||
if i["traits"]["email"] == user_info["email"]:
|
||||
identity = i
|
||||
|
||||
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), additional_claims={"user_id": identity["id"]}
|
||||
)
|
||||
|
||||
# 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
|
||||
# ).first()
|
||||
# app_roles.append(
|
||||
# {
|
||||
# "name": app.slug,
|
||||
# "role_id": tmp_app_role.role_id if tmp_app_role else None,
|
||||
# }
|
||||
# )
|
||||
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
|
||||
).first()
|
||||
app_roles.append(
|
||||
{
|
||||
"name": app.slug,
|
||||
"role_id": tmp_app_role.role_id if tmp_app_role else None,
|
||||
}
|
||||
)
|
||||
|
||||
return jsonify(
|
||||
{
|
||||
"accessToken": access_token,
|
||||
"userInfo": {
|
||||
"id": user_info["email"],
|
||||
"id": identity["id"],
|
||||
"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