99from idpyoidc .message .oidc import AuthorizationRequest
1010from idpyoidc .server import Server
1111from idpyoidc .server .authn_event import create_authn_event
12+ from idpyoidc .server .authz import AuthzHandling
1213from idpyoidc .server .client_authn import verify_client
1314from idpyoidc .server .token .id_token import get_sign_and_encrypt_algorithms
1415from idpyoidc .server .user_authn .authn_context import INTERNETPROTOCOLPASSWORD
@@ -179,7 +180,7 @@ def create_session_manager(self):
179180 self .session_manager = self .context .session_manager
180181 self .user_id = USER_ID
181182
182- def _create_session (self , auth_req , sub_type = "public" , sector_identifier = "" , authn_info = "" ):
183+ def _create_session (self , auth_req , sub_type = "public" , sector_identifier = "" , authn_info = "" , token_usage_rules = "" ):
183184 if sector_identifier :
184185 authz_req = auth_req .copy ()
185186 authz_req ["sector_identifier_uri" ] = sector_identifier
@@ -189,7 +190,7 @@ def _create_session(self, auth_req, sub_type="public", sector_identifier="", aut
189190 client_id = authz_req ["client_id" ]
190191 ae = create_authn_event (self .user_id , authn_info = authn_info )
191192 return self .session_manager .create_session (
192- ae , authz_req , self .user_id , client_id = client_id , sub_type = sub_type
193+ ae , authz_req , self .user_id , client_id = client_id , sub_type = sub_type , token_usage_rules = token_usage_rules
193194 )
194195
195196 def _mint_code (self , grant , session_id ):
@@ -247,6 +248,58 @@ def test_id_token_payload_0(self):
247248 "sid" ,
248249 }
249250
251+ def test_id_token_lifetime_per_client (self ):
252+ grant_config = {
253+ "usage_rules" : {
254+ "authorization_code" : {
255+ "supports_minting" : [
256+ "access_token" ,
257+ "refresh_token" ,
258+ "id_token" ,
259+ ],
260+ "max_usage" : 1 ,
261+ "expires_in" : 120 ,
262+ },
263+ "access_token" : {"expires_in" : 600 },
264+ },
265+ "expires_in" : 43200 ,
266+ }
267+ self .context .cdb ["client_1" ]["token_usage_rules" ] = {
268+ "id_token" : {
269+ "expires_in" : 100
270+ }
271+ }
272+
273+ self .context .authz = AuthzHandling (
274+ self .server .get_endpoint_context , grant_config = grant_config
275+ )
276+
277+ token_usage_rules = self .context .authz .usage_rules ("client_1" )
278+ session_id = self ._create_session (auth_req = AREQ , token_usage_rules = token_usage_rules )
279+
280+ grant = self .session_manager [session_id ]
281+ code = self ._mint_code (grant , session_id )
282+ id_token = self ._mint_id_token (grant , session_id , code )
283+ _jwt = factory (id_token .value )
284+ payload = _jwt .jwt .payload ()
285+
286+ assert set (payload .keys ()) == {
287+ "aud" ,
288+ "sub" ,
289+ "auth_time" ,
290+ "nonce" ,
291+ "iat" ,
292+ "exp" ,
293+ "email" ,
294+ "email_verified" ,
295+ "jti" ,
296+ "scope" ,
297+ "client_id" ,
298+ "iss" ,
299+ "sid" ,
300+ }
301+ assert payload ["exp" ] - payload ["iat" ] == 100
302+
250303 def test_id_token_payload_with_code (self ):
251304 session_id = self ._create_session (AREQ )
252305 grant = self .session_manager [session_id ]
0 commit comments