Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public final class LinkingOAuth2UserService
- Object
- LinkingOAuth2UserService
Signs the user of an identity provider in as a user of the application’s own.
LinkingOAuth2UserService linking = new LinkingOAuth2UserService(identities, users);
linking.setCreateUsers(true);
http.oauth2Login(oauth2 -> oauth2
.userService(linking)
.oidcUserService(linking.oidc()));Who the provider’s user is here is decided in this order:
An identity – this provider, this subject – that is tied to a local user already signs in as that user. Nothing else about the provider’s answer is consulted: not the email, which may have changed since.
Otherwise the provider must say the user’s email address is one it has verified. An address it does not vouch for is refused with
EMAIL_NOT_VERIFIED, whether or not anybody here has it: tying an account to an address somebody merely typed at a provider would hand that account to them.A provider whose registration names a
ClientRegistration.ProviderDetails.getUserEmailsUri– GitHub, whose user carries no such flag and often no address – is asked there instead, with the user’s access token: the address is the one the list marks bothprimaryandverified, and whatever the user info said of an address is not consulted. No such entry, or a list that cannot be read (theuser:emailscope was not granted), is refused the same way.A verified address that is the name of a local user ties the identity to that user, and signs in as them.
A verified address nobody here has makes a new local user of that name – when
setCreateUsersallows it and the users are aUserDetailsManager– and is refused withACCOUNT_NOT_FOUNDotherwise.
The user that comes back is named after the local account and has its authorities, with the provider’s attributes beside them; a second factor and remember-me, which go by name, then apply to it exactly as they do to a sign-in with a password.
A new user has a password nobody knows: 256 random bits under an encoding id no encoder has. They sign in through the provider until they set one.
Fields
public static final String EMAIL_NOT_VERIFIED = "email_not_verified" | The provider does not vouch for the user’s email address. |
public static final String ACCOUNT_NOT_FOUND = "account_not_found" | Nobody here has the address, and new users are not made. |
public static final String ACCOUNT_UNAVAILABLE = "account_unavailable" | The local user the identity is tied to cannot sign in. |
Constructors
public LinkingOAuth2UserService(FederatedIdentityRepository identities, UserDetailsService users) |
Methods
Inherited methods
Field details
EMAIL_NOT_VERIFIED
public static final String EMAIL_NOT_VERIFIED = "email_not_verified"ACCOUNT_NOT_FOUND
public static final String ACCOUNT_NOT_FOUND = "account_not_found"ACCOUNT_UNAVAILABLE
public static final String ACCOUNT_UNAVAILABLE = "account_unavailable"Constructor details
LinkingOAuth2UserService
public LinkingOAuth2UserService(FederatedIdentityRepository identities, UserDetailsService users)Parameters
identitiesFederatedIdentityRepository- Not documented.
usersUserDetailsService- the application’s users; a
UserDetailsManagerto let new ones be made
Method details
setCreateUsers
public void setCreateUsers(boolean createUsers)setNewUserAuthorities
public void setNewUserAuthorities(Collection<? extends GrantedAuthority> authorities)ROLE_USER unless set.setEmailAttributes
public void setEmailAttributes(String emailAttribute, String emailVerifiedAttribute)email and email_verified unless set.setOAuth2UserService
public void setOAuth2UserService(OAuth2UserService<OAuth2UserRequest, OAuth2User> service)setOidcUserService
public void setOidcUserService(OAuth2UserService<OidcUserRequest, OidcUser> service)loadUser
public OAuth2User loadUser(OAuth2UserRequest userRequest)The user.
OAuth2AuthenticationException: to refuse the sign-in
oidc
public OAuth2UserService<OidcUserRequest, OidcUser> oidc()