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

Commit 6e0b9bf

Browse files
authored
Merge pull request #118 from nsklikas/fix-expired-token-response
Handle exception raised from expired JWT access token
2 parents 852e710 + 9429d57 commit 6e0b9bf

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

src/oidcop/client_authn.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from oidcop.exception import InvalidClient
2323
from oidcop.exception import MultipleUsage
2424
from oidcop.exception import NotForMe
25+
from oidcop.exception import ToOld
2526
from oidcop.exception import UnknownClient
2627
from oidcop.util import importer
2728

@@ -409,6 +410,8 @@ def verify_client(
409410
try:
410411
# get_client_id_from_token is a callback... Do not abuse for code readability.
411412
auth_info["client_id"] = get_client_id_from_token(endpoint_context, _token, request)
413+
except ToOld:
414+
raise ValueError("Expired token")
412415
except KeyError:
413416
raise ValueError("Unknown token")
414417

tests/test_26_oidc_userinfo_endpoint.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,27 @@ def test_invalid_token(self):
381381
assert isinstance(args, ResponseMessage)
382382
assert args["error_description"] == "Invalid Token"
383383

384+
def test_expired_token(self, monkeypatch):
385+
_auth_req = AUTH_REQ.copy()
386+
_auth_req["scope"] = ["openid", "research_and_scholarship"]
387+
388+
session_id = self._create_session(_auth_req)
389+
grant = self.session_manager[session_id]
390+
access_token = self._mint_token("access_token", grant, session_id)
391+
392+
http_info = {"headers": {"authorization": "Bearer {}".format(access_token.value)}}
393+
394+
def mock():
395+
return time_sans_frac() + access_token.expires_at + 1
396+
397+
monkeypatch.setattr("oidcop.token.time_sans_frac", mock)
398+
399+
_req = self.endpoint.parse_request({}, http_info=http_info)
400+
401+
assert _req.to_dict() == {
402+
"error": "invalid_token", "error_description": "Expired token"
403+
}
404+
384405
def test_userinfo_claims(self):
385406
_acr = "https://refeds.org/profile/mfa"
386407
_auth_req = AUTH_REQ.copy()

0 commit comments

Comments
 (0)