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

Commit 9a2f6cf

Browse files
authored
Merge pull request #125 from IdentityPython/certification
Certification testing - bug fixes
2 parents d920971 + 3abbb14 commit 9a2f6cf

20 files changed

Lines changed: 345 additions & 116 deletions

example/flask_op/views.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,16 @@ def do_response(endpoint, req_args, error='', **args):
7878
if error:
7979
if _response_placement == 'body':
8080
_log.info('Error Response: {}'.format(info['response']))
81-
resp = make_response(info['response'], 400)
81+
_http_response_code = info.get('response_code', 400)
82+
resp = make_response(info['response'], _http_response_code)
8283
else: # _response_placement == 'url':
8384
_log.info('Redirect to: {}'.format(info['response']))
8485
resp = redirect(info['response'])
8586
else:
8687
if _response_placement == 'body':
8788
_log.info('Response: {}'.format(info['response']))
88-
resp = make_response(info['response'], 200)
89+
_http_response_code = info.get('response_code', 200)
90+
resp = make_response(info['response'], _http_response_code)
8991
else: # _response_placement == 'url':
9092
_log.info('Redirect to: {}'.format(info['response']))
9193
resp = redirect(info['response'])
@@ -166,10 +168,14 @@ def registration():
166168
current_app.server.server_get("endpoint", 'registration'))
167169

168170

169-
@oidc_op_views.route('/registration_api', methods=['GET'])
171+
@oidc_op_views.route('/registration_api', methods=['GET', 'DELETE'])
170172
def registration_api():
171-
return service_endpoint(
172-
current_app.server.server_get("endpoint", 'registration_read'))
173+
if request.method == "DELETE":
174+
return service_endpoint(
175+
current_app.server.server_get("endpoint", 'registration_delete'))
176+
else:
177+
return service_endpoint(
178+
current_app.server.server_get("endpoint", 'registration_read'))
173179

174180

175181
@oidc_op_views.route('/authorization')
@@ -245,10 +251,14 @@ def service_endpoint(endpoint):
245251
err_msg = ResponseMessage(error='invalid_request', error_description=str(err))
246252
return make_response(err_msg.to_json(), 400)
247253

248-
_log.info('request: {}'.format(req_args))
249254
if isinstance(req_args, ResponseMessage) and 'error' in req_args:
250-
return make_response(req_args.to_json(), 400)
255+
_log.info('Error response: {}'.format(req_args))
256+
_resp = make_response(req_args.to_json(), 400)
257+
if request.method == "POST":
258+
_resp.headers["Content-type"] = "application/json"
259+
return _resp
251260
try:
261+
_log.info('request: {}'.format(req_args))
252262
if isinstance(endpoint, Token):
253263
args = endpoint.process_request(AccessTokenRequest(**req_args), http_info=http_info)
254264
else:

src/oidcop/configure.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@
5959
"max_usage": 1,
6060
},
6161
"access_token": {},
62-
"refresh_token": {"supports_minting": ["access_token", "refresh_token"]},
62+
"refresh_token": {
63+
"supports_minting": ["access_token", "refresh_token"],
64+
"expires_in": -1
65+
},
6366
},
6467
"expires_in": 43200,
6568
}
@@ -380,7 +383,10 @@ def __init__(
380383
"max_usage": 1,
381384
},
382385
"access_token": {},
383-
"refresh_token": {"supports_minting": ["access_token", "refresh_token"]},
386+
"refresh_token": {
387+
"supports_minting": ["access_token", "refresh_token"],
388+
"expires_in": -1
389+
},
384390
},
385391
"expires_in": 43200,
386392
}

src/oidcop/constant.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
DIVIDER = ";;"
2+
3+
DEFAULT_TOKEN_LIFETIME = 1800

src/oidcop/cookie_handler.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ def _ver_dec_content(self, parts):
167167
try:
168168
msg = decrypter.decrypt(ciphertext, iv, tag=tag)
169169
except InvalidTag:
170+
LOGGER.debug("Decryption failed")
170171
return None
171172

172173
p = lv_unpack(msg.decode("utf-8"))
@@ -180,6 +181,8 @@ def _ver_dec_content(self, parts):
180181
self.sign_key.key,
181182
):
182183
return payload, timestamp
184+
else:
185+
LOGGER.debug("Could not verify signature")
183186
else:
184187
return payload, timestamp
185188
return None
@@ -247,12 +250,18 @@ def parse_cookie(self, name: str, cookies: List[dict]) -> Optional[List[dict]]:
247250
if not cookies:
248251
return None
249252

253+
LOGGER.debug("Looking for '{}' cookies".format(name))
250254
res = []
251255
for _cookie in cookies:
252-
if _cookie["name"] == name:
253-
payload, timestamp = self._ver_dec_content(_cookie["value"].split("|"))
254-
value, typ = payload.split("::")
255-
res.append({"value": value, "type": typ, "timestamp": timestamp})
256+
LOGGER.debug('Cookie: {}'.format(_cookie))
257+
if "name" in _cookie and _cookie["name"] == name:
258+
_content = self._ver_dec_content(_cookie["value"].split("|"))
259+
if _content:
260+
payload, timestamp = self._ver_dec_content(_cookie["value"].split("|"))
261+
value, typ = payload.split("::")
262+
res.append({"value": value, "type": typ, "timestamp": timestamp})
263+
else:
264+
LOGGER.debug(f"Could not verify {name} cookie")
256265
return res
257266

258267

src/oidcop/endpoint.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,6 @@ def __init__(self, server_get: Callable, **kwargs):
128128
self.allowed_targets = [self.name]
129129
self.client_verification_method = []
130130

131-
def parse_cookies(self, cookies: List[dict], context: EndpointContext, name: str):
132-
res = context.cookie_handler.parse_cookie(name, cookies)
133-
return res
134-
135131
def parse_request(
136132
self, request: Union[Message, dict, str], http_info: Optional[dict] = None, **kwargs
137133
):
@@ -330,10 +326,9 @@ def do_response(
330326
resp = None
331327
if error:
332328
_response = ResponseMessage(error=error)
333-
try:
334-
_response["error_description"] = kwargs["error_description"]
335-
except KeyError:
336-
pass
329+
for attr in ["error_description", "error_uri", "state"]:
330+
if attr in kwargs:
331+
_response[attr] = kwargs[attr]
337332
elif "response_msg" in kwargs:
338333
resp = kwargs["response_msg"]
339334
_response_placement = kwargs.get("response_placement")
@@ -405,6 +400,11 @@ def do_response(
405400
except KeyError:
406401
pass
407402

403+
try:
404+
_resp["response_code"] = kwargs["response_code"]
405+
except KeyError:
406+
pass
407+
408408
return _resp
409409

410410
def allowed_target_uris(self):

0 commit comments

Comments
 (0)