Class OAuth2AuthorizationRequestRedirectFilter
- All Implemented Interfaces:
jakarta.servlet.Filter
,org.springframework.beans.factory.Aware
,org.springframework.beans.factory.BeanNameAware
,org.springframework.beans.factory.DisposableBean
,org.springframework.beans.factory.InitializingBean
,org.springframework.context.EnvironmentAware
,org.springframework.core.env.EnvironmentCapable
,org.springframework.web.context.ServletContextAware
Filter
initiates the authorization code grant flow by redirecting the
End-User's user-agent to the Authorization Server's Authorization Endpoint.
It builds the OAuth 2.0 Authorization Request, which is used as the redirect
URI
to the Authorization Endpoint. The redirect URI
will include the
client identifier, requested scope(s), state, response type, and a redirection URI
which the authorization server will send the user-agent back to once access is granted
(or denied) by the End-User (Resource Owner).
By default, this Filter
responds to authorization requests at the URI
/oauth2/authorization/{registrationId}
using the default
OAuth2AuthorizationRequestResolver
. The URI
template variable
{registrationId}
represents the registration identifier
of the client that is used for initiating the OAuth 2.0
Authorization Request.
The default base URI
/oauth2/authorization
may be overridden via the
constructor
OAuth2AuthorizationRequestRedirectFilter(ClientRegistrationRepository, String)
,
or alternatively, an OAuth2AuthorizationRequestResolver
may be provided to the
constructor
OAuth2AuthorizationRequestRedirectFilter(OAuth2AuthorizationRequestResolver)
to override the resolving of authorization requests.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The default baseURI
used for authorization requests.Fields inherited from class org.springframework.web.filter.OncePerRequestFilter
ALREADY_FILTERED_SUFFIX
Fields inherited from class org.springframework.web.filter.GenericFilterBean
logger
-
Constructor Summary
ConstructorDescriptionOAuth2AuthorizationRequestRedirectFilter
(ClientRegistrationRepository clientRegistrationRepository) Constructs anOAuth2AuthorizationRequestRedirectFilter
using the provided parameters.OAuth2AuthorizationRequestRedirectFilter
(ClientRegistrationRepository clientRegistrationRepository, String authorizationRequestBaseUri) Constructs anOAuth2AuthorizationRequestRedirectFilter
using the provided parameters.OAuth2AuthorizationRequestRedirectFilter
(OAuth2AuthorizationRequestResolver authorizationRequestResolver) Constructs anOAuth2AuthorizationRequestRedirectFilter
using the provided parameters. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
doFilterInternal
(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.FilterChain filterChain) void
setAuthenticationFailureHandler
(AuthenticationFailureHandler authenticationFailureHandler) Sets theAuthenticationFailureHandler
used to handle errors redirecting to the Authorization Server's Authorization Endpoint.void
setAuthorizationRedirectStrategy
(RedirectStrategy authorizationRedirectStrategy) Sets the redirect strategy for Authorization Endpoint redirect URI.final void
setAuthorizationRequestRepository
(AuthorizationRequestRepository<OAuth2AuthorizationRequest> authorizationRequestRepository) Sets the repository used for storingOAuth2AuthorizationRequest
's.final void
setRequestCache
(RequestCache requestCache) Sets theRequestCache
used for storing the current request before redirecting the OAuth 2.0 Authorization Request.Methods inherited from class org.springframework.web.filter.OncePerRequestFilter
doFilter, doFilterNestedErrorDispatch, getAlreadyFilteredAttributeName, isAsyncDispatch, isAsyncStarted, shouldNotFilter, shouldNotFilterAsyncDispatch, shouldNotFilterErrorDispatch
Methods inherited from class org.springframework.web.filter.GenericFilterBean
addRequiredProperty, afterPropertiesSet, createEnvironment, destroy, getEnvironment, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContext
-
Field Details
-
DEFAULT_AUTHORIZATION_REQUEST_BASE_URI
The default baseURI
used for authorization requests.- See Also:
-
-
Constructor Details
-
OAuth2AuthorizationRequestRedirectFilter
public OAuth2AuthorizationRequestRedirectFilter(ClientRegistrationRepository clientRegistrationRepository) Constructs anOAuth2AuthorizationRequestRedirectFilter
using the provided parameters.- Parameters:
clientRegistrationRepository
- the repository of client registrations
-
OAuth2AuthorizationRequestRedirectFilter
public OAuth2AuthorizationRequestRedirectFilter(ClientRegistrationRepository clientRegistrationRepository, String authorizationRequestBaseUri) Constructs anOAuth2AuthorizationRequestRedirectFilter
using the provided parameters.- Parameters:
clientRegistrationRepository
- the repository of client registrationsauthorizationRequestBaseUri
- the baseURI
used for authorization requests
-
OAuth2AuthorizationRequestRedirectFilter
public OAuth2AuthorizationRequestRedirectFilter(OAuth2AuthorizationRequestResolver authorizationRequestResolver) Constructs anOAuth2AuthorizationRequestRedirectFilter
using the provided parameters.- Parameters:
authorizationRequestResolver
- the resolver used for resolving authorization requests- Since:
- 5.1
-
-
Method Details
-
setAuthorizationRedirectStrategy
Sets the redirect strategy for Authorization Endpoint redirect URI.- Parameters:
authorizationRedirectStrategy
- the redirect strategy
-
setAuthorizationRequestRepository
public final void setAuthorizationRequestRepository(AuthorizationRequestRepository<OAuth2AuthorizationRequest> authorizationRequestRepository) Sets the repository used for storingOAuth2AuthorizationRequest
's.- Parameters:
authorizationRequestRepository
- the repository used for storingOAuth2AuthorizationRequest
's
-
setRequestCache
Sets theRequestCache
used for storing the current request before redirecting the OAuth 2.0 Authorization Request.- Parameters:
requestCache
- the cache used for storing the current request
-
setAuthenticationFailureHandler
public void setAuthenticationFailureHandler(AuthenticationFailureHandler authenticationFailureHandler) Sets theAuthenticationFailureHandler
used to handle errors redirecting to the Authorization Server's Authorization Endpoint.- Parameters:
authenticationFailureHandler
- theAuthenticationFailureHandler
used to handle errors redirecting to the Authorization Server's Authorization Endpoint- Since:
- 6.3
-
doFilterInternal
protected void doFilterInternal(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.FilterChain filterChain) throws jakarta.servlet.ServletException, IOException - Specified by:
doFilterInternal
in classorg.springframework.web.filter.OncePerRequestFilter
- Throws:
jakarta.servlet.ServletException
IOException
-