Auth Backend supports OAuth 2.0 via Supabase for both Google and Apple. The implementation uses the PKCE (Proof Key for Code Exchange) flow, which is the recommended approach for public clients such as single-page applications.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/eggarcia98/auth-backend/llms.txt
Use this file to discover all available pages before exploring further.
Why PKCE?
PKCE eliminates the need for a client secret in the browser by replacing it with a dynamically generated, cryptographically random code verifier. Each authorization request produces a unique verifier, which is stored server-side by Supabase. The provider receives only a hashed version (the code challenge). When the backend exchanges the authorization code for tokens, Supabase validates the code against the stored verifier — so intercepting the code alone is useless.Code interception protection
An intercepted authorization code cannot be exchanged without the matching verifier.
No client secret
SPAs never need to embed a client secret — the code verifier serves the same purpose.
Replay prevention
Authorization codes are single-use and bound to a specific verifier.
Dynamic per-request
Every login attempt uses a new, unique verifier generated by Supabase.
Full PKCE flow
Get the authorization URL
Call
GET /api/v1/auth/oauth/:provider to fetch an authorization URL. Supabase generates the code verifier and challenge internally and returns a ready-to-use URL.curl
response
Redirect the user
Redirect the browser to the URL returned in step 1. The user authenticates with the provider and grants the requested scopes.Scopes requested per provider:
- Google —
email profile - Apple —
email name
Provider redirects back
After the user authenticates, the provider redirects to:Extract the
code query parameter from the URL.Exchange the code for a session
Post the authorization code to On success,
POST /api/v1/auth/oauth/:provider/callback. The backend calls supabase.auth.exchangeCodeForSession(code), which validates the code against the stored PKCE verifier and returns a session.curl
accessToken and refreshToken are written to HTTP-only cookies and the response body includes the user and token details.response
Frontend integration (TypeScript)
step-1-initiate.ts
step-2-callback.ts
Provider setup
- Google
- Apple
Google OAuth credentials
- Open the Google Cloud Console and create or select a project.
- Navigate to APIs & Services → Credentials and create an OAuth 2.0 Client ID (application type: Web application).
- Under Authorized redirect URIs, add your Supabase callback URL:
- Copy the Client ID and Client Secret.
Configure in Supabase
- In your Supabase project dashboard go to Authentication → Providers → Google.
- Enable the provider and paste the Client ID and Client Secret.
- Set the Authorized Client IDs if you are also targeting native mobile clients.
Environment
No additional environment variables are needed on the Auth Backend side — provider credentials are stored in Supabase.Callback request body
| Field | Type | Required | Description |
|---|---|---|---|
code | string | Yes | Authorization code from the provider redirect URL |
Error cases
| Scenario | HTTP status | Error message |
|---|---|---|
Missing code in body | 400 | Authorization code is required |
| Invalid or expired code | 401 | Failed to authenticate with OAuth provider |
| Unsupported provider | 404 | Route not found |