Class DefaultClientScopeAuthorizationCodeRequestConverter
- All Implemented Interfaces:
org.springframework.security.web.authentication.AuthenticationConverter
OAuth2AuthorizationCodeRequestAuthenticationConverter to create an
OAuth2AuthorizationCodeRequestAuthenticationToken or OAuth2PushedAuthorizationRequestAuthenticationToken from the request.
OAuth2AuthorizationCodeRequestAuthenticationToken is returned for standard /oauth2/authorize requests,
whereas OAuth2PushedAuthorizationRequestAuthenticationToken is returned for Pushed Authorization Requests (PAR) at /oauth2/par.
This implementation adds the ability to use default scopes if no scopes are requested. If there are no scopes on the request, then the scopes from the RegisteredClient will be used as requested scopes.
Scope validation and authorization is performed in
ScopeNarrowingOAuth2AuthorizationCodeRequestAuthenticationProvider.getUserAuthorizedScopes(OAuth2AuthorizationCodeRequestAuthenticationToken, RegisteredClient).
- Author:
- Cade Rea (cade-rea)
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultClientScopeAuthorizationCodeRequestConverter(org.springframework.security.oauth2.server.authorization.client.RegisteredClientRepository registeredClientRepository) -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.security.core.Authenticationconvert(jakarta.servlet.http.HttpServletRequest request) protected org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationCodeRequestAuthenticationTokenconvertAuthorizationCodeRequest(org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationCodeRequestAuthenticationToken requestToken) protected org.springframework.security.oauth2.server.authorization.authentication.OAuth2PushedAuthorizationRequestAuthenticationTokenconvertPushedAuthorizationRequest(org.springframework.security.oauth2.server.authorization.authentication.OAuth2PushedAuthorizationRequestAuthenticationToken requestToken) protected org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationCodeRequestAuthenticationExceptioncreateClientIdException(org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationCodeRequestAuthenticationToken requestToken) Prepare anOAuth2AuthorizationCodeRequestAuthenticationException.protected org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationCodeRequestAuthenticationExceptioncreateClientIdException(org.springframework.security.oauth2.server.authorization.authentication.OAuth2PushedAuthorizationRequestAuthenticationToken requestToken) Prepare anOAuth2AuthorizationCodeRequestAuthenticationException.getClientScopes(org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationCodeRequestAuthenticationToken requestToken) Read the scopes from theRegisteredClientspecified by theOAuth2ParameterNames.CLIENT_IDparameter.getClientScopes(org.springframework.security.oauth2.server.authorization.authentication.OAuth2PushedAuthorizationRequestAuthenticationToken requestToken) Read the scopes from theRegisteredClientspecified by theOAuth2ParameterNames.CLIENT_IDparameter.protected org.springframework.security.oauth2.server.authorization.client.RegisteredClientRepository
-
Constructor Details
-
DefaultClientScopeAuthorizationCodeRequestConverter
public DefaultClientScopeAuthorizationCodeRequestConverter(org.springframework.security.oauth2.server.authorization.client.RegisteredClientRepository registeredClientRepository)
-
-
Method Details
-
convert
public org.springframework.security.core.Authentication convert(jakarta.servlet.http.HttpServletRequest request) - Specified by:
convertin interfaceorg.springframework.security.web.authentication.AuthenticationConverter
-
convertPushedAuthorizationRequest
protected org.springframework.security.oauth2.server.authorization.authentication.OAuth2PushedAuthorizationRequestAuthenticationToken convertPushedAuthorizationRequest(org.springframework.security.oauth2.server.authorization.authentication.OAuth2PushedAuthorizationRequestAuthenticationToken requestToken) -
convertAuthorizationCodeRequest
protected org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationCodeRequestAuthenticationToken convertAuthorizationCodeRequest(org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationCodeRequestAuthenticationToken requestToken) -
getClientScopes
protected Set<String> getClientScopes(org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationCodeRequestAuthenticationToken requestToken) Read the scopes from theRegisteredClientspecified by theOAuth2ParameterNames.CLIENT_IDparameter.This logic is modeled after the logic used in
ScopeNarrowingOAuth2AuthorizationCodeRequestAuthenticationProvider.authenticate(Authentication)to retrieve the RegisteredClient.- Parameters:
requestToken- TheOAuth2AuthorizationCodeRequestAuthenticationTokenthat represents the auth code request.- Returns:
- The set of scopes specified on the
AuthorizedClient. - See Also:
-
getClientScopes
protected Set<String> getClientScopes(org.springframework.security.oauth2.server.authorization.authentication.OAuth2PushedAuthorizationRequestAuthenticationToken requestToken) Read the scopes from theRegisteredClientspecified by theOAuth2ParameterNames.CLIENT_IDparameter.- Parameters:
requestToken- TheOAuth2PushedAuthorizationRequestAuthenticationTokenthat represents the pushed auth code request.- Returns:
- The set of scopes specified on the
AuthorizedClient. - See Also:
-
createClientIdException
protected org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationCodeRequestAuthenticationException createClientIdException(org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationCodeRequestAuthenticationToken requestToken) Prepare anOAuth2AuthorizationCodeRequestAuthenticationException. Adapted fromOAuth2AuthorizationCodeRequestAuthenticationProvider.- Parameters:
requestToken- Container for parameters of the Authorization Code request.- Returns:
- An
OAuth2AuthorizationCodeRequestAuthenticationExceptionthat describes the authorization error. - See Also:
-
OAuth2AuthorizationCodeRequestAuthenticationProvider.throwError(String, String, OAuth2AuthorizationCodeRequestAuthenticationToken, RegisteredClient)ScopeNarrowingOAuth2AuthorizationCodeRequestAuthenticationProvider.throwError(String, String, OAuth2AuthorizationCodeRequestAuthenticationToken, RegisteredClient)
-
createClientIdException
protected org.springframework.security.oauth2.server.authorization.authentication.OAuth2AuthorizationCodeRequestAuthenticationException createClientIdException(org.springframework.security.oauth2.server.authorization.authentication.OAuth2PushedAuthorizationRequestAuthenticationToken requestToken) Prepare anOAuth2AuthorizationCodeRequestAuthenticationException.- Parameters:
requestToken- Container for parameters of the Pushed Authorization request.- Returns:
- An
OAuth2AuthorizationCodeRequestAuthenticationExceptionthat describes the authorization error.
-
getRegisteredClientRepository
protected org.springframework.security.oauth2.server.authorization.client.RegisteredClientRepository getRegisteredClientRepository()
-