|
9 | 9 | import six |
10 | 10 | import time |
11 | 11 | import logging |
| 12 | +from typing import Mapping |
12 | 13 | from warnings import warn as _warn |
13 | 14 |
|
14 | 15 | from saml2.entity import Entity |
@@ -365,20 +366,29 @@ def create_authn_request( |
365 | 366 | or self.config.getattr("requested_authn_context", "sp") |
366 | 367 | or {} |
367 | 368 | ) |
368 | | - requested_authn_context_accrs = requested_authn_context.get( |
369 | | - "authn_context_class_ref", [] |
370 | | - ) |
371 | | - requested_authn_context_comparison = requested_authn_context.get( |
372 | | - "comparison", "exact" |
373 | | - ) |
374 | | - if requested_authn_context_accrs: |
375 | | - args["requested_authn_context"] = RequestedAuthnContext( |
376 | | - authn_context_class_ref=[ |
377 | | - AuthnContextClassRef(accr) |
378 | | - for accr in requested_authn_context_accrs |
379 | | - ], |
380 | | - comparison=requested_authn_context_comparison, |
| 369 | + if isinstance(requested_authn_context, RequestedAuthnContext): |
| 370 | + args["requested_authn_context"] = requested_authn_context |
| 371 | + elif isinstance(requested_authn_context, Mapping): |
| 372 | + requested_authn_context_accrs = requested_authn_context.get( |
| 373 | + "authn_context_class_ref", [] |
381 | 374 | ) |
| 375 | + requested_authn_context_comparison = requested_authn_context.get( |
| 376 | + "comparison", "exact" |
| 377 | + ) |
| 378 | + if requested_authn_context_accrs: |
| 379 | + args["requested_authn_context"] = RequestedAuthnContext( |
| 380 | + authn_context_class_ref=[ |
| 381 | + AuthnContextClassRef(accr) |
| 382 | + for accr in requested_authn_context_accrs |
| 383 | + ], |
| 384 | + comparison=requested_authn_context_comparison, |
| 385 | + ) |
| 386 | + else: |
| 387 | + logger.warning({ |
| 388 | + "message": "Cannot process requested_authn_context", |
| 389 | + "requested_authn_context": requested_authn_context, |
| 390 | + "type_of_requested_authn_context": type(requested_authn_context), |
| 391 | + }) |
382 | 392 |
|
383 | 393 | # Allow argument values either as class instances or as dictionaries |
384 | 394 | # all of these have cardinality 0..1 |
|
0 commit comments