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

Commit 7b311c5

Browse files
authored
Merge pull request #2 from openid/master
merge
2 parents 5d0bd1b + 81ae827 commit 7b311c5

File tree

7 files changed

+66
-74
lines changed

7 files changed

+66
-74
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# oicrp
1+
# oidcrp
22
High level interface to the OIDC RP library
33

44
oidcrp represents the 4th layer in the

flask_rp/application.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22

3+
from cryptojwt import KeyJar
34
from cryptojwt.key_jar import init_key_jar
45
from flask.app import Flask
56
from oidcop.utils import load_yaml_config
@@ -10,19 +11,28 @@
1011

1112

1213
def init_oidc_rp_handler(app):
13-
oidc_keys_conf = app.config.get('OIDC_KEYS')
14-
verify_ssl = app.config.get('VERIFY_SSL')
14+
rp_keys_conf = app.config.get('RP_KEYS')
15+
if rp_keys_conf is None:
16+
rp_keys_conf = app.config.get('OIDC_KEYS')
1517

16-
_kj = init_key_jar(**oidc_keys_conf)
18+
verify_ssl = app.config.get('VERIFY_SSL')
19+
hash_seed = app.config.get('HASH_SEED')
20+
if not hash_seed:
21+
hash_seed = "BabyHoldOn"
22+
23+
if rp_keys_conf:
24+
_kj = init_key_jar(**rp_keys_conf)
25+
_path = rp_keys_conf['public_path']
26+
if _path.startswith('./'):
27+
_path = _path[2:]
28+
elif _path.startswith('/'):
29+
_path = _path[1:]
30+
else:
31+
_kj = KeyJar()
32+
_path = ''
1733
_kj.verify_ssl = verify_ssl
1834

