diff --git a/src/oidcop/session/grant.py b/src/oidcop/session/grant.py index 86c7915b..74f9be93 100644 --- a/src/oidcop/session/grant.py +++ b/src/oidcop/session/grant.py @@ -186,11 +186,23 @@ def payload_arguments( if not scope: scope = self.scope - payload = {"scope": scope, "aud": self.resources} + payload = { + "scope": scope, + "aud": self.resources, + "jti" : uuid1().hex + } if extra_payload: payload.update(extra_payload) + if self.authorization_request: + client_id = self.authorization_request.get('client_id') + if client_id: + payload.update({ + "client_id": client_id, + 'sub': client_id + }) + _claims_restriction = endpoint_context.claims_interface.get_claims( session_id, scopes=scope, usage=token_type ) @@ -262,19 +274,16 @@ def mint_token( ) if token_handler is None: token_handler = endpoint_context.session_manager.token_handler.handler[ - GRANT_TYPE_MAP[token_type] - ] - - item.value = token_handler( - session_id=session_id, - **self.payload_arguments( - session_id, - endpoint_context, - token_type=token_type, - scope=scope, - extra_payload=handler_args, - ), - ) + GRANT_TYPE_MAP[token_type]] + + token_payload = self.payload_arguments(session_id, + endpoint_context, + token_type=token_type, + scope=scope, + extra_payload=handler_args) + item.value = token_handler(session_id=session_id, + **token_payload) + else: raise ValueError("Can not mint that kind of token") diff --git a/src/oidcop/token/jwt_token.py b/src/oidcop/token/jwt_token.py index b64a7fdc..049e3f1e 100644 --- a/src/oidcop/token/jwt_token.py +++ b/src/oidcop/token/jwt_token.py @@ -44,9 +44,15 @@ def __init__( self.def_aud = aud or [] self.alg = alg - def __call__( - self, session_id: Optional[str] = "", ttype: Optional[str] = "", **payload - ) -> str: + def load_custom_claims(self, payload:dict={}): + # inherit me and do your things here + return payload + + def __call__(self, + session_id: Optional[str] = '', + ttype: Optional[str] = '', + **payload) -> str: + """ Return a token. @@ -61,7 +67,12 @@ def __call__( else: ttype = "A" - payload.update({"sid": session_id, "ttype": ttype}) + payload.update( + {"sid": session_id, + "ttype": ttype + } + ) + payload = self.load_custom_claims(payload) # payload.update(kwargs) _context = self.server_get("endpoint_context")