88from typing import Union
99from urllib .parse import urlparse
1010
11- from cryptojwt .exception import IssuerNotFound
1211from cryptojwt .jwe .jwe import factory as jwe_factory
1312from cryptojwt .jws .jws import factory as jws_factory
1413from cryptojwt .jwt import JWT
15- from idpyoidc .exception import MissingSigningKey
1614
1715from idpyoidc .client .exception import Unsupported
16+ from idpyoidc .exception import MissingSigningKey
1817from idpyoidc .impexp import ImpExp
1918from idpyoidc .item import DLDict
2019from idpyoidc .message import Message
21- from idpyoidc .message .oauth2 import ResponseMessage
2220from idpyoidc .message .oauth2 import is_error_message
21+ from idpyoidc .message .oauth2 import ResponseMessage
2322from idpyoidc .util import importer
24-
25- from ..constant import JOSE_ENCODED
26- from ..constant import JSON_ENCODED
27- from ..constant import URL_ENCODED
2823from .client_auth import client_auth_setup
2924from .client_auth import method_to_item
3025from .client_auth import single_authn_setup
3126from .configure import Configuration
3227from .exception import ResponseError
3328from .util import get_http_body
3429from .util import get_http_url
30+ from ..constant import JOSE_ENCODED
31+ from ..constant import JSON_ENCODED
32+ from ..constant import URL_ENCODED
3533
3634__author__ = "Roland Hedberg"
3735
@@ -79,7 +77,7 @@ class Service(ImpExp):
7977 _callback_path = {}
8078
8179 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
8381 ):
8482 ImpExp .__init__ (self )
8583
@@ -333,7 +331,7 @@ def get_endpoint(self):
333331 return self .upstream_get ("context" ).provider_info [self .endpoint_name ]
334332
335333 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
337335 ) -> dict :
338336 """
339337 Construct an authorization specification to be sent in the
@@ -364,12 +362,15 @@ def get_authn_method(self) -> str:
364362 """
365363 return self .default_authn_method
366364
365+ def get_headers_args (self ):
366+ return {}
367+
367368 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 ,
373374 ) -> dict :
374375 """
375376
@@ -404,7 +405,7 @@ def get_headers(
404405 return _headers
405406
406407 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
408409 ) -> dict :
409410 """
410411 Builds the request message and constructs the HTTP headers.
@@ -445,6 +446,7 @@ def get_request_parameters(
445446
446447 # Client authentication by usage of the Authorization HTTP header
447448 # or by modifying the request object
449+ _args .update (self .get_headers_args ())
448450 _headers = self .get_headers (request , http_method = method , authn_method = authn_method , ** _args )
449451
450452 # Find out where to send this request
@@ -506,7 +508,7 @@ def post_parse_response(self, response, **kwargs):
506508 return response
507509
508510 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
510512 ):
511513 """
512514 Need to add some information before running verify()
@@ -542,7 +544,7 @@ def _do_jwt(self, info):
542544 def _do_response (self , info , sformat , ** kwargs ):
543545 _context = self .upstream_get ("context" )
544546
545- if isinstance (info , list ): # Don't have support for sformat=list
547+ if isinstance (info , list ): # Don't have support for sformat=list
546548 return info
547549
548550 try :
@@ -566,13 +568,13 @@ def _do_response(self, info, sformat, **kwargs):
566568 return resp
567569
568570 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+ ):
576578 """
577579 This the start of a pipeline that will:
578580
@@ -707,12 +709,12 @@ def get_uri(base_url, path, hex):
707709 return f"{ base_url } /{ path } /{ hex } "
708710
709711 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 ,
716718 ):
717719 if not targets :
718720 targets = self ._callback_path .keys ()
0 commit comments