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

Commit c58e605

Browse files
committed
Added more needed methods.
Bumped version
1 parent 20827a2 commit c58e605

7 files changed

Lines changed: 105 additions & 31 deletions

File tree

src/oidcservice/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
__author__ = 'Roland Hedberg'
12-
__version__ = '0.6.0'
12+
__version__ = '0.6.1'
1313

1414

1515
OIDCONF_PATTERN = "{}/.well-known/openid-configuration"

src/oidcservice/oidc/end_session.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ class EndSession(Service):
1717
response_cls = Message
1818
error_msg = ResponseMessage
1919
endpoint_name = 'end_session_endpoint'
20-
synchronous = False
20+
synchronous = True
2121
service_name = 'end_session'
22+
response_body_type = 'html'
2223

2324
def __init__(self, service_context, state_db, client_authn_factory=None,
2425
conf=None):
@@ -56,7 +57,8 @@ def add_post_logout_redirect_uri(self, request_args=None, **kwargs):
5657
try:
5758
request_args[
5859
'post_logout_redirect_uri'
59-
] = self.service_context.post_logout_redirect_uris[0]
60+
] = self.service_context.register_args[
61+
'post_logout_redirect_uris'][0]
6062
except KeyError:
6163
pass
6264

src/oidcservice/oidc/registration.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def add_request_uri(request_args=None, service=None, **kwargs):
4343
if _context.requests_dir:
4444
try:
4545
if _context.provider_info[
46-
'require_request_uri_registration'] is True:
46+
'require_request_uri_registration'] is True:
4747
request_args['request_uris'] = _context.generate_request_uris(
4848
_context.requests_dir)
4949
except KeyError:
@@ -64,8 +64,9 @@ def add_post_logout_redirect_uris(request_args=None, service=None, **kwargs):
6464

6565
if "post_logout_redirect_uris" not in request_args:
6666
try:
67-
_uris = service.service_context.post_logout_redirect_uris
68-
except AttributeError:
67+
_uris = service.service_context.register_args[
68+
'post_logout_redirect_uris']
69+
except KeyError:
6970
pass
7071
else:
7172
request_args["post_logout_redirect_uris"] = _uris

src/oidcservice/service.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,12 @@ def gather_request_args(self, **kwargs):
9494
ar_args[prop] = self.conf['request_args'][prop]
9595
except KeyError:
9696
try:
97-
ar_args[prop] = self.default_request_args[prop]
97+
ar_args[prop] = self.service_context.register_args[prop]
9898
except KeyError:
99-
pass
99+
try:
100+
ar_args[prop] = self.default_request_args[prop]
101+
except KeyError:
102+
pass
100103

101104
return ar_args
102105

