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

Commit c0bb0ca

Browse files
committed
Don't issue refresh token if not configured
1 parent 9a2f6cf commit c0bb0ca

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

src/oidcop/oauth2/token.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,16 @@ def process_request(self, req: Union[Message, dict], **kwargs):
118118
return self.error_cls(error="invalid_request", error_description="Missing code")
119119

120120
_session_info = _mngr.get_session_info_by_token(_access_code, grant=True)
121-
if _session_info["client_id"] != req["client_id"]:
122-
logger.debug("{} owner of token".format(_session_info["client_id"]))
121+
client_id = _session_info["client_id"]
122+
if client_id != req["client_id"]:
123+
logger.debug("{} owner of token".format(client_id))
123124
logger.warning("Client using token it was not given")
124125
return self.error_cls(error="invalid_grant", error_description="Wrong client")
125126

127+
if "grant_types_supported" in _context.cdb[client_id]:
128+
grant_types_supported = _context.cdb[client_id].get("grant_types_supported")
129+
else:
130+
grant_types_supported = _context.provider_info["grant_types_supported"]
126131
grant = _session_info["grant"]
127132

128133
_based_on = grant.get_token(_access_code)
@@ -162,7 +167,11 @@ def process_request(self, req: Union[Message, dict], **kwargs):
162167
if token.expires_at:
163168
_response["expires_in"] = token.expires_at - utc_time_sans_frac()
164169

165-
if issue_refresh and "refresh_token" in _supports_minting:
170+
if (
171+
issue_refresh
172+
and "refresh_token" in _supports_minting
173+
and "refresh_token" in grant_types_supported
174+
):
166175
try:
167176
refresh_token = self._mint_token(
168177
token_class="refresh_token",

src/oidcop/oidc/token.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,16 @@ def process_request(self, req: Union[Message, dict], **kwargs):
4545
_session_info = _mngr.get_session_info_by_token(_access_code, grant=True)
4646
logger.debug(f"Session info: {_session_info}")
4747

48-
if _session_info["client_id"] != req["client_id"]:
49-
logger.debug("{} owner of token".format(_session_info["client_id"]))
48+
client_id = _session_info["client_id"]
49+
if client_id != req["client_id"]:
50+
logger.debug("{} owner of token".format(client_id))
5051
logger.warning("{} using token it was not given".format(req["client_id"]))
5152
return self.error_cls(error="invalid_grant", error_description="Wrong client")
5253

54+
if "grant_types_supported" in _context.cdb[client_id]:
55+
grant_types_supported = _context.cdb[client_id].get("grant_types_supported")
56+
else:
57+
grant_types_supported = _context.provider_info["grant_types_supported"]
5358
grant = _session_info["grant"]
5459

5560
token_type = "Bearer"
@@ -110,7 +115,11 @@ def process_request(self, req: Union[Message, dict], **kwargs):
110115
if token.expires_at:
111116
_response["expires_in"] = token.expires_at - utc_time_sans_frac()
112117

113-
if issue_refresh and "refresh_token" in _supports_minting:
118+
if (
119+
issue_refresh
120+
and "refresh_token" in _supports_minting
121+
and "refresh_token" in grant_types_supported
122+
):
114123
try:
115124
refresh_token = self._mint_token(
116125
token_class="refresh_token",

0 commit comments

Comments
 (0)