Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public final class OAuth2LoginConfigurer
- Object
- SecurityConfigurer
- OAuth2LoginConfigurer
Sign-in through another identity provider, with OAuth2 or OpenID Connect.
http.authorizeHttpRequests(auth -> auth.anyRequest().authenticated())
.oauth2Login(Customizer.withDefaults());
with, in application.properties,
cn1.security.oauth2.client.registration.google.client-id=...
cn1.security.oauth2.client.registration.google.client-secret=...
The providers are the application’s
ClientRegistrationRepository bean, or the registrations the configuration
declares; see ClientRegistrations and
CommonOAuth2Provider.
A sign-in starts at GET /oauth2/authorization/{registrationId}, which
sends the browser to the provider, and ends at
/login/oauth2/code/{registrationId}, where the provider sends it back.
Every request carries a state, a PKCE challenge and, with OpenID Connect,
a nonce; the answer is taken only when it repeats the state this
browser was given, the code is exchanged with the PKCE verifier, and an ID
token is accepted only as
OidcIdTokenDecoderFactory describes and with that nonce in it.
Who the provider’s user is here is the OAuth2UserService’s to say; see
userService and oidcUserService, and
LinkingOAuth2UserService for
tying them to the application’s own users. The sign-in then ends the way
every sign-in to a session does – see SessionSignIn – so a second factor
and remember-me apply to it.
A signed-in user goes back to the page that asked for the sign-in, or to
defaultSuccessUrl: nothing the provider or the request says chooses the
address. A refused one goes to /login?error, and is told nothing of why;
the reason, as an OAuth2 error code, is the
AuthenticationFailureHandler’s to read from the exception.
A chain that serves no login page of its own serves a plain one at
GET /login with a link per provider, and sends a request that must sign
in straight to the provider when there is only one.
Methods
Inherited methods
Method details
clientRegistrationRepository
public OAuth2LoginConfigurer clientRegistrationRepository(ClientRegistrationRepository clientRegistrationRepository)loginPage
public OAuth2LoginConfigurer loginPage(String loginPage)/oauth2/authorization/{registrationId} for each provider.authorizationRequestResolver
public OAuth2LoginConfigurer authorizationRequestResolver(OAuth2AuthorizationRequestResolver authorizationRequestResolver)DefaultOAuth2AuthorizationRequestResolver.authorizationEndpointBaseUri
public OAuth2LoginConfigurer authorizationEndpointBaseUri(String baseUri)/oauth2/authorization unless set.redirectionEndpointBaseUri
public OAuth2LoginConfigurer redirectionEndpointBaseUri(String baseUri)/login/oauth2/code unless set. A registration’s redirect address has
to agree with it.authorizationRequestRepository
public OAuth2LoginConfigurer authorizationRequestRepository(AuthorizationRequestRepository authorizationRequestRepository)CookieOAuth2AuthorizationRequestRepository.accessTokenResponseClient
public OAuth2LoginConfigurer accessTokenResponseClient(OAuth2AccessTokenResponseClient accessTokenResponseClient)userService
public OAuth2LoginConfigurer userService(OAuth2UserService<OAuth2UserRequest, OAuth2User> userService)oidcUserService
public OAuth2LoginConfigurer oidcUserService(OAuth2UserService<OidcUserRequest, OidcUser> oidcUserService)idTokenDecoderFactory
public OAuth2LoginConfigurer idTokenDecoderFactory(OidcIdTokenDecoderFactory factory)defaultSuccessUrl
public OAuth2LoginConfigurer defaultSuccessUrl(String defaultSuccessUrl)/ unless set.defaultSuccessUrl
public OAuth2LoginConfigurer defaultSuccessUrl(String defaultSuccessUrl, boolean alwaysUse)Parameters
defaultSuccessUrlString- Not documented.
alwaysUseboolean- go there even when a page asked for the sign-in
successHandler
public OAuth2LoginConfigurer successHandler(AuthenticationSuccessHandler successHandler)failureUrl
public OAuth2LoginConfigurer failureUrl(String failureUrl)?error unless set.failureHandler
public OAuth2LoginConfigurer failureHandler(AuthenticationFailureHandler failureHandler)OAuth2AuthenticationException
whose error says why.permitAll
public OAuth2LoginConfigurer permitAll()loginPage of the application’s.init
public void init(HttpSecurity http)configure
public void configure(HttpSecurity http)