Skip to content

Commit 63f6ed3

Browse files
authored
Merge pull request #66 from IdentityPython/enforce-aud-restriction
Option for audience restriction enforcement
2 parents bc9e3ad + 09a39a0 commit 63f6ed3

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/idpyoidc/server/oauth2/introspection.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Introspection(Endpoint):
3232
def __init__(self, upstream_get, **kwargs):
3333
Endpoint.__init__(self, upstream_get, **kwargs)
3434
self.offset = kwargs.get("offset", 0)
35+
self.enforce_aud_restriction = kwargs.get("enforce_audience_restriction", True)
3536

3637
def _introspect(self, token, client_id, grant):
3738
# Make sure that the token is an access_token or a refresh_token
@@ -114,8 +115,17 @@ def process_request(self, request=None, release: Optional[list] = None, **kwargs
114115
if not aud:
115116
aud = grant.resources
116117

117-
if request["client_id"] not in aud:
118-
return {"response_args": _resp}
118+
client_id = request["client_id"]
119+
try:
120+
_cinfo = _context.cdb[client_id]
121+
enforce_aud_restriction = _cinfo.get(
122+
"enforce_audience_restriction", self.enforce_aud_restriction
123+
)
124+
except:
125+
enforce_aud_restriction = self.enforce_aud_restriction
126+
if enforce_aud_restriction:
127+
if request["client_id"] not in aud:
128+
return {"response_args": _resp}
119129

120130
_info = self._introspect(_token, _session_info["client_id"], _session_info["grant"])
121131
if _info is None:

tests/test_server_31_oauth2_introspection.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ def create_endpoint(self, jwt_token):
132132
"kwargs": {
133133
"client_authn_method": ["client_secret_post"],
134134
"enable_claims_per_client": False,
135+
"enforce_audience_restriction": True,
135136
},
136137
},
137138
"token": {

0 commit comments

Comments
 (0)