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

Commit 731b7d5

Browse files
committed
Callback uris are stored in context.callback .
1 parent eb7fd14 commit 731b7d5

11 files changed

Lines changed: 32 additions & 21 deletions

src/oidcrp/configure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
try:
1515
from secrets import token_urlsafe as rnd_token
1616
except ImportError:
17-
from oidcendpoint import rndstr as rnd_token
17+
from cryptojwt import rndstr as rnd_token
1818

1919
DEFAULT_FILE_ATTRIBUTE_NAMES = ['server_key', 'server_cert', 'filename', 'template_dir',
2020
'private_path', 'public_path', 'db_file']

src/oidcrp/oauth2/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from oidcmsg.exception import FormatError
55

6+
from oidcrp.configure import URIS
67
from oidcrp.entity import Entity
78
from oidcrp.exception import OidcServiceError
89
from oidcrp.exception import ParseError

src/oidcrp/oidc/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33

44
from oidcrp.client_auth import BearerHeader
5+
from oidcrp.oidc.registration import CALLBACK_URIS
56

67
try:
78
from json import JSONDecodeError
@@ -112,6 +113,15 @@ def __init__(self, client_authn_factory=None,
112113
keyjar=keyjar, verify_ssl=verify_ssl, config=config,
113114
httplib=httplib, services=_srvs, httpc_params=httpc_params)
114115

