Add app roles to userInfo when logging in
This commit is contained in:
parent
61e512c208
commit
bc85575e9b
1 changed files with 14 additions and 3 deletions
|
@ -4,7 +4,7 @@ from flask_cors import cross_origin
|
|||
from datetime import timedelta
|
||||
|
||||
from areas import api_v1
|
||||
from areas.apps import AppRole
|
||||
from areas.apps import AppRole, App
|
||||
from config import *
|
||||
from helpers import HydraOauth, BadRequest, KratosApi
|
||||
|
||||
|
@ -40,7 +40,18 @@ def hydra_callback():
|
|||
identity=token, expires_delta=timedelta(days=365)
|
||||
)
|
||||
|
||||
app_role = AppRole.query.filter_by(user_id=identity["id"]).first()
|
||||
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(
|
||||
{
|
||||
|
@ -50,7 +61,7 @@ def hydra_callback():
|
|||
"email": user_info["email"],
|
||||
"name": user_info["name"],
|
||||
"preferredUsername": user_info["preferred_username"],
|
||||
"role_id": app_role.role_id if app_role else None,
|
||||
"app_roles": app_roles,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue