Skip to content

Commit 97f49ae

Browse files
committed
Fix per-client configuration of deny_unknown_scopes
Signed-off-by: Kostis Triantafyllakis <[email protected]>
1 parent 869068c commit 97f49ae

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/idpyoidc/server/oauth2/authorization.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,9 @@ def authn_args_gather(
268268

269269

270270
def check_unknown_scopes_policy(request_info, client_id, context):
271-
if not context.get_preference("deny_unknown_scopes"):
271+
cinfo = context.cdb.get(client_id, {})
272+
deny_unknown_scopes = cinfo.get("deny_unknown_scopes", context.get_preference("deny_unknown_scopes"))
273+
if not deny_unknown_scopes:
272274
return
273275

274276
scope = request_info["scope"]

tests/test_server_24_oauth2_authorization_endpoint.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,38 @@ def test_setup_auth_invalid_scope(self):
588588
assert excp
589589
assert isinstance(excp, UnAuthorizedClientScope)
590590

591+
def test_setup_auth_invalid_scope_2(self):
592+
request = AuthorizationRequest(
593+
client_id="client_id",
594+
redirect_uri="https://rp.example.com/cb",
595+
response_type=["id_token"],
596+
state="state",
597+
nonce="nonce",
598+
scope="openid THAT-BLOODY_SCOPE",
599+
)
600+
cinfo = {
601+
"client_id": "client_id",
602+
"redirect_uris": [("https://rp.example.com/cb", {})],
603+
"id_token_signed_response_alg": "RS256",
604+
"allowed_scopes": ["openid", "profile", "email", "address", "phone", "offline_access"],
605+
"deny_unknown_scopes": True
606+
}
607+
608+
_context = self.endpoint.upstream_get("context")
609+
_context.cdb["client_id"] = cinfo
610+
611+
kaka = _context.cookie_handler.make_cookie_content("value", "sso")
612+
613+
# force to 400 Http Error message if the release scope policy is heavy!
614+
_context.set_preference("deny_unknown_scopes", False)
615+
excp = None
616+
try:
617+
res = self.endpoint.process_request(request, http_info={"headers": {"cookie": [kaka]}})
618+
except UnAuthorizedClientScope as e:
619+
excp = e
620+
assert excp
621+
assert isinstance(excp, UnAuthorizedClientScope)
622+
591623
def test_setup_auth_user(self):
592624
request = AuthorizationRequest(
593625
client_id="client_id",

0 commit comments

Comments
 (0)