Return role_id when callback is called

This commit is contained in:
Luka Radenovic 2022-04-15 12:44:30 +02:00
parent 932f3c4fcb
commit 3c8c900d2c
2 changed files with 12 additions and 0 deletions

View file

@ -4,6 +4,7 @@ from flask_cors import cross_origin
from datetime import timedelta from datetime import timedelta
from areas import api_v1 from areas import api_v1
from areas.apps import AppRole
from config import * from config import *
from helpers import HydraOauth, BadRequest, KratosApi from helpers import HydraOauth, BadRequest, KratosApi
@ -39,6 +40,8 @@ def hydra_callback():
identity=token, expires_delta=timedelta(days=365) identity=token, expires_delta=timedelta(days=365)
) )
app_role = AppRole.query.filter_by(user_id=identity["id"]).first()
return jsonify( return jsonify(
{ {
"accessToken": access_token, "accessToken": access_token,
@ -47,6 +50,7 @@ def hydra_callback():
"email": user_info["email"], "email": user_info["email"],
"name": user_info["name"], "name": user_info["name"],
"preferredUsername": user_info["preferred_username"], "preferredUsername": user_info["preferred_username"],
"role_id": app_role.role_id if app_role else None,
}, },
} }
) )

View file

@ -51,6 +51,14 @@ class UserService:
if app_role: if app_role:
app_role.role_id = data["role_id"] if "role_id" in data else None app_role.role_id = data["role_id"] if "role_id" in data else None
db.session.commit() 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) return UserService.get_user(id)