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

Commit 30250dc

Browse files
committed
Merge
2 parents 55c9e82 + 9d68324 commit 30250dc

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

flask_rp/application.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import re
23

34
from cryptojwt import KeyJar
45
from cryptojwt.key_jar import init_key_jar
@@ -23,16 +24,15 @@ def init_oidc_rp_handler(app):
2324
if rp_keys_conf:
2425
_kj = init_key_jar(**rp_keys_conf)
2526
_path = rp_keys_conf['public_path']
26-
if _path.startswith('./'):
27-
_path = _path[2:]
28-
elif _path.startswith('/'):
29-
_path = _path[1:]
27+
# replaces ./ and / from the begin of the string
28+
_path = re.sub('^(.)/', '', _path)
3029
else:
3130
_kj = KeyJar()
3231
_path = ''
3332
_kj.verify_ssl = verify_ssl
3433

35-
rph = RPHandler(base_url=app.config.get('BASEURL'), hash_seed=hash_seed,
34+
rph = RPHandler(base_url=app.config.get('BASEURL'),
35+
hash_seed=hash_seed,
3636
keyjar=_kj, jwks_path=_path,
3737
client_configs=app.config.get('CLIENTS'),
3838
services=app.config.get('SERVICES'),

flask_rp/views.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from flask import session
1111
from flask.helpers import make_response
1212
from flask.helpers import send_from_directory
13+
from oidcservice.exception import OidcServiceError
1314

1415
import oidcrp
1516

@@ -91,21 +92,31 @@ def get_rp(op_hash):
9192
def finalize(op_hash, request_args):
9293
rp = get_rp(op_hash)
9394

94-
try:
95-
session['client_id'] = rp.service_context.registration_response['client_id']
96-
except KeyError:
97-
session['client_id'] = rp.service_context.client_id
95+
if hasattr(rp, 'status_code') and rp.status_code != 200:
96+
logger.error(rp.response[0].decode())
97+
return rp.response[0], rp.status_code
9898

99-
session['state'] = request_args['state']
100-
try:
101-
iss = rp.session_interface.get_iss(request_args['state'])
102-
except KeyError:
99+
session['client_id'] = rp.service_context.registration_response.\
100+
get('client_id', rp.service_context.client_id)
101+
102+
session['state'] = request_args.get('state')
103+
104+
if session['state']:
105+
iss = rp.session_interface.get_iss(session['state'])
106+
else:
103107
return make_response('Unknown state', 400)
104108

105109
session['session_state'] = request_args.get('session_state', '')
106110

107111
logger.debug('Issuer: {}'.format(iss))
108-
res = current_app.rph.finalize(iss, request_args)
112+
113+
try:
114+
res = current_app.rph.finalize(iss, request_args)
115+
except OidcServiceError as excp:
116+
# replay attack prevention, is that code was already used before
117+
return excp.__str__(), 403
118+
except Exception as excp:
119+
raise excp
109120

110121
if 'userinfo' in res:
111122
endpoints = {}

0 commit comments

Comments
 (0)