Add Kratos user id to Hydra callback response

This commit is contained in:
Luka Radenovic 2022-02-10 13:04:54 +01:00
parent 4a82c8f224
commit c483ef6a4d

View file

@ -5,7 +5,7 @@ from datetime import timedelta
from areas import api_v1
from config import *
from helpers import HydraOauth, BadRequest
from helpers import HydraOauth, BadRequest, KratosApi
@api_v1.route("/login", methods=["POST"])
@ -28,6 +28,12 @@ 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
access_token = create_access_token(
identity=token, expires_delta=timedelta(days=365)
@ -37,6 +43,7 @@ def hydra_callback():
{
"accessToken": access_token,
"userInfo": {
"id": identity["id"],
"email": user_info["email"],
"name": user_info["name"],
"preferredUsername": user_info["preferred_username"],