OAuth (Google & Apple)
Let users sign in with their Google or Apple accounts. ezAuth handles the full OAuth 2.0 code flow, ID token verification, and user creation.
Supported Providers
| Provider | Flow | ID Token Verification |
|---|---|---|
| OAuth 2.0 authorization code | JWKS (cached 1 hour) | |
| Apple | OAuth 2.0 with form_post response mode | JWKS (cached 1 hour) |
Setup
- Go to the Google Cloud Console
- Create an OAuth 2.0 Client ID (Web application)
- Add your ezAuth callback URL as an authorized redirect URI:
https://your-ezauth.com/v1/oauth/google/callback - Configure the provider in ezAuth via the dashboard or API
Apple
- Go to the Apple Developer Portal
- Create a Services ID with "Sign in with Apple" enabled
- Create a key for Sign in with Apple
- Add your callback URL:
https://your-ezauth.com/v1/oauth/apple/callback - Configure the provider in ezAuth with your team ID, client ID, key ID, and private key
Configure via API
Use the secret key to configure OAuth providers:
// Configure Google OAuth
await fetch('https://your-ezauth.com/v1/oauth/providers', {
method: 'POST',
headers: {
'Authorization': 'Bearer sk_live_...',
'Content-Type': 'application/json',
},
body: JSON.stringify({
provider: 'google',
client_id: 'your-google-client-id.apps.googleusercontent.com',
client_secret: 'GOCSPX-...',
}),
})
// Configure Apple OAuth
await fetch('https://your-ezauth.com/v1/oauth/providers', {
method: 'POST',
headers: {
'Authorization': 'Bearer sk_live_...',
'Content-Type': 'application/json',
},
body: JSON.stringify({
provider: 'apple',
client_id: 'com.yourapp.service',
team_id: 'ABCD1234EF',
key_id: 'XYZ789',
private_key: '-----BEGIN EC PRIVATE KEY-----\\n...',
}),
})
Client-Side Flow
From your frontend, redirect the user to the OAuth authorization URL:
JavaScript
const { authorization_url } = await ez.auth.signInWithOAuth({
provider: 'google',
redirectUrl: 'https://myapp.com/dashboard',
})
// Redirect the user to the authorization URL
window.location.href = authorization_url
Swift
let result = try await ez.auth.signInWithOAuth(
provider: "google",
redirectUrl: "https://myapp.com/dashboard"
)
// Open result.authorization_url in a browser/webview
How It Works
- Your app calls
GET /v1/oauth/{provider}/authorize?redirect_url=... - ezAuth generates a CSRF nonce, stores it in Redis (10-minute TTL), and returns the provider's authorization URL
- The user authenticates with Google/Apple and is redirected back to ezAuth's callback
- ezAuth exchanges the authorization code for an ID token
- The ID token signature is verified against the provider's JWKS (cached 1 hour)
- ezAuth upserts the user via the OAuth identity (creates a new user or links to an existing one)
- A session is created, the
__sessioncookie is set, and the user is redirected to yourredirect_url
OAuth Identity Linking
Users are matched by (app_id, provider, provider_user_id). If a user already exists with the same email, the OAuth identity is linked to that user. If not, a new user is created with the provider's email.
Callback URLs
| Provider | Callback URL | Method |
|---|---|---|
/v1/oauth/google/callback | GET (query params) | |
| Apple | /v1/oauth/apple/callback | POST (form_post) |
Managing Providers
Use the secret key to list, configure, or remove OAuth providers:
| Method | Endpoint | Description |
|---|---|---|
| GET | /v1/oauth/providers | List configured providers (secrets redacted) |
| POST | /v1/oauth/providers | Configure a provider |
| DELETE | /v1/oauth/providers/{provider} | Remove a provider |