116+
_context = self.get_service_context()
117+
if _context.callback is None:
118+
_context.callback = {}
119+
120+
for _cb in CALLBACK_URIS:
121+
_uri = config.get(_cb)
122+
if _uri:
123+
_context.callback[_cb] = _uri
124+
115125
def fetch_distributed_claims(self, userinfo, callback=None):
116126
"""
117127

src/oidcrp/oidc/end_session.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,14 @@ def get_id_token_hint(self, request_args=None, **kwargs):
5454

5555
def add_post_logout_redirect_uri(self, request_args=None, **kwargs):
5656
if 'post_logout_redirect_uri' not in request_args:
57-
try:
58-
request_args[
59-
'post_logout_redirect_uri'
60-
] = self.client_get("service_context").register_args[
61-
'post_logout_redirect_uris'][0]
62-
except KeyError:
63-
pass
57+
_context = self.client_get("service_context")
58+
_uri = _context.register_args.get('post_logout_redirect_uri')
59+
if _uri:
60+
request_args['post_logout_redirect_uri'] = _uri
61+
else:
62+
_uris = _context.callback.get("post_logout_redirect_uris", [])
63+
if _uris:
64+
request_args['post_logout_redirect_uri'] = _uris[0]
6465

6566
return request_args, {}
6667

src/oidcrp/oidc/registration.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from oidcmsg import oidc
88
from oidcmsg.oauth2 import ResponseMessage
99

10-
from oidcrp.oidc.provider_info_discovery import add_redirect_uris
1110
from oidcrp.service import Service
1211

1312
__author__ = 'Roland Hedberg'
@@ -81,7 +80,7 @@ def create_callbacks(issuer: str,
8180
res["request_uris"] = f"{base_url}/req_uri/{_hex}"
8281

8382
if backchannel_logout_uri or frontchannel_logout_uri:
84-
res["post_logout_redirect_uri"] = f"{base_url}/session_logout/{_hex}"
83+
res["post_logout_redirect_uris"] = [f"{base_url}/session_logout/{_hex}"]
8584

8685
if backchannel_logout_uri:
8786
res["backchannel_logout_uri"] = f"{base_url}/bc_logout/{_hex}"
@@ -163,7 +162,7 @@ def add_callbacks(context, ignore: Optional[List[str]] = None):
163162
context.set('callback', callbacks)
164163

165164

166-
CALLBACK_URIS = ["post_logout_redirect_uri", "backchannel_logout_uri", "frontchannel_logout_uri",
165+
CALLBACK_URIS = ["post_logout_redirect_uris", "backchannel_logout_uri", "frontchannel_logout_uri",
167166
"request_uris", 'redirect_uris']
168167

169168

src/oidcrp/rp_handler.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ def do_client_registration(self, client=None,
248248
"""
249249
Prepare for and do client registration if configured to do so
250250
251+
:param iss_id: Issuer ID
251252
:param behaviour_args: To fine tune behaviour
252253
:param client: A Client instance
253254
:param state: A key by which the state of the session can be
@@ -267,8 +268,8 @@ def do_client_registration(self, client=None,
267268
self.hash2issuer[iss_id] = _iss
268269

269270
# This should only be interesting if the client supports Single Log Out
270-
if _context.post_logout_redirect_uris is None:
271-
_context.post_logout_redirect_uris = [self.base_url]
271+
# if _context.callback.get("post_logout_redirect_uris") is None:
272+
# _context.callback["post_logout_redirect_uris"] = [self.base_url]
272273

273274
if not _context.client_id: # means I have to do dynamic client registration
274275
if request_args is None:

src/oidcrp/service_context.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class ServiceContext(OidcContext):
103103
"httpc_params": None,
104104
'issuer': None,
105105
"kid": None,
106-
"post_logout_redirect_uris": [],
106+
"post_logout_redirect_uri": '',
107107
'provider_info': None,
108108
'redirect_uris': None,
109109
"requests_dir": None,
@@ -137,7 +137,7 @@ def __init__(self, base_url="", keyjar=None, config=None, state=None, **kwargs):
137137
self.client_secret_expires_at = 0
138138
self.behaviour = {}
139139
self.provider_info = {}
140-
self.post_logout_redirect_uris = []
140+
self.post_logout_redirect_uri = ''
141141
self.redirect_uris = []
142142
self.register_args = {}
143143
self.registration_response = {}

tests/pub_client.jwks

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"keys": [{"kty": "RSA", "use": "sig", "kid": "SUswNi1MRFlDT0Y2YjU1Z1RfQlo2S3dEa3FTTkV3LThFcnhDTHF5elk2VQ", "n": "0UkUx2ewKyc-XJ1o0ToyGjws_JybAMZj2oYjsPyyvQ_T5dhZ2VmRRRkhsaVJ2xE_GGc7mSG0IjmGFyXp5y0w4mJBcsAEE5-8eBTvQdYIryjW74r3jt6Fi4Hlm1yFMTie3apv8mw79BUj-jT0kh3_m-FiKKUvLsq45DcLtTJ4cx7Ize37dl1sFSpQcoYMk7eiUEM8fiNboiVwvBYNAWVMkUM-LnVUPm3UjvKp0LihYEkZFWOxmuQmj2x25SFUkjus38ERrRqJQBZduxdBHFrWtWg8yOA53BkMU0FFg_r0H3ctl-5GaKw-BWlogU4qXnsq85xy0EoenRk7FPV8g_ulJw", "e": "AQAB"}, {"kty": "EC", "use": "sig", "kid": "NC1pdGRQN002bWM3bk1xX2R0SktscElqbFdtN29ITDV2WVd2b0hOYzREVQ", "crv": "P-256", "x": "kK7Qp1woSerI7rUOAwW_4sU6ZmwV3wwXKX3VU-v2fMI", "y": "iPWd_Pjq6EjxYy08KNFZ3PxhEwgWHgAQTTknlKMKJA0"}]}
1+
{"keys": [{"kty": "RSA", "use": "sig", "kid": "SUswNi1MRFlDT0Y2YjU1Z1RfQlo2S3dEa3FTTkV3LThFcnhDTHF5elk2VQ", "e": "AQAB", "n": "0UkUx2ewKyc-XJ1o0ToyGjws_JybAMZj2oYjsPyyvQ_T5dhZ2VmRRRkhsaVJ2xE_GGc7mSG0IjmGFyXp5y0w4mJBcsAEE5-8eBTvQdYIryjW74r3jt6Fi4Hlm1yFMTie3apv8mw79BUj-jT0kh3_m-FiKKUvLsq45DcLtTJ4cx7Ize37dl1sFSpQcoYMk7eiUEM8fiNboiVwvBYNAWVMkUM-LnVUPm3UjvKp0LihYEkZFWOxmuQmj2x25SFUkjus38ERrRqJQBZduxdBHFrWtWg8yOA53BkMU0FFg_r0H3ctl-5GaKw-BWlogU4qXnsq85xy0EoenRk7FPV8g_ulJw"}, {"kty": "EC", "use": "sig", "kid": "NC1pdGRQN002bWM3bk1xX2R0SktscElqbFdtN29ITDV2WVd2b0hOYzREVQ", "crv": "P-256", "x": "kK7Qp1woSerI7rUOAwW_4sU6ZmwV3wwXKX3VU-v2fMI", "y": "iPWd_Pjq6EjxYy08KNFZ3PxhEwgWHgAQTTknlKMKJA0"}]}

tests/test_13_oidc_service.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -891,9 +891,8 @@ def test_construct(self):
891891
'token_response', 'abcde')
892892
_req = self.service.construct(state='abcde')
893893
assert isinstance(_req, EndSessionRequest)
894-
assert len(_req) == 3
895-
assert set(_req.keys()) == {'state', 'id_token_hint',
896-
'post_logout_redirect_uri'}
894+
assert len(_req) == 2
895+
assert set(_req.keys()) == {'state', 'id_token_hint'}
897896

898897

899898
def test_authz_service_conf():

tests/test_20_rp_handler_oidc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ def test_do_client_registration(self):
312312
# only 2 things should have happened
313313

314314
assert self.rph.hash2issuer['github'] == issuer
315-
assert client.client_get("service_context").post_logout_redirect_uris == []
315+
assert client.client_get("service_context").callback.get("post_logout_redirect_uris") is None
316316

317317
def test_do_client_setup(self):
318318
client = self.rph.client_setup('github')

0 commit comments

Comments
 (0)