Auth Service supports federated login via Google and GitHub using Spring Security’s OAuth2 client infrastructure. Rather than embedding the issued JWT access and refresh tokens in the redirect URL (which would expose them in browser history, proxy logs, andDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/ricardomb-tech/auth-service/llms.txt
Use this file to discover all available pages before exploring further.
Referer headers), the service follows a one-time exchange code pattern: after the provider authenticates the user, Auth Service redirects the browser to a frontend URL carrying a short-lived, opaque code parameter. The client then exchanges that code for the real token pair via a direct back-channel POST request. This keeps tokens out of the URL entirely.
OAuth2 login flow
Redirect the user to the provider
Your frontend sends the user’s browser to one of the two authorization endpoints. Spring Security handles building the full authorization URL, including GitHubNo request body or custom headers are required. Simply redirect or link the browser to these URLs.
state and code_challenge parameters. The state value is stored in a cookie (instead of the HTTP session) to keep the service fully stateless.GoogleUser authenticates with the provider
The user is taken to Google’s or GitHub’s consent screen. Auth Service is not involved at this stage. The provider validates the user’s identity and, if successful, redirects the browser back to the Auth Service callback URL.
Auth Service processes the callback
Spring Security validates the authorization code returned by the provider and fetches the user’s profile from the provider’s userinfo endpoint. For Google this uses the OIDC
id_token flow; for GitHub a custom GitHubOAuth2UserService resolves the primary verified email from the GitHub emails API.Federated identity linking: if the provider’s verified email matches an email address already registered in Auth Service (whether via credentials or another provider), the OAuth2 identity is linked to that existing account. No duplicate accounts are created. If no account exists for that email, a new one is created in ACTIVE state (email is considered verified by the provider).GitHub accounts that do not have a verified primary email (e.g. a private email-only setup with no public email) will fail the federated login. Auth Service requires a verified email from every provider.
Auth Service issues a one-time exchange code and redirects
On success, For example:
OAuth2AuthenticationSuccessHandler issues a short-lived, single-use exchange code (stored server-side) and redirects the browser to:The exchange code — not the access or refresh token — travels in the redirect URL. This is intentional: a code is useless once consumed, has a short TTL, and does not grant direct API access on its own. Tokens sent in query parameters would be logged by web servers, visible in browser history, and potentially leaked via the
Referer header to any third-party resource on the redirect target page.Exchange the code for tokens
Your frontend reads the Response — 200 OKThe response is identical to the credential login response (
code query parameter and immediately exchanges it for a real token pair by calling POST /auth/oauth2/exchange. This call should be made server-side or from a trusted context — not exposed as a user-facing URL.LoginResponse). From this point on, the access and refresh token lifecycle is the same as for credential-based login — see Token Management.If the exchange code is invalid, expired, or has already been consumed, the endpoint returns 401 Unauthorized with a application/problem+json body.Failure handling
When the OAuth2 flow fails — the user denies consent, the provider returns an error, or Auth Service cannot process the user’s profile — the browser is redirected to:Required environment variables
Configure the following variables before enabling OAuth2 social login. All six are required; missing values will cause the service to fail on startup in theprod profile.
| Variable | Description |
|---|---|
GOOGLE_CLIENT_ID | OAuth2 client ID from the Google Cloud Console. |
GOOGLE_CLIENT_SECRET | OAuth2 client secret from the Google Cloud Console. |
GITHUB_CLIENT_ID | OAuth2 client ID from the GitHub Developer Settings. |
GITHUB_CLIENT_SECRET | OAuth2 client secret from the GitHub Developer Settings. |
OAUTH2_SUCCESS_REDIRECT_URI | Frontend URL that receives the ?code= parameter after a successful login. Example: https://app.example.com/oauth2/success. |
OAUTH2_FAILURE_REDIRECT_URI | Frontend URL that receives ?error=federated_login_failed after a failed login. Example: https://app.example.com/oauth2/failure. |
{AUTH_SERVICE_BASE_URL}/login/oauth2/code/google and {AUTH_SERVICE_BASE_URL}/login/oauth2/code/github as authorized redirect URIs in each provider’s developer console.