8
8
from typing import Union
9
9
from urllib .parse import urlparse
10
10
11
- from cryptojwt .exception import IssuerNotFound
12
11
from cryptojwt .jwe .jwe import factory as jwe_factory
13
12
from cryptojwt .jws .jws import factory as jws_factory
14
13
from cryptojwt .jwt import JWT
15
- from idpyoidc .exception import MissingSigningKey
16
14
17
15
from idpyoidc .client .exception import Unsupported
16
+ from idpyoidc .exception import MissingSigningKey
18
17
from idpyoidc .impexp import ImpExp
19
18
from idpyoidc .item import DLDict
20
19
from idpyoidc .message import Message
21
- from idpyoidc .message .oauth2 import ResponseMessage
22
20
from idpyoidc .message .oauth2 import is_error_message
21
+ from idpyoidc .message .oauth2 import ResponseMessage
23
22
from idpyoidc .util import importer
24
-
25
- from ..constant import JOSE_ENCODED
26
- from ..constant import JSON_ENCODED
27
- from ..constant import URL_ENCODED
28
23
from .client_auth import client_auth_setup
29
24
from .client_auth import method_to_item
30
25
from .client_auth import single_authn_setup
31
26
from .configure import Configuration
32
27
from .exception import ResponseError
33
28
from .util import get_http_body
34
29
from .util import get_http_url
30
+ from ..constant import JOSE_ENCODED
31
+ from ..constant import JSON_ENCODED
32
+ from ..constant import URL_ENCODED
35
33
36
34
__author__ = "Roland Hedberg"
37
35
@@ -79,7 +77,7 @@ class Service(ImpExp):
79
77
_callback_path = {}
80
78
81
79
def __init__ (
82
- self , upstream_get : Callable , conf : Optional [Union [dict , Configuration ]] = None , ** kwargs
80
+ self , upstream_get : Callable , conf : Optional [Union [dict , Configuration ]] = None , ** kwargs
83
81
):
84
82
ImpExp .__init__ (self )
85
83
@@ -333,7 +331,7 @@ def get_endpoint(self):
333
331
return self .upstream_get ("context" ).provider_info [self .endpoint_name ]
334
332
335
333
def get_authn_header (
336
- self , request : Union [dict , Message ], authn_method : Optional [str ] = "" , ** kwargs
334
+ self , request : Union [dict , Message ], authn_method : Optional [str ] = "" , ** kwargs
337
335
) -> dict :
338
336
"""
339
337
Construct an authorization specification to be sent in the
@@ -364,12 +362,15 @@ def get_authn_method(self) -> str:
364
362
"""
365
363
return self .default_authn_method
366
364
365
+ def get_headers_args (self ):
366
+ return {}
367
+
367
368
def get_headers (
368
- self ,
369
- request : Union [dict , Message ],
370
- http_method : str ,
371
- authn_method : Optional [str ] = "" ,
372
- ** kwargs ,
369
+ self ,
370
+ request : Union [dict , Message ],
371
+ http_method : str ,
372
+ authn_method : Optional [str ] = "" ,
373
+ ** kwargs ,
373
374
) -> dict :
374
375
"""
375
376
@@ -404,7 +405,7 @@ def get_headers(
404
405
return _headers
405
406
406
407
def get_request_parameters (
407
- self , request_args = None , method = "" , request_body_type = "" , authn_method = "" , ** kwargs
408
+ self , request_args = None , method = "" , request_body_type = "" , authn_method = "" , ** kwargs
408
409
) -> dict :
409
410
"""
410
411
Builds the request message and constructs the HTTP headers.
@@ -445,6 +446,7 @@ def get_request_parameters(
445
446
446
447
# Client authentication by usage of the Authorization HTTP header
447
448
# or by modifying the request object
449
+ _args .update (self .get_headers_args ())
448
450
_headers = self .get_headers (request , http_method = method , authn_method = authn_method , ** _args )
449
451
450
452
# Find out where to send this request
@@ -506,7 +508,7 @@ def post_parse_response(self, response, **kwargs):
506
508
return response
507
509
508
510
def gather_verify_arguments (
509
- self , response : Optional [Union [dict , Message ]] = None , behaviour_args : Optional [dict ] = None
511
+ self , response : Optional [Union [dict , Message ]] = None , behaviour_args : Optional [dict ] = None
510
512
):
511
513
"""
512
514
Need to add some information before running verify()
@@ -542,7 +544,7 @@ def _do_jwt(self, info):
542
544
def _do_response (self , info , sformat , ** kwargs ):
543
545
_context = self .upstream_get ("context" )
544
546
545
- if isinstance (info , list ): # Don't have support for sformat=list
547
+ if isinstance (info , list ): # Don't have support for sformat=list
546
548
return info
547
549
548
550
try :
@@ -566,13 +568,13 @@ def _do_response(self, info, sformat, **kwargs):
566
568
return resp
567
569
568
570
def parse_response (
569
- self ,
570
- info ,
571
- sformat : Optional [str ] = "" ,
572
- state : Optional [str ] = "" ,
573
- behaviour_args : Optional [dict ] = None ,
574
- ** kwargs ,
575
- ) :
571
+ self ,
572
+ info ,
573
+ sformat : Optional [str ] = "" ,
574
+ state : Optional [str ] = "" ,
575
+ behaviour_args : Optional [dict ] = None ,
576
+ ** kwargs ,
577
+ ):
576
578
"""
577
579
This the start of a pipeline that will:
578
580
@@ -707,12 +709,12 @@ def get_uri(base_url, path, hex):
707
709
return f"{ base_url } /{ path } /{ hex } "
708
710
709
711
def construct_uris (
710
- self ,
711
- base_url : str ,
712
- hex : bytes ,
713
- context : OidcContext ,
714
- targets : Optional [List [str ]] = None ,
715
- response_types : Optional [list ] = None ,
712
+ self ,
713
+ base_url : str ,
714
+ hex : bytes ,
715
+ context : OidcContext ,
716
+ targets : Optional [List [str ]] = None ,
717
+ response_types : Optional [list ] = None ,
716
718
):
717
719
if not targets :
718
720
targets = self ._callback_path .keys ()
0 commit comments