@@ -41,14 +41,6 @@ def __init__(
4141 self .resources = resources
4242
4343
44- GRANT_TYPE_MAP = {
45- "authorization_code" : "code" ,
46- "access_token" : "access_token" ,
47- "refresh_token" : "refresh_token" ,
48- "id_token" : "id_token" ,
49- }
50-
51-
5244def find_token (issued , token_id ):
5345 for iss in issued :
5446 if iss .id == token_id :
@@ -179,12 +171,17 @@ def payload_arguments(
179171 self ,
180172 session_id : str ,
181173 endpoint_context ,
182- token_type : str ,
174+ claims_release_ref : str ,
183175 scope : Optional [dict ] = None ,
184176 extra_payload : Optional [dict ] = None ,
185177 ) -> dict :
186178 """
187179
180+ :param session_id:
181+ :param endpoint_context:
182+ :param claims_release_ref: One of "userinfo", "introspection", "id_token", "access_token"
183+ :param scope:
184+ :param extra_payload:
188185 :return: dictionary containing information to place in a token value
189186 """
190187 if not scope :
@@ -205,7 +202,7 @@ def payload_arguments(
205202 payload .update ({"client_id" : client_id , "sub" : client_id })
206203
207204 _claims_restriction = endpoint_context .claims_interface .get_claims (
208- session_id , scopes = scope , usage = token_type
205+ session_id , scopes = scope , claims_release_ref = claims_release_ref
209206 )
210207 user_id , _ , _ = endpoint_context .session_manager .decrypt_session_id (session_id )
211208 user_info = endpoint_context .claims_interface .get_user_claims (user_id , _claims_restriction )
@@ -217,7 +214,7 @@ def mint_token(
217214 self ,
218215 session_id : str ,
219216 endpoint_context : object ,
220- token_type : str ,
217+ token_class : str ,
221218 token_handler : TokenHandler = None ,
222219 based_on : Optional [SessionToken ] = None ,
223220 usage_rules : Optional [dict ] = None ,
@@ -240,42 +237,46 @@ def mint_token(
240237 return None
241238
242239 if based_on :
243- if based_on .supports_minting (token_type ) is False :
244- raise MintingNotAllowed (f"Minting of { token_type } not supported" )
240+ if based_on .supports_minting (token_class ) is False :
241+ raise MintingNotAllowed (f"Minting of { token_class } not supported" )
245242 if not based_on .is_active ():
246243 raise MintingNotAllowed ("Token inactive" )
247244 _base_on_ref = based_on .value
248245 else :
249246 _base_on_ref = None
250247
251- if usage_rules is None and token_type in self .usage_rules :
252- usage_rules = self .usage_rules [token_type ]
248+ if usage_rules is None and token_class in self .usage_rules :
249+ usage_rules = self .usage_rules [token_class ]
253250
254- token_class = self .token_map .get (token_type )
255- if token_type == "id_token" :
251+ _class = self .token_map .get (token_class )
252+ if token_class == "id_token" :
256253 class_args = {k : v for k , v in kwargs .items () if k not in ["code" , "access_token" ]}
257254 handler_args = {k : v for k , v in kwargs .items () if k in ["code" , "access_token" ]}
258255 else :
259256 class_args = kwargs
260257 handler_args = {}
261258
262- if token_class :
263- item = token_class (
264- type = token_type ,
259+ if _class :
260+ item = _class (
261+ token_class = token_class ,
265262 based_on = _base_on_ref ,
266263 usage_rules = usage_rules ,
267264 scope = scope ,
268265 ** class_args ,
269266 )
270267 if token_handler is None :
271- token_handler = endpoint_context .session_manager .token_handler .handler [
272- GRANT_TYPE_MAP [token_type ]
273- ]
268+ token_handler = endpoint_context .session_manager .token_handler .handler [token_class ]
269+
270+ # Only access_token and id_token can give rise to claims release
271+ if token_class in ["access_token" , "id_token" ]:
272+ claims_release_ref = token_class
273+ else :
274+ claims_release_ref = ""
274275
275276 token_payload = self .payload_arguments (
276277 session_id ,
277278 endpoint_context ,
278- token_type = token_type ,
279+ claims_release_ref = claims_release_ref ,
279280 scope = scope ,
280281 extra_payload = handler_args ,
281282 )
0 commit comments