32
32
OIDCFED_PROVIDER_PROFILES_ACR_4_REFRESH ,
33
33
OIDCFED_PROVIDER_PROFILES_ID_TOKEN_CLAIMS
34
34
)
35
+
35
36
logger = logging .getLogger (__name__ )
36
37
37
38
@@ -40,7 +41,7 @@ class OpBase:
40
41
Baseclass with common methods for OPs
41
42
"""
42
43
43
- def redirect_response_data (self , redirect_uri :str , ** kwargs ) -> HttpResponseRedirect :
44
+ def redirect_response_data (self , redirect_uri : str , ** kwargs ) -> HttpResponseRedirect :
44
45
if "?" in redirect_uri :
45
46
qstring = "&"
46
47
else :
@@ -114,7 +115,7 @@ def validate_authz_request_object(self, req) -> TrustChain:
114
115
115
116
jwks = get_jwks (
116
117
rp_trust_chain .metadata ['openid_relying_party' ],
117
- federation_jwks = rp_trust_chain .jwks
118
+ federation_jwks = rp_trust_chain .jwks
118
119
)
119
120
jwk = self .find_jwk (header , jwks )
120
121
if not jwk :
@@ -178,7 +179,7 @@ def check_session(self, request) -> OidcSession:
178
179
)
179
180
180
181
session_not_after = session .created + timezone .timedelta (
181
- minutes = OIDCFED_PROVIDER_AUTH_CODE_MAX_AGE
182
+ minutes = OIDCFED_PROVIDER_AUTH_CODE_MAX_AGE
182
183
)
183
184
if session_not_after < timezone .localtime ():
184
185
raise ExpiredAuthCode (
@@ -199,12 +200,12 @@ def check_client_assertion(self, client_id: str, client_assertion: str) -> bool:
199
200
_op = self .get_issuer ()
200
201
_op_eid = _op .sub
201
202
_op_eid_authz_endpoint = [_op .metadata ['openid_provider' ]['authorization_endpoint' ]]
202
-
203
+
203
204
try :
204
205
ClientAssertion (** payload )
205
206
except Exception as e :
206
207
raise Exception (f"Client Assertion: json schema validation error: { e } " )
207
-
208
+
208
209
if isinstance (_aud , str ):
209
210
_aud = [_aud ]
210
211
_allowed_auds = _aud + _op_eid_authz_endpoint
@@ -250,9 +251,9 @@ def get_jwt_common_data(self):
250
251
}
251
252
252
253
def get_access_token (
253
- self , iss_sub :str , sub :str , authz : OidcSession , commons :dict
254
+ self , iss_sub : str , sub : str , authz : OidcSession , commons : dict
254
255
) -> dict :
255
-
256
+
256
257
access_token = {
257
258
"iss" : iss_sub ,
258
259
"sub" : sub ,
@@ -266,8 +267,8 @@ def get_access_token(
266
267
return access_token
267
268
268
269
def get_id_token_claims (
269
- self ,
270
- authz :OidcSession
270
+ self ,
271
+ authz : OidcSession
271
272
) -> dict :
272
273
_provider_profile = getattr (settings , 'OIDCFED_DEFAULT_PROVIDER_PROFILE' , OIDCFED_DEFAULT_PROVIDER_PROFILE )
273
274
claims = {}
@@ -276,21 +277,21 @@ def get_id_token_claims(
276
277
return claims
277
278
278
279
for claim in (
279
- authz .authz_request .get (
280
- "claims" , {}
281
- ).get ("id_token" , {}).keys ()
280
+ authz .authz_request .get (
281
+ "claims" , {}
282
+ ).get ("id_token" , {}).keys ()
282
283
):
283
284
if claim in allowed_id_token_claims and authz .user .attributes .get (claim , None ):
284
285
claims [claim ] = authz .user .attributes [claim ]
285
286
return claims
286
287
287
288
def get_id_token (
288
- self ,
289
- iss_sub :str ,
290
- sub :str ,
291
- authz :OidcSession ,
292
- jwt_at :str ,
293
- commons :dict
289
+ self ,
290
+ iss_sub : str ,
291
+ sub : str ,
292
+ authz : OidcSession ,
293
+ jwt_at : str ,
294
+ commons : dict
294
295
) -> dict :
295
296
296
297
id_token = {
@@ -312,19 +313,19 @@ def get_id_token(
312
313
313
314
def get_refresh_token (
314
315
self ,
315
- iss_sub :str ,
316
- sub :str ,
317
- authz :OidcSession ,
318
- jwt_at :str ,
319
- commons :dict
316
+ iss_sub : str ,
317
+ sub : str ,
318
+ authz : OidcSession ,
319
+ jwt_at : str ,
320
+ commons : dict
320
321
) -> dict :
321
322
# refresh token is scope offline_access and prompt == consent
322
323
refresh_acrs = OIDCFED_PROVIDER_PROFILES_ACR_4_REFRESH [OIDCFED_DEFAULT_PROVIDER_PROFILE ]
323
324
acrs = authz .authz_request .get ('acr_values' , [])
324
325
if (
325
- "offline_access" in authz .authz_request ['scope' ] and
326
- 'consent' in authz .authz_request ['prompt' ] and
327
- set (refresh_acrs ).intersection (set (acrs ))
326
+ "offline_access" in authz .authz_request ['scope' ] and
327
+ 'consent' in authz .authz_request ['prompt' ] and
328
+ set (refresh_acrs ).intersection (set (acrs ))
328
329
):
329
330
refresh_token = {
330
331
"sub" : sub ,
@@ -337,8 +338,8 @@ def get_refresh_token(
337
338
refresh_token .update (commons )
338
339
return refresh_token
339
340
340
- def get_iss_token_data (self , session : OidcSession , issuer : FederationEntityConfiguration ):
341
- _sub = session .pairwised_sub (provider_id = issuer .sub )
341
+ def get_iss_token_data (self , session : OidcSession , issuer : FederationEntityConfiguration ):
342
+ _sub = session .pairwised_sub (provider_id = issuer .sub )
342
343
iss_sub = issuer .sub
343
344
commons = self .get_jwt_common_data ()
344
345
jwk = issuer .jwks_core [0 ]
@@ -363,7 +364,7 @@ def get_iss_token_data(self, session : OidcSession, issuer: FederationEntityConf
363
364
364
365
def get_expires_in (self , iat : int , exp : int ):
365
366
return timezone .timedelta (
366
- seconds = exp - iat
367
+ seconds = exp - iat
367
368
).seconds
368
369
369
370
def attributes_names_to_release (self , request , session : OidcSession ) -> dict :
@@ -391,6 +392,23 @@ def attributes_names_to_release(self, request, session: OidcSession) -> dict:
391
392
for i in filtered_user_claims .keys ()
392
393
]
393
394
return dict (
394
- i18n_user_claims = i18n_user_claims ,
395
- filtered_user_claims = filtered_user_claims
395
+ i18n_user_claims = i18n_user_claims ,
396
+ filtered_user_claims = filtered_user_claims
396
397
)
398
+
399
+ def get_client_organization_name (self , tc ):
400
+ rp_metadata = (
401
+ tc .metadata .get (
402
+ "federation_entity" , {}
403
+ ) or
404
+ tc .metadata .get (
405
+ "openid_relying_party" , {}
406
+ )
407
+ )
408
+ if rp_metadata :
409
+ name = (
410
+ rp_metadata .get ("organization_name" , "" ) or
411
+ rp_metadata .get ("client_name" , "" ) or
412
+ rp_metadata .get ("client_id" , "" )
413
+ )
414
+ return name
0 commit comments