|
1 | 1 | /* |
2 | | - * Copyright 2020-2023 the original author or authors. |
| 2 | + * Copyright 2020-2025 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
34 | 34 | import org.springframework.security.oauth2.core.OAuth2ErrorCodes; |
35 | 35 | import org.springframework.security.oauth2.core.OAuth2UserCode; |
36 | 36 | import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames; |
| 37 | +import org.springframework.security.oauth2.core.oidc.OidcScopes; |
37 | 38 | import org.springframework.security.oauth2.server.authorization.OAuth2Authorization; |
38 | 39 | import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService; |
39 | 40 | import org.springframework.security.oauth2.server.authorization.client.RegisteredClient; |
@@ -165,6 +166,23 @@ public void authenticateWhenInvalidScopesThenThrowOAuth2AuthenticationException( |
165 | 166 | // @formatter:on |
166 | 167 | } |
167 | 168 |
|
| 169 | + @Test |
| 170 | + public void authenticateWhenOpenIdScopeThenThrowOAuth2AuthenticationException() { |
| 171 | + RegisteredClient registeredClient = TestRegisteredClients.registeredClient() |
| 172 | + .authorizationGrantType(AuthorizationGrantType.DEVICE_CODE) |
| 173 | + .scope(OidcScopes.OPENID) |
| 174 | + .build(); |
| 175 | + Authentication authentication = createAuthentication(registeredClient); |
| 176 | + // @formatter:off |
| 177 | + assertThatExceptionOfType(OAuth2AuthenticationException.class) |
| 178 | + .isThrownBy(() -> this.authenticationProvider.authenticate(authentication)) |
| 179 | + .withMessageContaining(OAuth2ParameterNames.SCOPE) |
| 180 | + .extracting(OAuth2AuthenticationException::getError) |
| 181 | + .extracting(OAuth2Error::getErrorCode) |
| 182 | + .isEqualTo(OAuth2ErrorCodes.INVALID_SCOPE); |
| 183 | + // @formatter:on |
| 184 | + } |
| 185 | + |
168 | 186 | @Test |
169 | 187 | public void authenticateWhenDeviceCodeIsNullThenThrowOAuth2AuthenticationException() { |
170 | 188 | @SuppressWarnings("unchecked") |
|
0 commit comments