@@ -286,7 +289,7 @@ def get_request_parameters(self, request_body_type="", method="",
286289
"""
287290
Builds the request message and constructs the HTTP headers.
288291
289-
This is the starting pont for a pipeline that will:
292+
This is the starting point for a pipeline that will:
290293
291294
- construct the request message
292295
- add/remove information to/from the request message in the way a

src/oidcservice/service_context.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
# This represents a map between the local storage of algorithm choices
1212
# and how they are represented in a provider info response.
13+
from oidcmsg.oidc import RegistrationRequest
1314

1415
CLI_REG_MAP = {
1516
"userinfo": {
@@ -72,6 +73,7 @@ def __init__(self, keyjar=None, config=None, **kwargs):
7273
# Below so my IDE won't complain
7374
self.base_url = ''
7475
self.requests_dir = ''
76+
self.register_args = {}
7577
self.allow = {}
7678
self.behaviour = {}
7779
self.client_preferences = {}
@@ -87,13 +89,18 @@ def __init__(self, keyjar=None, config=None, **kwargs):
8789
for key, val in kwargs.items():
8890
setattr(self, key, val)
8991

90-
for attr in ['client_id', 'issuer', 'base_url', 'requests_dir',
91-
'post_logout_redirect_uris']:
92+
for attr in ['client_id', 'issuer', 'base_url', 'requests_dir']:
9293
try:
9394
setattr(self, attr, config[attr])
9495
except:
9596
setattr(self, attr, '')
9697

98+
for attr in RegistrationRequest.c_param.keys():
99+
try:
100+
self.register_args[attr] = config[attr]
101+
except KeyError:
102+
pass
103+
97104
for attr in ['allow', 'client_preferences', 'behaviour',
98105
'provider_info']:
99106
try:

src/oidcservice/state_interface.py

Lines changed: 79 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import json
2+
13
from oidcmsg.message import Message
24
from oidcmsg.message import SINGLE_OPTIONAL_JSON
35
from oidcmsg.message import SINGLE_REQUIRED_STRING
@@ -20,7 +22,9 @@ class State(Message):
2022

2123
KEY_PATTERN = {
2224
'nonce': '__{}__',
23-
'logout state': '::{}::'
25+
'logout state': '::{}::',
26+
'session id': '..{}..',
27+
'subject id': '=={}=='
2428
}
2529

2630

@@ -197,30 +201,38 @@ def multiple_extend_request_args(self, args, key, parameters, item_types,
197201

198202
return args
199203

200-
def store_X2state(self, nonce, state, xtyp):
204+
def store_X2state(self, x, state, xtyp):
201205
"""
202-
Store the connection between a nonce value and a state value.
206+
Store the connection between some value and a state value.
203207
This allows us later in the game to find the state if we have the nonce.
204208
205-
:param nonce: The nonce value
209+
:param x: The value of x
206210
:param state: The state value
211+
:param xtyp: The type of value x is (e.g. nonce, ...)
207212
"""
208-
self.state_db.set(KEY_PATTERN[xtyp].format(nonce), state)
213+
self.state_db.set(KEY_PATTERN[xtyp].format(x), state)
214+
_val = self.state_db.get("ref{}ref".format(state))
215+
if _val is None:
216+
refs = {xtyp:x}
217+
else:
218+
refs = json.loads(_val)
219+
refs[xtyp] = x
220+
self.state_db.set("ref{}ref".format(state), json.dumps(refs))
209221

210-
def get_state_by_X(self, nonce, xtyp):
222+
def get_state_by_X(self, x, xtyp):
211223
"""
212-
Find the state value by providing the nonce value.
213-
Will raise an exception if the nonce value is absent from the state
224+
Find the state value by providing the x value.
225+
Will raise an exception if the x value is absent from the state
214226
data base.
215227
216-
:param nonce: The nonce value
228+
:param x: The x value
217229
:return: The state value
218230
"""
219-
_state = self.state_db.get(KEY_PATTERN[xtyp].format(nonce))
231+
_state = self.state_db.get(KEY_PATTERN[xtyp].format(x))
220232
if _state:
221233
return _state
222234
else:
223-
raise KeyError('Unknown {}: "{}"'.format(xtyp, nonce))
235+
raise KeyError('Unknown {}: "{}"'.format(xtyp, x))
224236

225237
def store_nonce2state(self, nonce, state):
226238
"""
@@ -245,8 +257,9 @@ def get_state_by_nonce(self, nonce):
245257

246258
def store_logout_state2state(self, logout_state, state):
247259
"""
248-
Store the connection between a nonce value and a state value.
249-
This allows us later in the game to find the state if we have the nonce.
260+
Store the connection between a logout state value and a state value.
261+
This allows us later in the game to find the state if we have the
262+
logout state value.
250263
251264
:param logout_state: The logout state value
252265
:param state: The state value
@@ -255,15 +268,59 @@ def store_logout_state2state(self, logout_state, state):
255268

256269
def get_state_by_logout_state(self, logout_state):
257270
"""
258-
Find the state value by providing the nonce value.
259-
Will raise an exception if the nonce value is absent from the state
260-
data base.
271+
Find the state value by providing the logout state value.
272+
Will raise an exception if the logout state value is absent from the
273+
state data base.
261274
262-
:param nonce: The nonce value
275+
:param logout_state: The logout state value
263276
:return: The state value
264277
"""
265278
return self.get_state_by_X(logout_state, 'logout state')
266279

280+
def store_sid2state(self, sid, state):
281+
"""
282+
Store the connection between a session id (sid) value and a state value.
283+
This allows us later in the game to find the state if we have the
284+
sid value.
285+
286+
:param sid: The session ID value
287+
:param state: The state value
288+
"""
289+
self.store_X2state(sid, state, 'session id')
290+
291+
def get_state_by_sid(self, sid):
292+
"""
293+
Find the state value by providing the logout state value.
294+
Will raise an exception if the logout state value is absent from the
295+
state data base.
296+
297+
:param sid: The session ID value
298+
:return: The state value
299+
"""
300+
return self.get_state_by_X(sid, 'session id')
301+
302+
def store_sub2state(self, sub, state):
303+
"""
304+
Store the connection between a subject id (sub) value and a state value.
305+
This allows us later in the game to find the state if we have the
306+
sub value.
307+
308+
:param sub: The Subject ID value
309+
:param state: The state value
310+
"""
311+
self.store_X2state(sub, state, 'subject id')
312+
313+
def get_state_by_sub(self, sub):
314+
"""
315+
Find the state value by providing the subject id value.
316+
Will raise an exception if the subject id value is absent from the
317+
state data base.
318+
319+
:param sub: The Subject ID value
320+
:return: The state value
321+
"""
322+
return self.get_state_by_X(sub, 'subject id')
323+
267324
def create_state(self, iss, key=''):
268325
if not key:
269326
key = rndstr(32)
@@ -277,4 +334,8 @@ def create_state(self, iss, key=''):
277334
return key
278335

279336
def remove_state(self, state):
280-
self.state_db.delete(state)
337+
self.state_db.delete(state)
338+
refs = json.loads(self.state_db.get("ref{}ref".format(state)))
339+
if refs:
340+
for xtyp, x in refs.items():
341+
self.state_db.delete(KEY_PATTERN[xtyp].format(x))

tests/test_13_oic_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,8 +583,8 @@ def test_construct(self):
583583
assert len(_req) == 4
584584

585585
def test_config_with_post_logout(self):
586-
self.service.service_context.post_logout_redirect_uris = [
587-
'https://example.com/post_logout']
586+
self.service.service_context.register_args[
587+
'post_logout_redirect_uris'] = ['https://example.com/post_logout']
588588
_req = self.service.construct()
589589
assert isinstance(_req, RegistrationRequest)
590590
assert len(_req) == 5

0 commit comments

Comments
 (0)