@@ -38,7 +38,7 @@ def __init__(self, salt: Optional[str] = "", filename: Optional[str] = ""):
3838 if os .path .isfile (filename ):
3939 self .salt = open (filename ).read ()
4040 elif not os .path .isfile (filename ) and os .path .exists (
41- filename
41+ filename
4242 ): # Not a file, Something else
4343 raise ConfigurationError ("Salt filename points to something that is not a file" )
4444 else :
@@ -73,8 +73,10 @@ class SessionManager(Database):
7373 init_args = ["handler" ]
7474
7575 def __init__ (
76- self , handler : TokenHandler , conf : Optional [dict ] = None , sub_func : Optional [dict ] = None ,
76+ self , handler : TokenHandler , conf : Optional [dict ] = None ,
77+ sub_func : Optional [dict ] = None ,
7778 ):
79+ super (SessionManager , self ).__init__ ()
7880 self .conf = conf or {}
7981
8082 # these won't change runtime
@@ -125,9 +127,9 @@ def __setattr__(self, key, value):
125127
126128 def _init_db (self ):
127129 Database .__init__ (
128- self ,
129- key = self .load_key (),
130- salt = self .load_salt ()
130+ self ,
131+ key = self .load_key (),
132+ salt = self .load_salt ()
131133 )
132134
133135 def get_user_info (self , uid : str ) -> UserSessionInfo :
@@ -153,14 +155,14 @@ def find_token(self, session_id: str, token_value: str) -> Optional[SessionToken
153155 return None # pragma: no cover
154156
155157 def create_grant (
156- self ,
157- authn_event : AuthnEvent ,
158- auth_req : AuthorizationRequest ,
159- user_id : str ,
160- client_id : Optional [str ] = "" ,
161- sub_type : Optional [str ] = "public" ,
162- token_usage_rules : Optional [dict ] = None ,
163- scopes : Optional [list ] = None ,
158+ self ,
159+ authn_event : AuthnEvent ,
160+ auth_req : AuthorizationRequest ,
161+ user_id : str ,
162+ client_id : Optional [str ] = "" ,
163+ sub_type : Optional [str ] = "public" ,
164+ token_usage_rules : Optional [dict ] = None ,
165+ scopes : Optional [list ] = None ,
164166 ) -> str :
165167 """
166168
@@ -175,29 +177,31 @@ def create_grant(
175177 """
176178 sector_identifier = auth_req .get ("sector_identifier_uri" , "" )
177179
180+ _claims = auth_req .get ("claims" , {})
181+
178182 grant = Grant (
179183 authorization_request = auth_req ,
180184 authentication_event = authn_event ,
181- sub = self .sub_func [sub_type ](
182- user_id , salt = self .salt , sector_identifier = sector_identifier
183- ),
185+ sub = self .sub_func [sub_type ](user_id , salt = self .salt ,
186+ sector_identifier = sector_identifier ),
184187 usage_rules = token_usage_rules ,
185188 scope = scopes ,
189+ claims = _claims
186190 )
187191
188192 self .set ([user_id , client_id , grant .id ], grant )
189193
190194 return self .encrypted_session_id (user_id , client_id , grant .id )
191195
192196 def create_session (
193- self ,
194- authn_event : AuthnEvent ,
195- auth_req : AuthorizationRequest ,
196- user_id : str ,
197- client_id : Optional [str ] = "" ,
198- sub_type : Optional [str ] = "public" ,
199- token_usage_rules : Optional [dict ] = None ,
200- scopes : Optional [list ] = None ,
197+ self ,
198+ authn_event : AuthnEvent ,
199+ auth_req : AuthorizationRequest ,
200+ user_id : str ,
201+ client_id : Optional [str ] = "" ,
202+ sub_type : Optional [str ] = "public" ,
203+ token_usage_rules : Optional [dict ] = None ,
204+ scopes : Optional [list ] = None ,
201205 ) -> str :
202206 """
203207 Create part of a user session. The parts added are user- and client
@@ -309,10 +313,10 @@ def revoke_token(self, session_id: str, token_value: str, recursive: bool = Fals
309313 self ._revoke_dependent (grant , token )
310314
311315 def get_authentication_events (
312- self ,
313- session_id : Optional [str ] = "" ,
314- user_id : Optional [str ] = "" ,
315- client_id : Optional [str ] = "" ,
316+ self ,
317+ session_id : Optional [str ] = "" ,
318+ user_id : Optional [str ] = "" ,
319+ client_id : Optional [str ] = "" ,
316320 ) -> List [AuthnEvent ]:
317321 """
318322 Return the authentication events that exists for a user/client combination.
@@ -371,10 +375,10 @@ def revoke_grant(self, session_id: str):
371375 self .set (_path , _info )
372376
373377 def grants (
374- self ,
375- session_id : Optional [str ] = "" ,
376- user_id : Optional [str ] = "" ,
377- client_id : Optional [str ] = "" ,
378+ self ,
379+ session_id : Optional [str ] = "" ,
380+ user_id : Optional [str ] = "" ,
381+ client_id : Optional [str ] = "" ,
378382 ) -> List [Grant ]:
379383 """
380384 Find all grant connected to a user session
@@ -395,13 +399,13 @@ def grants(
395399 return [self .get ([user_id , client_id , gid ]) for gid in _csi .subordinate ]
396400
397401 def get_session_info (
398- self ,
399- session_id : str ,
400- user_session_info : bool = False ,
401- client_session_info : bool = False ,
402- grant : bool = False ,
403- authentication_event : bool = False ,
404- authorization_request : bool = False ,
402+ self ,
403+ session_id : str ,
404+ user_session_info : bool = False ,
405+ client_session_info : bool = False ,
406+ grant : bool = False ,
407+ authentication_event : bool = False ,
408+ authorization_request : bool = False ,
405409 ) -> dict :
406410 """
407411 Returns information connected to a session.
@@ -448,14 +452,21 @@ def get_session_info(
448452
449453 return res
450454
455+ def _compatible_sid (self , sid ):
456+ # To be backward compatible is this an old time sid
457+ p = self .unpack_session_key (sid )
458+ if len (p ) == 3 :
459+ sid = self .encrypted_session_id (* p )
460+ return sid
461+
451462 def get_session_info_by_token (
452- self ,
453- token_value : str ,
454- user_session_info : bool = False ,
455- client_session_info : bool = False ,
456- grant : bool = False ,
457- authentication_event : bool = False ,
458- authorization_request : bool = False ,
463+ self ,
464+ token_value : str ,
465+ user_session_info : bool = False ,
466+ client_session_info : bool = False ,
467+ grant : bool = False ,
468+ authentication_event : bool = False ,
469+ authorization_request : bool = False ,
459470 ) -> dict :
460471 _token_info = self .token_handler .info (token_value )
461472 sid = _token_info .get ("sid" )
@@ -464,6 +475,9 @@ def get_session_info_by_token(
464475 if not sid :
465476 raise WrongTokenClass
466477
478+ # To be backward compatible is this an old time sid
479+ sid = self ._compatible_sid (sid )
480+
467481 return self .get_session_info (
468482 sid ,
469483 user_session_info = user_session_info ,
@@ -475,7 +489,8 @@ def get_session_info_by_token(
475489
476490 def get_session_id_by_token (self , token_value : str ) -> str :
477491 _token_info = self .token_handler .info (token_value )
478- return _token_info ["sid" ]
492+ sid = _token_info .get ("sid" )
493+ return self ._compatible_sid (sid )
479494
480495 def add_grant (self , user_id : str , client_id : str , ** kwargs ) -> Grant :
481496 """
0 commit comments