19-
_path = oidc_keys_conf['public_path']
20-
if _path.startswith('./'):
21-
_path = _path[2:]
22-
elif _path.startswith('/'):
23-
_path = _path[1:]
24-
25-
rph = RPHandler(base_url=app.config.get('BASEURL'), hash_seed="BabyHoldOn",
35+
rph = RPHandler(base_url=app.config.get('BASEURL'), hash_seed=hash_seed,
2636
keyjar=_kj, jwks_path=_path,
2737
client_configs=app.config.get('CLIENTS'),
2838
services=app.config.get('SERVICES'),
@@ -41,6 +51,8 @@ def oidc_provider_init_app(config_file, name=None, **kwargs):
4151
else:
4252
raise ValueError('Unknown configuration format')
4353

54+
app.config['SECRET_KEY'] = os.urandom(12).hex()
55+
4456
app.users = {'test_user': {'name': 'Testing Name'}}
4557

4658
try:

flask_rp/conf.yaml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,13 @@ SECRET_KEY: 'secret_key'
2424
SESSION_COOKIE_NAME: 'rp_session'
2525
PREFERRED_URL_SCHEME: 'https'
2626

27-
OIDC_KEYS:
27+
RP_KEYS:
2828
'private_path': './private/jwks.json'
2929
'key_defs': *keydef
3030
'public_path': './static/jwks.json'
31-
# this will create the jwks files if they absent
31+
# this will create the jwks files if they are absent
3232
'read_only': False
3333

34-
# PUBLIC_JWKS_PATH: 'https://127.0.0.1:8090/static/jwks.json'
35-
# PRIVATE_JWKS_PATH: './private/jwks.json'
36-
3734
client_preferences: &id001
3835
application_name: rphandler
3936
application_type: web

flask_rp/example_conf.yaml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,21 @@ VERIFY_SSL: False
1111

1212
KEYDEFS: &keydef
1313
-
14-
"type: "RSA"
15-
"key: ''
16-
"use: ["sig"]
14+
"type": "RSA"
15+
"key": ''
16+
"use": ["sig"]
1717
-
18-
"type: "EC"
19-
"crv: "P-256"
20-
"use: ["sig"]
18+
"type": "EC"
19+
"crv": "P-256"
20+
"use": ["sig"]
21+
22+
RP_KEYS:
23+
'private_path': 'jwks_dir/jwks.json'
24+
'key_defs': *keydef
25+
'public_path': 'static/jwks.json'
26+
# this will create the jwks files if they absent
27+
'read_only': False
2128

22-
PRIVATE_JWKS_PATH: "jwks_dir/jwks.json"
23-
PUBLIC_JWKS_PATH: 'static/jwks.json'
2429
# information used when registering the client, this may be the same for all OPs
2530

2631
services: &services

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ def run_tests(self):
6666
install_requires=[
6767
'cryptojwt>=0.7.0',
6868
'oidcservice>=0.6.3',
69-
'oidcmsg>=0.6.3'
69+
'oidcmsg>=0.6.3',
70+
'pyyaml'
7071
],
7172
tests_require=[
7273
'pytest',

src/oidcrp/__init__.py

Lines changed: 24 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22
import logging
33
import sys
44
import traceback
5-
from importlib import import_module
65

7-
from cryptojwt.utils import as_bytes, as_unicode
8-
from oidcmsg.exception import MessageException, NotForMe
6+
from cryptojwt.key_bundle import keybundle_from_local_file
7+
from cryptojwt.utils import as_bytes
8+
from cryptojwt.utils import as_unicode
9+
from oidcmsg.exception import MessageException
10+
from oidcmsg.exception import NotForMe
911
from oidcmsg.oauth2 import ResponseMessage
1012
from oidcmsg.oauth2 import is_error_message
11-
from oidcmsg.oidc import AccessTokenResponse, verified_claim_name
13+
from oidcmsg.oidc import AccessTokenResponse
1214
from oidcmsg.oidc import AuthorizationRequest
1315
from oidcmsg.oidc import AuthorizationResponse
1416
from oidcmsg.oidc import OpenIDSchema
17+
from oidcmsg.oidc import verified_claim_name
1518
from oidcmsg.oidc.session import BackChannelLogoutRequest
1619
from oidcmsg.time_util import time_sans_frac
1720
from oidcservice import rndstr
@@ -24,7 +27,7 @@
2427
from oidcrp import provider
2528

2629
__author__ = 'Roland Hedberg'
27-
__version__ = '0.6.1'
30+
__version__ = '0.6.3'
2831

2932
logger = logging.getLogger(__name__)
3033

@@ -237,6 +240,22 @@ def do_provider_info(self, client=None, state=''):
237240
if _srv.endpoint_name == key:
238241
_srv.endpoint = val
239242

243+
if 'keys' in _pi:
244+
_kj = client.service_context.keyjar
245+
for typ, _spec in _pi['keys'].items():
246+
if typ == 'url':
247+
for _iss, _url in _spec.items():
248+
_kj.add_url(_iss, _url)
249+
elif typ == 'file':
250+
for kty, _name in _spec.items():
251+
if kty == 'jwks':
252+
_kj.import_jwks_from_file(_name,
253+
client.service_context.issuer)
254+
elif kty == 'rsa': # PEM file
255+
_kb = keybundle_from_local_file(_name, "der", ["sig"])
256+
_kj.add_kb(client.service_context.issuer, _kb)
257+
else:
258+
raise ValueError('Unknown provider JWKS type: {}'.format(typ))
240259
try:
241260
return client.service_context.provider_info['issuer']
242261
except KeyError:
@@ -903,46 +922,3 @@ def backchannel_logout(client, request='', request_args=None):
903922
_state = client.session_interface.get_state_by_sub(sub)
904923

905924
return _state
906-
907-
908-
# def get_provider_specific_service(service_provider, service, **kwargs):
909-
# """
910-
# Get a class instance of a :py:class:`oidcservice.service.Service` subclass
911-
# specific to a specified service provider.
912-
#
913-
# :param service_provider: The name of the service provider
914-
# :param service: The name of the service
915-
# :param kwargs: Arguments provided when initiating the class
916-
# :return: An initiated subclass of :py:class:`oidcservice.service.Service`
917-
# or None if the service or the service provider could not be found.
918-
# """
919-
# if service_provider in provider.__all__:
920-
# mod = import_module('oidcrp.provider.' + service_provider)
921-
# cls = getattr(mod, service)
922-
# return cls(**kwargs)
923-
#
924-
# return None
925-
#
926-
#
927-
# def factory(service_name, ignore, **kwargs):
928-
# """
929-
# A factory the given a service name will return a
930-
# :py:class:`oidcservice.service.Service` instance if a service matching the
931-
# name could be found.
932-
#
933-
# :param service_name: A service name, could be either of the format
934-
# 'group.name' or 'name'.
935-
# :param kwargs: A set of key word arguments to be used when initiating the
936-
# Service class
937-
# :return: A :py:class:`oidcservice.service.Service` instance or None
938-
# """
939-
# if '.' in service_name:
940-
# group, name = service_name.split('.')
941-
# if group == 'oauth2':
942-
# service_factory(service_name[1], ['oauth2'], **kwargs)
943-
# elif group == 'oidc':
944-
# service_factory(service_name[1], ['oidc'], **kwargs)
945-
# else:
946-
# return get_provider_specific_service(group, name, **kwargs)
947-
# else:
948-
# return service_factory(service_name, ['oidc', 'oauth2'], **kwargs)

tests/test_11_oauth2.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from oidcmsg.oauth2 import ResponseMessage
1717
from oidcmsg.oidc import IdToken
1818
from oidcmsg.time_util import utc_time_sans_frac
19+
from oidcservice.exception import OidcServiceError
1920
from oidcservice.exception import ParseError
2021

2122
from oidcrp.oauth2 import Client
@@ -163,7 +164,7 @@ def test_error_response_2(self):
163164
400, err.to_json(),
164165
headers={'content-type': 'application/x-www-form-urlencoded'})
165166

166-
with pytest.raises(HTTPError):
167+
with pytest.raises(OidcServiceError):
167168
self.client.parse_request_response(
168169
self.client.service['authorization'], http_resp)
169170

0 commit comments

Comments
 (0)