Skip to content

Authorize request should fail if scope request parameter is not provided #289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,16 @@ private void validateAuthorizationRequest(OAuth2AuthorizationRequestContext auth
return;
}

// scope (OPTIONAL)
// scope (REQUIRED)
// If the client omits the scope parameter when requesting
// authorization, the authorization server MUST either process the
// request using a pre-defined default value or fail the request
// indicating an invalid scope. The authorization server SHOULD
// document its scope requirements and default value (if defined).
// TODO Allow configuration for scope request parameter behavior
Set<String> requestedScopes = authorizationRequestContext.getScopes();
Set<String> allowedScopes = registeredClient.getScopes();
if (!requestedScopes.isEmpty() && !allowedScopes.containsAll(requestedScopes)) {
if (requestedScopes.isEmpty() || !allowedScopes.containsAll(requestedScopes)) {
authorizationRequestContext.setError(
createError(OAuth2ErrorCodes.INVALID_SCOPE, OAuth2ParameterNames.SCOPE));
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,21 @@ public void doFilterWhenAuthorizationRequestInvalidResponseTypeThenUnsupportedRe
request -> request.setParameter(OAuth2ParameterNames.RESPONSE_TYPE, "id_token"));
}

// gh-288
@Test
public void doFilterWhenAuthorizationRequestMissingScopeThenInvalidScopeError() throws Exception {
RegisteredClient registeredClient = TestRegisteredClients.registeredClient().build();
when(this.registeredClientRepository.findByClientId((eq(registeredClient.getClientId()))))
.thenReturn(registeredClient);

doFilterWhenAuthorizationRequestInvalidParameterThenRedirect(
registeredClient,
OAuth2ParameterNames.SCOPE,
OAuth2ErrorCodes.INVALID_SCOPE,
DEFAULT_ERROR_URI,
request -> request.removeParameter(OAuth2ParameterNames.SCOPE));
}

@Test
public void doFilterWhenAuthorizationRequestInvalidScopeThenInvalidScopeError() throws Exception {
RegisteredClient registeredClient = TestRegisteredClients.registeredClient().build();
Expand Down