File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed
oauth2/oauth2-authorization-server/src
main/java/org/springframework/security/oauth2/server/authorization/authentication
test/java/org/springframework/security/oauth2/server/authorization/authentication Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change 4040import org .springframework .security .oauth2 .core .OAuth2ErrorCodes ;
4141import org .springframework .security .oauth2 .core .OAuth2UserCode ;
4242import org .springframework .security .oauth2 .core .endpoint .OAuth2ParameterNames ;
43+ import org .springframework .security .oauth2 .core .oidc .OidcScopes ;
4344import org .springframework .security .oauth2 .server .authorization .OAuth2Authorization ;
4445import org .springframework .security .oauth2 .server .authorization .OAuth2AuthorizationService ;
4546import 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 ()) {
Original file line number Diff line number Diff line change 3535import org .springframework .security .oauth2 .core .OAuth2ErrorCodes ;
3636import org .springframework .security .oauth2 .core .OAuth2UserCode ;
3737import org .springframework .security .oauth2 .core .endpoint .OAuth2ParameterNames ;
38+ import org .springframework .security .oauth2 .core .oidc .OidcScopes ;
3839import org .springframework .security .oauth2 .server .authorization .OAuth2Authorization ;
3940import org .springframework .security .oauth2 .server .authorization .OAuth2AuthorizationService ;
4041import 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" )
You can’t perform that action at this time.
0 commit comments