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

Commit 6169bab

Browse files
committed
Dealing with static configuration and provider keys.
1 parent 7e06140 commit 6169bab

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

src/oidcrp/__init__.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sys
44
import traceback
55

6+
from cryptojwt.key_bundle import keybundle_from_local_file
67
from cryptojwt.utils import as_bytes
78
from cryptojwt.utils import as_unicode
89
from oidcmsg.exception import MessageException
@@ -239,6 +240,21 @@ def do_provider_info(self, client=None, state=''):
239240
if _srv.endpoint_name == key:
240241
_srv.endpoint = val
241242

243+
if 'keys' in _pi:
244+
for typ, _spec in _pi['keys'].items():
245+
if typ == 'url':
246+
for _iss, _url in _spec.items():
247+
self.keyjar.add_url(_iss, _url)
248+
elif typ == 'file':
249+
for kty, _name in _spec.items():
250+
if kty == 'jwks':
251+
self.keyjar.import_jwks_from_file(_name,
252+
client.service_context.issuer)
253+
elif kty == 'rsa': # PEM file
254+
_kb = keybundle_from_local_file(_name, "der", ["sig"])
255+
self.keyjar.add_kb(client.service_context.issuer, _kb)
256+
else:
257+
raise ValueError('Unknown provider JWKS type: {}'.format(typ))
242258
try:
243259
return client.service_context.provider_info['issuer']
244260
except KeyError:
@@ -357,7 +373,7 @@ def create_callbacks(self, issuer):
357373
'implicit': "{}/authz_im_cb/{}".format(self.base_url, _hex),
358374
'form_post': "{}/authz_fp_cb/{}".format(self.base_url, _hex),
359375
'__hex': _hex
360-
}
376+
}
361377

362378
def init_authorization(self, client=None, state='', req_args=None):
363379
"""
@@ -384,7 +400,7 @@ def init_authorization(self, client=None, state='', req_args=None):
384400
'scope': service_context.behaviour['scope'],
385401
'response_type': service_context.behaviour['response_types'][0],
386402
'nonce': _nonce
387-
}
403+
}
388404

389405
if req_args is not None:
390406
request_args.update(req_args)
@@ -493,15 +509,15 @@ def get_access_token(self, state, client=None):
493509
'grant_type': 'authorization_code',
494510
'client_id': client.service_context.client_id,
495511
'client_secret': client.service_context.client_secret
496-
}
512+
}
497513
logger.debug('request_args: {}'.format(req_args))
498514
try:
499515
tokenresp = client.do_request(
500516
'accesstoken', request_args=req_args,
501517
authn_method=self.get_client_authn_method(client,
502518
"token_endpoint"),
503519
state=state
504-
)
520+
)
505521
except Exception as err:
506522
message = traceback.format_exception(*sys.exc_info())
507523
logger.error(message)
@@ -537,7 +553,7 @@ def refresh_access_token(self, state, client=None, scope=''):
537553
authn_method=self.get_client_authn_method(client,
538554
"token_endpoint"),
539555
state=state, request_args=req_args
540-
)
556+
)
541557
except Exception as err:
542558
message = traceback.format_exception(*sys.exc_info())
543559
logger.error(message)
@@ -714,7 +730,7 @@ def finalize(self, issuer, response):
714730
return {
715731
'state': authorization_response['state'],
716732
'error': authorization_response['error']
717-
}
733+
}
718734

719735
_state = authorization_response['state']
720736
token = self.get_access_and_id_token(authorization_response,
@@ -729,7 +745,7 @@ def finalize(self, issuer, response):
729745
return {
730746
'error': "Invalid response %s." % inforesp["error"],
731747
'state': _state
732-
}
748+
}
733749

734750
elif token['id_token']: # look for it in the ID Token
735751
inforesp = self.userinfo_in_id_token(token['id_token'])
@@ -764,7 +780,7 @@ def finalize(self, issuer, response):
764780
'state': authorization_response['state'],
765781
'token': token['access_token'],
766782
'id_token': token['id_token']
767-
}
783+
}
768784

769785
def has_active_authentication(self, state):
770786
"""
@@ -853,7 +869,7 @@ def logout(self, state, client=None, post_logout_redirect_uri=''):
853869
if post_logout_redirect_uri:
854870
request_args = {
855871
"post_logout_redirect_uri": post_logout_redirect_uri
856-
}
872+
}
857873
else:
858874
request_args = {}
859875

@@ -883,7 +899,7 @@ def backchannel_logout(client, request='', request_args=None):
883899
'aud': client.service_context.client_id,
884900
'iss': client.service_context.issuer,
885901
'keyjar': client.service_context.keyjar
886-
}
902+
}
887903

888904
try:
889905
req.verify(**kwargs)
@@ -905,4 +921,3 @@ def backchannel_logout(client, request='', request_args=None):
905921
_state = client.session_interface.get_state_by_sub(sub)
906922

907923
return _state
908-

0 commit comments

Comments
 (0)