Package com.irurueta.authserver.authorization.api.web.social
package com.irurueta.authserver.authorization.api.web.social
Social login (identity brokering) through external identity providers: Google, Microsoft Entra ID, Apple and GitHub.
Everything here is inert until at least one provider is configured with a client id
(
authserver.social.providers.<id>.client-id); with none the login chain is exactly the one without it.-
ClassDescriptionCustomizes the authorization request: Apple only hands over the name and the e-mail address of the user when the response is posted to the redirect URI (
response_mode=form_post), so the request made for Apple's client id asks for it.Generates the client secret Sign in with Apple requires: a JWT signed with ES256 by the key Apple issued (issthe team id,subthe client id,audhttps://appleid.apple.com, headerkidthe key id), valid for a short time.Reads the private key Apple issues for Sign in with Apple (an EC P-256 key in PKCS#8 PEM form, the content of the.p8file) from the text an environment variable holds, where line breaks are often written as a literal\n.Condition that holds when Sign in with Apple is configured, so the key of its client secret is only parsed and its special handling (the signed client secret, the form post callback) only installed then.Customizes the parameters of the token request of the authorization code grant: the request made for Apple's client id carries the signed JWT ofAppleClientSecretGeneratoras itsclient_secret, in place of the empty secret the registration holds.Maps the settings of the enabled providers onto the client registrations Spring Security'soauth2Loginneeds.Validates the issuer of an ID token of Microsoft Entra ID in a multi-tenant application.Finds the local account of a sign-in with an external provider and refuses it unless that account may sign in.Failure handler of the sign-in with an external provider.Success handler of the sign-in with an external provider.Registers the sign-in with an external provider as an authentication factor, in two flavours that are never held together by one session:FederatedFactor.AUTHORITY(fed, aFactorStrength.PRIMARYfactor): the normal case.Decides which factor a federated sign-in proved: the strong one when the provider is trusted for its multi-factor authentication (authserver.social.providers.<id>.trust-mfa) and its upstreamamrcontainsmfa, the ordinary one otherwise.The user service of the providers that are plain OAuth 2.0 (GitHub), which have no ID token: the framework's service reads the profile from the provider's API, the verified primary e-mail address is read from/user/emails(through the domain portVerifiedEmailLookup, implemented by the GitHub adapter ofinfrastructure/githubwith a client generated from the contract of that GitHub operation), the account is resolved (found, linked by verified e-mail or provisioned, and refused when it may not sign in) and the principal becomes the local one, named after the account.The user service of the OpenID Connect providers (Google, Microsoft, Apple): the framework's service loads the user as it always does (the ID token, and the UserInfo endpoint where the provider has one), then the account is resolved (found, linked by verified e-mail or provisioned, and refused when it may not sign in) and the principal becomes the local one, named after the account.Maps the user an external provider described onto the user the rest of the server sees: the principal of the session, whose name is the local account's username (so it is thesubof the issued tokens, as it is for every other way of signing in), whose authorities are the account's own, and which still carries the claims of the provider (theamramong them).Keeps the identities page and its link post behind the multi-factor policy, as the passkeys and phone pages are: a session that only presented the password of an account that still has to complete its second factor is sent to the second-factor page instead of being able to add a way to sign in to the account.Declares the chain customizer of the identities page.Serves the account page of the linked identities and the form post that starts linking another one, as the contractapis/auth-server/web-pages/auth-server-pages-v1.yamldescribes them through the generatedIdentitiesPageApi.Manages the identities of external providers linked to the authenticated account (the operations of the contract).Maps the linked identities of the domain onto the DTO generated from the contract.Answers the failures of the identities API asapplication/problem+json.What the identities page shows of a linked identity.Maps the linked identities of the domain onto the view model of the identities page.Adds to the tokens of a user who signed in with an external provider the claimidp(the registration id of the provider).Chooses the validator of the ID token of each registration: the framework'sOidcIdTokenValidator, plus theEntraIssuerValidatorfor Microsoft (registered without an issuer, seeClientRegistrationMapper).The marker a signed-in user leaves in the session when asking to link an identity of an external provider: the next sign-in with that provider, before the marker expires, links the identity to this account instead of signing anybody in.Keeps the link marker (PendingIdentityLink) of the explicit link flow: the identities page records it in the session before sending the browser to the provider, and the user services consume it when the provider sends the user back.Base of the exception handlers of the APIs that remove a sign-in method of the account (the linked identities, the bound certificates): both refuse to remove the last way to sign in and both need a recent multi-factor sign-in, so both answer those failures the same way.Customizes the login/UI chain with the sign-in with external providers:http.oauth2Login(...)with the client registrations of the configured providers, the user services that resolve the local account, the success handler that grants the federated factor and, for Apple, the signed client secret and the form post callback.Installs the sign-in with external providers in the login/UI chain.Declares the generator of the Apple client secret, only while Apple is configured.Contributes the sign-in with the configured external providers to the login page: one link per enabled provider, below the password form and the passkeys.Settings of the sign-in with external providers, bound once fromauthserver.social.*and injected wherever one is needed; an invalid value stops the application at startup.Settings of one provider.Condition that holds when at least one social provider is configured, that is, when someauthserver.social.providers.<id>.client-idhas text.