Skip to content
Snippets Groups Projects
Commit c483ef6a authored by Luka's avatar Luka
Browse files

Add Kratos user id to Hydra callback response

parent 4a82c8f2
No related branches found
No related tags found
No related merge requests found
......@@ -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"],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment