11import json
22import logging
3- import time
43
54from cryptojwt import BadSyntax
65from cryptojwt .jwe .exception import JWEException
76from cryptojwt .jws .exception import NoSuitableSigningKeys
7+ from cryptojwt .jwt import utc_time_sans_frac
88from cryptojwt .utils import as_bytes
99from cryptojwt .utils import as_unicode
1010from cryptojwt .utils import b64d
@@ -282,7 +282,7 @@ def _do_request_uri(self, request, client_id, endpoint_context, **kwargs):
282282 "enc_enc" ,
283283 )
284284 # The protected info overwrites the non-protected
285- for k ,v in _ver_request .items ():
285+ for k , v in _ver_request .items ():
286286 request [k ] = v
287287
288288 request [verified_claim_name ("request" )] = _ver_request
@@ -435,11 +435,11 @@ def setup_auth(self, request, redirect_uri, cinfo, cookie, acr=None, **kwargs):
435435 if "req_user" in kwargs :
436436 sids = self .endpoint_context .sdb .get_sids_by_sub (kwargs ["req_user" ])
437437 if (
438- sids
439- and user
440- != self .endpoint_context .sdb .get_authentication_event (
441- sids [- 1 ]
442- ).uid
438+ sids
439+ and user
440+ != self .endpoint_context .sdb .get_authentication_event (
441+ sids [- 1 ]
442+ ).uid
443443 ):
444444 logger .debug ("Wanted to be someone else!" )
445445 if "prompt" in request and "none" in request ["prompt" ]:
@@ -451,26 +451,21 @@ def setup_auth(self, request, redirect_uri, cinfo, cookie, acr=None, **kwargs):
451451 else :
452452 return {"function" : authn , "args" : authn_args }
453453
454+ authn_event = None
454455 if session :
455456 authn_event = session .get ('authn_event' )
456- if authn_event is None :
457- authn_event = create_authn_event (
458- identity ["uid" ],
459- identity .get ("salt" , "" ),
460- authn_info = authn_class_ref ,
461- time_stamp = _ts ,
462- )
463- else :
457+
458+ if authn_event is None :
464459 authn_event = create_authn_event (
465460 identity ["uid" ],
466461 identity .get ("salt" , "" ),
467462 authn_info = authn_class_ref ,
468463 time_stamp = _ts ,
469464 )
470465
471- if "valid_until" in authn_event :
472- vu = time . time () + authn . kwargs . get ( "expires_in" , 0.0 )
473- authn_event ["valid_until" ] = vu
466+ _exp_in = authn . kwargs . get ( "expires_in" )
467+ if _exp_in and "valid_until" in authn_event :
468+ authn_event ["valid_until" ] = utc_time_sans_frac () + _exp_in
474469
475470 return {"authn_event" : authn_event , "identity" : identity , "user" : user }
476471
0 commit comments