Add Kratos user id to Hydra callback response
This commit is contained in:
parent
4a82c8f224
commit
c483ef6a4d
1 changed files with 8 additions and 1 deletions
|
@ -5,7 +5,7 @@ from datetime import timedelta
|
||||||
|
|
||||||
from areas import api_v1
|
from areas import api_v1
|
||||||
from config import *
|
from config import *
|
||||||
from helpers import HydraOauth, BadRequest
|
from helpers import HydraOauth, BadRequest, KratosApi
|
||||||
|
|
||||||
|
|
||||||
@api_v1.route("/login", methods=["POST"])
|
@api_v1.route("/login", methods=["POST"])
|
||||||
|
@ -28,6 +28,12 @@ def hydra_callback():
|
||||||
|
|
||||||
token = HydraOauth.get_token(state, code)
|
token = HydraOauth.get_token(state, code)
|
||||||
user_info = HydraOauth.get_user_info()
|
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(
|
access_token = create_access_token(
|
||||||
identity=token, expires_delta=timedelta(days=365)
|
identity=token, expires_delta=timedelta(days=365)
|
||||||
|
@ -37,6 +43,7 @@ def hydra_callback():
|
||||||
{
|
{
|
||||||
"accessToken": access_token,
|
"accessToken": access_token,
|
||||||
"userInfo": {
|
"userInfo": {
|
||||||
|
"id": identity["id"],
|
||||||
"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"],
|
||||||
|
|
Loading…
Reference in a new issue