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

Commit 635dd24

Browse files
authored
Merge pull request #138 from nsklikas/feature-allowed-scope
Use filter_scopes in check_unknown_scopes_policy
2 parents 47120f8 + 49c6cec commit 635dd24

3 files changed

Lines changed: 13 additions & 10 deletions

File tree

src/oidcop/oauth2/authorization.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,16 @@ def check_unknown_scopes_policy(request_info, client_id, endpoint_context):
250250
if not endpoint_context.conf["capabilities"].get("deny_unknown_scopes"):
251251
return
252252

253-
allowed_scopes = endpoint_context.scopes_handler.get_allowed_scopes(client_id=client_id)
254-
253+
scope = request_info["scope"]
254+
filtered_scopes = set(
255+
endpoint_context.scopes_handler.filter_scopes(scope, client_id=client_id)
256+
)
257+
scopes = set(scope)
255258
# this prevents that authz would be released for unavailable scopes
256-
for scope in request_info["scope"]:
257-
if scope not in allowed_scopes:
258-
_msg = "{} requested an unauthorized scope ({})"
259-
logger.warning(_msg.format(client_id, scope))
260-
raise UnAuthorizedClientScope()
259+
if scopes != filtered_scopes:
260+
diff = " ".join(scopes - filtered_scopes)
261+
logger.warning(f"{client_id} requested unauthorized scopes: {diff}")
262+
raise UnAuthorizedClientScope()
261263

262264

263265
class Authorization(Endpoint):

src/oidcop/scopes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ def convert_scopes2claims(scopes, allowed_claims=None, scope2claim_map=None):
3131
res = {}
3232
if allowed_claims is None:
3333
for scope in scopes:
34-
claims = {name: None for name in scope2claim_map[scope]}
34+
claims = {name: None for name in scope2claim_map.get(scope, [])}
3535
res.update(claims)
3636
else:
3737
for scope in scopes:
3838
try:
39-
claims = {name: None for name in scope2claim_map[scope] if name in allowed_claims}
39+
claims = {name: None for name in scope2claim_map.get(scope, []) if name in allowed_claims}
4040
res.update(claims)
4141
except KeyError:
4242
continue

tests/test_26_oidc_userinfo_endpoint.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,10 @@ def test_scopes_to_claims_per_client(self):
360360
"eduperson_scoped_affiliation",
361361
],
362362
}
363+
self.endpoint_context.cdb["client_1"]["allowed_scopes"] = list(self.endpoint_context.cdb["client_1"]["scopes_to_claims"].keys()) + ["aba"]
363364

364365
_auth_req = AUTH_REQ.copy()
365-
_auth_req["scope"] = ["openid", "research_and_scholarship_2"]
366+
_auth_req["scope"] = ["openid", "research_and_scholarship_2", "aba"]
366367

367368
session_id = self._create_session(_auth_req)
368369
grant = self.session_manager[session_id]

0 commit comments

Comments
 (0)