Skip to content
Open
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 @@ -50,6 +50,7 @@
* used in the OAuth 2.0 Device Authorization Grant.
*
* @author Steve Riesenberg
* @author Andrey Litvitski
* @since 7.0
* @see OAuth2DeviceAuthorizationConsentAuthenticationToken
* @see OAuth2AuthorizationConsent
Expand Down Expand Up @@ -183,7 +184,7 @@ public Authentication authenticate(Authentication authentication) throws Authent
OAuth2Authorization.Token<OAuth2UserCode> userCodeToken = authorization.getToken(OAuth2UserCode.class);
Assert.notNull(userCodeToken, "userCode cannot be null");

if (authorities.isEmpty()) {
if (authorities.isEmpty() && !requestedScopes.isEmpty()) {
// Authorization consent denied (or revoked)
if (currentAuthorizationConsent != null) {
this.authorizationConsentService.remove(currentAuthorizationConsent);
Expand All @@ -203,11 +204,13 @@ public Authentication authenticate(Authentication authentication) throws Authent
throw createException(OAuth2ErrorCodes.ACCESS_DENIED, OAuth2ParameterNames.CLIENT_ID);
}

OAuth2AuthorizationConsent authorizationConsent = authorizationConsentBuilder.build();
if (currentAuthorizationConsent == null || !authorizationConsent.equals(currentAuthorizationConsent)) {
this.authorizationConsentService.save(authorizationConsent);
if (this.logger.isTraceEnabled()) {
this.logger.trace("Saved authorization consent");
if (!authorities.isEmpty()) {
OAuth2AuthorizationConsent authorizationConsent = authorizationConsentBuilder.build();
if (currentAuthorizationConsent == null || !authorizationConsent.equals(currentAuthorizationConsent)) {
Comment on lines +207 to +209

@therepanic therepanic Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If left unprocessed, the following OAuth2AuthorizationConsent.Builder#build assertiong will be executed

public OAuth2AuthorizationConsent build() {
    Assert.notEmpty(this.authorities, "authorities cannot be empty");
    return new OAuth2AuthorizationConsent(this.registeredClientId, this.principalName, this.authorities);
}

this.authorizationConsentService.save(authorizationConsent);
if (this.logger.isTraceEnabled()) {
this.logger.trace("Saved authorization consent");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
* Tests for {@link OAuth2DeviceAuthorizationConsentAuthenticationProvider}.
*
* @author Steve Riesenberg
* @author Andrey Litvitski
*/
public class OAuth2DeviceAuthorizationConsentAuthenticationProviderTests {

Expand Down Expand Up @@ -274,9 +275,12 @@ public void authenticateWhenRequestedScopesNotAuthorizedThenThrowOAuth2Authentic
@Test
public void authenticateWhenAuthoritiesIsEmptyThenThrowOAuth2AuthenticationException() {
RegisteredClient registeredClient = TestRegisteredClients.registeredClient().build();
RegisteredClient registeredClient2 = TestRegisteredClients.registeredClient().scopes(Set::clear).build();
OAuth2Authorization authorization = createAuthorization(registeredClient2);
Authentication authentication = createAuthentication(registeredClient2);
OAuth2Authorization authorization = createAuthorization(registeredClient);
TestingAuthenticationToken principal = new TestingAuthenticationToken("principal", null,
Collections.emptyList());
Authentication authentication = new OAuth2DeviceAuthorizationConsentAuthenticationToken(AUTHORIZATION_URI,
registeredClient.getClientId(), principal, USER_CODE, STATE, Collections.emptySet(),
Collections.emptyMap());
given(this.authorizationService.findByToken(anyString(), any(OAuth2TokenType.class))).willReturn(authorization);
given(this.registeredClientRepository.findByClientId(anyString())).willReturn(registeredClient);
// @formatter:off
Expand Down
Loading