Skip to content

Commit 570672c

Browse files
author
Willem van Dreumel
committed
PAR using requested scopes on consent
PAR was missing the scopes when giving consent. Making consent authentications distinguish between requested and already authorized scopes. Fixes gh-2175 Signed-off-by: Willem van Dreumel <willem.vandreumel@edsn.nl>
1 parent ded91ea commit 570672c

File tree

3 files changed

+326
-4
lines changed

3 files changed

+326
-4
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
import java.util.Arrays;
2121
import java.util.Base64;
2222
import java.util.Collections;
23+
import java.util.HashMap;
2324
import java.util.HashSet;
25+
import java.util.Map;
2426
import java.util.Set;
2527
import java.util.function.Consumer;
2628
import java.util.function.Predicate;
@@ -282,8 +284,13 @@ public Authentication authenticate(Authentication authentication) throws Authent
282284
Set<String> currentAuthorizedScopes = (currentAuthorizationConsent != null)
283285
? currentAuthorizationConsent.getScopes() : null;
284286

287+
Map<String, Object> additionalParameters = new HashMap<>();
288+
if (pushedAuthorization != null) {
289+
additionalParameters.put(OAuth2ParameterNames.SCOPE, authorizationRequest.getScopes());
290+
}
291+
285292
return new OAuth2AuthorizationConsentAuthenticationToken(authorizationRequest.getAuthorizationUri(),
286-
registeredClient.getClientId(), principal, state, currentAuthorizedScopes, null);
293+
registeredClient.getClientId(), principal, state, currentAuthorizedScopes, additionalParameters);
287294
}
288295

289296
OAuth2TokenContext tokenContext = createAuthorizationCodeTokenContext(authorizationCodeRequestAuthentication,

oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/web/OAuth2AuthorizationEndpointFilter.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,20 @@ private void sendAuthorizationConsent(HttpServletRequest request, HttpServletRes
292292

293293
String clientId = authorizationConsentAuthentication.getClientId();
294294
Authentication principal = (Authentication) authorizationConsentAuthentication.getPrincipal();
295-
Set<String> requestedScopes = authorizationCodeRequestAuthentication.getScopes();
296295
Set<String> authorizedScopes = authorizationConsentAuthentication.getScopes();
297296
String state = authorizationConsentAuthentication.getState();
298297

298+
Set<String> requestedScopes;
299+
String requestUri = (String) authorizationCodeRequestAuthentication.getAdditionalParameters()
300+
.get(OAuth2ParameterNames.REQUEST_URI);
301+
if (StringUtils.hasText(requestUri)) {
302+
requestedScopes = (Set<String>) authorizationConsentAuthentication.getAdditionalParameters()
303+
.get(OAuth2ParameterNames.SCOPE);
304+
}
305+
else {
306+
requestedScopes = authorizationCodeRequestAuthentication.getScopes();
307+
}
308+
299309
if (hasConsentUri()) {
300310
String redirectUri = UriComponentsBuilder.fromUriString(resolveConsentUri(request))
301311
.queryParam(OAuth2ParameterNames.SCOPE, String.join(" ", requestedScopes))

0 commit comments

Comments
 (0)