Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit f9711ad

Browse files
committed
Allow behaviour_args for do_provider_info and do_client_registration too.
1 parent dc03542 commit f9711ad

3 files changed

Lines changed: 23 additions & 11 deletions

File tree

src/oidcrp/rp_handler.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from oidcmsg.oidc import AuthorizationResponse
1919
from oidcmsg.oidc import Claims
2020
from oidcmsg.oidc import OpenIDSchema
21+
from oidcmsg.oidc import RegistrationRequest
2122
from oidcmsg.oidc.session import BackChannelLogoutRequest
2223
from oidcmsg.time_util import time_sans_frac
2324

@@ -180,7 +181,7 @@ def init_client(self, issuer):
180181
_context.jwks_uri = self.jwks_uri
181182
return client
182183

183-
def do_provider_info(self, client=None, state=''):
184+
def do_provider_info(self, client=None, state='', behaviour_args=None):
184185
"""
185186
Either get the provider info from configuration or through dynamic
186187
discovery.
@@ -235,10 +236,14 @@ def do_provider_info(self, client=None, state=''):
235236
except KeyError:
236237
return _context.get('issuer')
237238

238-
def do_client_registration(self, client=None, iss_id='', state=''):
239+
def do_client_registration(self, client=None,
240+
iss_id: Optional[str] = '',
241+
state: Optional[str] = '',
242+
behaviour_args: Optional[dict] = None):
239243
"""
240244
Prepare for and do client registration if configured to do so
241245
246+
:param behaviour_args: To fine tune behaviour
242247
:param client: A Client instance
243248
:param state: A key by which the state of the session can be
244249
retrieved
@@ -271,7 +276,9 @@ def do_client_registration(self, client=None, iss_id='', state=''):
271276
v for k, v in callbacks.items() if not k.startswith('__')])
272277
_context.set('callbacks', callbacks)
273278

274-
load_registration_response(client)
279+
_params = RegistrationRequest().parameters()
280+
request_args = {k:v for k, v in behaviour_args.items() if k in _params}
281+
load_registration_response(client, request_args=request_args)
275282

276283
def add_callbacks(self, service_context):
277284
_iss = service_context.get('issuer')
@@ -298,7 +305,7 @@ def do_webfinger(self, user):
298305
temporary_client.do_request('webfinger', resource=user)
299306
return temporary_client
300307

301-
def client_setup(self, iss_id='', user=''):
308+
def client_setup(self, iss_id='', user='', behaviour_args=None):
302309
"""
303310
First if no issuer ID is given then the identifier for the user is
304311
used by the webfinger service to try to find the issuer ID.
@@ -307,6 +314,7 @@ def client_setup(self, iss_id='', user=''):
307314
the necessary information for the client to be able to communicate
308315
with the OP/AS that has the provided issuer ID.
309316
317+
:param behaviour_args: To fine tune behaviour
310318
:param iss_id: The issuer ID
311319
:param user: A user identifier
312320
:return: A :py:class:`oidcrp.oidc.Client` instance
@@ -335,10 +343,10 @@ def client_setup(self, iss_id='', user=''):
335343
return client
336344

337345
logger.debug("Get provider info")
338-
issuer = self.do_provider_info(client)
346+
issuer = self.do_provider_info(client, behaviour_args=behaviour_args)
339347

340348
logger.debug("Do client registration")
341-
self.do_client_registration(client, iss_id)
349+
self.do_client_registration(client, iss_id, behaviour_args=behaviour_args)
342350

343351
self.issuer2rp[issuer] = client
344352
return client
@@ -439,7 +447,7 @@ def begin(self, issuer_id='', user_id='', req_args=None, behaviour_args=None):
439447
"""
440448

441449
# Get the client instance that has been assigned to this issuer
442-
client = self.client_setup(issuer_id, user_id)
450+
client = self.client_setup(issuer_id, user_id, behaviour_args=behaviour_args)
443451

444452
try:
445453
res = self.init_authorization(client, req_args=req_args, behaviour_args=behaviour_args)

src/oidcrp/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ def add_path(url, path):
534534
return '{}/{}'.format(url, path)
535535

536536

537-
def load_registration_response(client):
537+
def load_registration_response(client, request_args=None):
538538
"""
539539
If the client has been statically registered that information
540540
must be provided during the configuration. If expected to be
@@ -544,7 +544,7 @@ def load_registration_response(client):
544544
"""
545545
if not client.client_get("service_context").get('client_id'):
546546
try:
547-
response = client.do_request('registration')
547+
response = client.do_request('registration', request_args=request_args)
548548
except KeyError:
549549
raise ConfigurationError('No registration info')
550550
except Exception as err:

tests/test_20_rp_handler_oidc.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,8 @@ def test_rphandler_request_uri():
832832

833833
def test_rphandler_request():
834834
rph = RPHandler(BASE_URL, CLIENT_CONFIG, keyjar=CLI_KEY)
835-
res = rph.begin(issuer_id='github2', behaviour_args={"request_param": "request"})
835+
res = rph.begin(issuer_id='github2',
836+
behaviour_args={"request_param": "request"})
836837
_session = rph.get_session_information(res['state'])
837838
_url = res["url"]
838839
_qp = parse_qs(urlparse(_url).query)
@@ -990,7 +991,10 @@ def test_dynamic_setup_redirect_uri(self):
990991
'/connect/register', registration_callback, 200,
991992
{'content-type': "application/json"})
992993

993-
res = self.rph.begin(user_id=user_id)
994+
res = self.rph.begin(user_id=user_id,
995+
behaviour_args={
996+
"request_param": "request",
997+
"request_object_signing_alg": "RS256"})
994998
assert res
995999

9961000
_url = res["url"]

0 commit comments

Comments
 (0)