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

Commit 5879a9a

Browse files
committed
Verify correct user
1 parent 88da05a commit 5879a9a

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/oidcop/oidc/token.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def process_request(self, req: Union[Message, dict], **kwargs):
3232
_context = self.endpoint.server_get("endpoint_context")
3333

3434
_mngr = _context.session_manager
35-
_log_debug = logger.debug
35+
logger.debug("OIDC Access Token")
3636

3737
if req["grant_type"] != "authorization_code":
3838
return self.error_cls(error="invalid_request", error_description="Unknown grant_type")
@@ -43,6 +43,13 @@ def process_request(self, req: Union[Message, dict], **kwargs):
4343
return self.error_cls(error="invalid_request", error_description="Missing code")
4444

4545
_session_info = _mngr.get_session_info_by_token(_access_code, grant=True)
46+
logger.debug(f"Session info: {_session_info}")
47+
48+
if _session_info["client_id"] != req["client_id"]:
49+
logger.debug("{} owner of token".format(_session_info["client_id"]))
50+
logger.warning("{} using token it was not given".format(req["client_id"]))
51+
return self.error_cls(error="invalid_grant", error_description="Wrong client")
52+
4653
grant = _session_info["grant"]
4754

4855
token_type = "Bearer"
@@ -72,7 +79,7 @@ def process_request(self, req: Union[Message, dict], **kwargs):
7279
error="invalid_request", error_description="redirect_uri mismatch"
7380
)
7481

75-
_log_debug("All checks OK")
82+
logger.debug("All checks OK")
7683

7784
issue_refresh = False
7885
if "issue_refresh" in kwargs:
@@ -195,6 +202,11 @@ def process_request(self, req: Union[Message, dict], **kwargs):
195202

196203
token_value = req["refresh_token"]
197204
_session_info = _mngr.get_session_info_by_token(token_value, grant=True)
205+
if _session_info["client_id"] != req["client_id"]:
206+
logger.debug("{} owner of token".format(_session_info["client_id"]))
207+
logger.warning("{} using token it was not given".format(req["client_id"]))
208+
return self.error_cls(error="invalid_grant", error_description="Wrong client")
209+
198210
_grant = _session_info["grant"]
199211

200212
token_type = "Bearer"

0 commit comments

Comments
 (0)