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

Commit 9389042

Browse files
committed
If you want to turn off refresh access token.
1 parent 00d1527 commit 9389042

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

src/oidcendpoint/oidc/token_coop.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from oidcendpoint import sanitize
1515
from oidcendpoint.cookie import new_cookie
1616
from oidcendpoint.endpoint import Endpoint
17+
from oidcendpoint.exception import ProcessError
1718
from oidcendpoint.token_handler import AccessCodeUsed
1819
from oidcendpoint.token_handler import ExpiredToken
1920
from oidcendpoint.userinfo import by_schema
@@ -40,6 +41,7 @@ def __init__(self, endpoint_context, **kwargs):
4041
self.endpoint_info["token_endpoint_auth_methods_supported"] = kwargs[
4142
"client_authn_method"
4243
]
44+
self.allow_refresh = kwargs.get("allow_refresh", True)
4345

4446
def _refresh_access_token(self, req, **kwargs):
4547
_sdb = self.endpoint_context.sdb
@@ -198,7 +200,10 @@ def _post_parse_request(self, request, client_id="", **kwargs):
198200
if request["grant_type"] == "authorization_code":
199201
return self._access_token_post_parse_request(request, client_id, **kwargs)
200202
else: # request["grant_type"] == "refresh_token":
201-
return self._refresh_token_post_parse_request(request, client_id, **kwargs)
203+
if self.allow_refresh:
204+
return self._refresh_token_post_parse_request(request, client_id, **kwargs)
205+
else:
206+
raise ProcessError("Refresh Token not allowed")
202207

203208
def process_request(self, request=None, **kwargs):
204209
"""

tests/test_35_oidc_token_coop_endpoint.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from oidcendpoint.client_authn import verify_client
1313
from oidcendpoint.endpoint_context import EndpointContext
1414
from oidcendpoint.exception import MultipleUsage
15+
from oidcendpoint.exception import ProcessError
1516
from oidcendpoint.oidc import userinfo
1617
from oidcendpoint.oidc.authorization import Authorization
1718
from oidcendpoint.oidc.provider_config import ProviderConfiguration
@@ -306,3 +307,23 @@ def test_do_2nd_refresh_access_token(self):
306307
}
307308
msg = self.endpoint.do_response(request=_req, **_resp)
308309
assert isinstance(msg, dict)
310+
311+
def test_do_refresh_access_token_not_allowed(self):
312+
areq = AUTH_REQ.copy()
313+
areq["scope"] = ["openid", "offline_access"]
314+
_cntx = self.endpoint.endpoint_context
315+
session_id = setup_session(
316+
_cntx, areq, uid="user", acr=INTERNETPROTOCOLPASSWORD
317+
)
318+
_cntx.sdb.update(session_id, user="diana")
319+
_token_request = TOKEN_REQ_DICT.copy()
320+
_token_request["code"] = _cntx.sdb[session_id]["code"]
321+
_req = self.endpoint.parse_request(_token_request)
322+
_resp = self.endpoint.process_request(request=_req)
323+
324+
self.endpoint.allow_refresh = False
325+
326+
_request = REFRESH_TOKEN_REQ.copy()
327+
_request["refresh_token"] = _resp["response_args"]["refresh_token"]
328+
with pytest.raises(ProcessError):
329+
self.endpoint.parse_request(_request.to_json())

0 commit comments

Comments
 (0)