@@ -47,11 +47,12 @@ def fetch_user_info(token: str) -> UserInfo:
4747 raise ValueError (f"Error communicating with IdP: { str (e )} " )
4848
4949
50- def create_or_update_user (idp_id : str , user_info : Dict ) -> User :
50+ def create_or_update_user (sub : str , iss : str , user_info : Dict ) -> User :
5151 """Create or update user record with information from IdP.
5252
5353 Args:
54- idp_id: Subject identifier from IdP
54+ sub: Subject identifier from IdP
55+ iss: Issuer identifier from IdP
5556 user_info: User information from IdP's UserInfo endpoint
5657
5758 Returns:
@@ -65,16 +66,18 @@ def create_or_update_user(idp_id: str, user_info: Dict) -> User:
6566 if not email :
6667 raise ValueError ("Email is required in UserInfo response from IdP" )
6768
68- user = Session .query (User ).filter_by (idp_id = idp_id ).one_or_none ()
69+ user = Session .query (User ).filter_by (idp_subject = sub , idp_issuer = iss ).one_or_none ()
6970
7071 if not user :
7172 user = Session .query (User ).filter_by (email = email ).one_or_none ()
7273 if user :
73- user .idp_id = idp_id
74+ user .idp_subject = sub
75+ user .idp_issuer = iss
7476 else :
7577 user_parameters = {
7678 "email" : email ,
77- "idp_id" : idp_id ,
79+ "idp_subject" : sub ,
80+ "idp_issuer" : iss ,
7881 "full_name" : user_info .get ("name" , email ),
7982 "username" : user_info .get ("preferred_username" , email ),
8083 }
@@ -90,12 +93,13 @@ def create_or_update_user(idp_id: str, user_info: Dict) -> User:
9093 raise ValueError (f"Error creating or updating user: { str (e )} " )
9194
9295
93- def create_or_update_user_from_idp (token : str , user_idp_id : str ) -> User :
96+ def create_or_update_user_from_idp (token : str , sub : str , iss : str ) -> User :
9497 """Create or update user record by fetching info from IdP.
9598
9699 Args:
97100 token: Access token to fetch user info
98- user_idp_id: Subject identifier from IdP (e.g., sub claim)
101+ sub: Subject identifier from IdP (e.g., sub claim)
102+ iss: Issuer identifier from IdP (e.g., iss claim)
99103
100104 Returns:
101105 User: Created or updated user record
@@ -105,6 +109,6 @@ def create_or_update_user_from_idp(token: str, user_idp_id: str) -> User:
105109 """
106110 try :
107111 user_info = fetch_user_info (token )
108- return create_or_update_user (user_idp_id , user_info )
112+ return create_or_update_user (sub , iss , user_info )
109113 except Exception as e :
110114 raise ValueError (f"Failed to create/update user: { str (e )} " )
0 commit comments