11from json import JSONDecodeError
22import logging
3+ from typing import Optional
34
45from oidcmsg .exception import FormatError
6+ from oidcmsg .message import Message
7+ from oidcmsg .oauth2 import is_error_message
58
69from oidcrp .entity import Entity
10+ from oidcrp .exception import ConfigurationError
711from oidcrp .exception import OidcServiceError
812from oidcrp .exception import ParseError
913from oidcrp .http import HTTPLib
1014from oidcrp .service import REQUEST_INFO
1115from oidcrp .service import SUCCESSFUL
16+ from oidcrp .service import Service
1217from oidcrp .util import do_add_ons
1318from oidcrp .util import get_deserialization_method
1419
@@ -72,7 +77,11 @@ def __init__(self, client_authn_factory=None, keyjar=None, verify_ssl=True, conf
7277 # just ignore verify_ssl until it goes away
7378 self .verify_ssl = self .httpc_params .get ("verify" , True )
7479
75- def do_request (self , request_type , response_body_type = "" , request_args = None , ** kwargs ):
80+ def do_request (self ,
81+ request_type : str ,
82+ response_body_type : Optional [str ] = "" ,
83+ request_args : Optional [dict ] = None ,
84+ behaviour_args : Optional [dict ] = None , ** kwargs ):
7685 _srv = self ._service [request_type ]
7786
7887 _info = _srv .get_request_parameters (request_args = request_args , ** kwargs )
@@ -93,8 +102,13 @@ def set_client_id(self, client_id):
93102 self .client_id = client_id
94103 self ._service_context .set ('client_id' , client_id )
95104
96- def get_response (self , service , url , method = "GET" , body = None , response_body_type = "" ,
97- headers = None , ** kwargs ):
105+ def get_response (self ,
106+ service : Service ,
107+ url : str ,
108+ method : Optional [str ] = "GET" ,
109+ body : Optional [dict ] = None ,
110+ response_body_type : Optional [str ] = "" ,
111+ headers : Optional [dict ] = None , ** kwargs ):
98112 """
99113
100114 :param url:
@@ -129,8 +143,13 @@ def get_response(self, service, url, method="GET", body=None, response_body_type
129143 return self .parse_request_response (service , resp ,
130144 response_body_type , ** kwargs )
131145
132- def service_request (self , service , url , method = "GET" , body = None ,
133- response_body_type = "" , headers = None , ** kwargs ):
146+ def service_request (self ,
147+ service : Service ,
148+ url : str ,
149+ method : Optional [str ] = "GET" ,
150+ body : Optional [dict ] = None ,
151+ response_body_type : Optional [str ] = "" ,
152+ headers : Optional [dict ] = None , ** kwargs ) -> Message :
134153 """
135154 The method that sends the request and handles the response returned.
136155 This assumes that the response arrives in the HTTP response.
@@ -249,3 +268,27 @@ def parse_request_response(self, service, reqresp, response_body_type='',
249268 reqresp .text ))
250269 raise OidcServiceError ("HTTP ERROR: %s [%s] on %s" % (
251270 reqresp .text , reqresp .status_code , reqresp .url ))
271+
272+
273+ def dynamic_provider_info_discovery (client : Client , behaviour_args : Optional [dict ]= None ):
274+ """
275+ This is about performing dynamic Provider Info discovery
276+
277+ :param behaviour_args:
278+ :param client: A :py:class:`oidcrp.oidc.Client` instance
279+ """
280+ try :
281+ client .get_service ('provider_info' )
282+ except KeyError :
283+ raise ConfigurationError (
284+ 'Can not do dynamic provider info discovery' )
285+ else :
286+ _context = client .client_get ("service_context" )
287+ try :
288+ _context .set ('issuer' , _context .config ['srv_discovery_url' ])
289+ except KeyError :
290+ pass
291+
292+ response = client .do_request ('provider_info' , behaviour_args = behaviour_args )
293+ if is_error_message (response ):
294+ raise OidcServiceError (response ['error' ])
0 commit comments