Return role_id when callback is called
This commit is contained in:
parent
932f3c4fcb
commit
3c8c900d2c
2 changed files with 12 additions and 0 deletions
|
@ -4,6 +4,7 @@ from flask_cors import cross_origin
|
|||
from datetime import timedelta
|
||||
|
||||
from areas import api_v1
|
||||
from areas.apps import AppRole
|
||||
from config import *
|
||||
from helpers import HydraOauth, BadRequest, KratosApi
|
||||
|
||||
|
@ -39,6 +40,8 @@ def hydra_callback():
|
|||
identity=token, expires_delta=timedelta(days=365)
|
||||
)
|
||||
|
||||
app_role = AppRole.query.filter_by(user_id=identity["id"]).first()
|
||||
|
||||
return jsonify(
|
||||
{
|
||||
"accessToken": access_token,
|
||||
|
@ -47,6 +50,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,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
|
|
@ -51,6 +51,14 @@ class UserService:
|
|||
if app_role:
|
||||
app_role.role_id = data["role_id"] if "role_id" in data else None
|
||||
db.session.commit()
|
||||
else:
|
||||
appRole = AppRole(
|
||||
user_id=id,
|
||||
role_id=data["role_id"] if "role_id" in data else None,
|
||||
app_id=1,
|
||||
)
|
||||
db.session.add(appRole)
|
||||
db.session.commit()
|
||||
|
||||
return UserService.get_user(id)
|
||||
|
||||
|
|
Loading…
Reference in a new issue