Skip to content

Commit 4b810a8

Browse files
committed
Disallow usage of the openid scope in device authorization requests
Issue spring-projects/spring-authorization-server#2177
1 parent 0d261e9 commit 4b810a8

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

oauth2/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/authentication/OAuth2DeviceAuthorizationRequestAuthenticationProvider.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.springframework.security.oauth2.core.OAuth2ErrorCodes;
4141
import org.springframework.security.oauth2.core.OAuth2UserCode;
4242
import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames;
43+
import org.springframework.security.oauth2.core.oidc.OidcScopes;
4344
import org.springframework.security.oauth2.server.authorization.OAuth2Authorization;
4445
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService;
4546
import org.springframework.security.oauth2.server.authorization.OAuth2TokenType;
@@ -121,6 +122,9 @@ public Authentication authenticate(Authentication authentication) throws Authent
121122
throwError(OAuth2ErrorCodes.INVALID_SCOPE, OAuth2ParameterNames.SCOPE);
122123
}
123124
}
125+
if (requestedScopes.contains(OidcScopes.OPENID)) {
126+
throwError(OAuth2ErrorCodes.INVALID_SCOPE, OAuth2ParameterNames.SCOPE);
127+
}
124128
}
125129

126130
if (this.logger.isTraceEnabled()) {

oauth2/oauth2-authorization-server/src/test/java/org/springframework/security/oauth2/server/authorization/authentication/OAuth2DeviceAuthorizationRequestAuthenticationProviderTests.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.springframework.security.oauth2.core.OAuth2ErrorCodes;
3636
import org.springframework.security.oauth2.core.OAuth2UserCode;
3737
import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames;
38+
import org.springframework.security.oauth2.core.oidc.OidcScopes;
3839
import org.springframework.security.oauth2.server.authorization.OAuth2Authorization;
3940
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService;
4041
import org.springframework.security.oauth2.server.authorization.client.RegisteredClient;
@@ -166,6 +167,23 @@ public void authenticateWhenInvalidScopesThenThrowOAuth2AuthenticationException(
166167
// @formatter:on
167168
}
168169

170+
@Test
171+
public void authenticateWhenOpenIdScopeThenThrowOAuth2AuthenticationException() {
172+
RegisteredClient registeredClient = TestRegisteredClients.registeredClient()
173+
.authorizationGrantType(AuthorizationGrantType.DEVICE_CODE)
174+
.scope(OidcScopes.OPENID)
175+
.build();
176+
Authentication authentication = createAuthentication(registeredClient);
177+
// @formatter:off
178+
assertThatExceptionOfType(OAuth2AuthenticationException.class)
179+
.isThrownBy(() -> this.authenticationProvider.authenticate(authentication))
180+
.withMessageContaining(OAuth2ParameterNames.SCOPE)
181+
.extracting(OAuth2AuthenticationException::getError)
182+
.extracting(OAuth2Error::getErrorCode)
183+
.isEqualTo(OAuth2ErrorCodes.INVALID_SCOPE);
184+
// @formatter:on
185+
}
186+
169187
@Test
170188
public void authenticateWhenDeviceCodeIsNullThenThrowOAuth2AuthenticationException() {
171189
@SuppressWarnings("unchecked")

0 commit comments

Comments
 (0)