Google Cloud Console: OAuth2 App Setup
Before configuring Keycloak's Google Identity Provider, you need a Google OAuth2 application. This page walks through the Google Cloud Console setup.
Step 1: Create or Select a Google Cloud Project
- Go to console.cloud.google.com
- Click the project selector → New Project
- Name it (e.g., "MyApp Authentication")
- Click Create
Step 2: Enable the Google+ API / People API
In your project, navigate to APIs & Services → Library:
- Search for "Google People API"
- Click Enable
This API provides the user profile information (name, email, avatar) that Keycloak will use to populate user attributes.
Step 3: Configure the OAuth Consent Screen
Navigate to APIs & Services → OAuth consent screen:
- User Type: External (for production) or Internal (for G Suite org)
- Fill in required fields: - App name: Your application name - User support email: Your email - Developer contact: Your email
- Scopes: Add
openid,email,profile - Test users: Add your email (required while app is in "Testing" mode)
- Click Save and Continue
Step 4: Create OAuth2 Credentials
Navigate to APIs & Services → Credentials → Create Credentials → OAuth client ID:
- Application type: Web application
- Name: "Keycloak Integration"
- Authorized redirect URIs: Add your Keycloak callback URL:
http://localhost:8080/realms/YOUR_REALM/broker/google/endpointFor production:https://auth.yourdomain.com/realms/YOUR_REALM/broker/google/endpoint - Click Create
Save the Client ID and Client Secret — you'll need these in Keycloak.
Redirect URI Pattern
The Keycloak callback URL for Google follows this pattern:
{keycloak-base-url}/realms/{realm-name}/broker/google/endpoint
Examples:
- Dev: http://localhost:8080/realms/myrealm/broker/google/endpoint
- Prod: https://auth.example.com/realms/myrealm/broker/google/endpoint
OAuth Consent Screen: Testing vs Production
| State | Access | User limit |
|---|---|---|
| Testing | Only test users you've added | 100 users |
| Production | Any Google account | Unlimited |
To publish: Go to OAuth consent screen → Publish App → Submit for verification (required for external apps requesting sensitive scopes).
For openid, email, profile — these are non-sensitive scopes and don't require Google review.
Environment Variables
Store credentials securely, never in source code:
# .env (never commit this)
GOOGLE_CLIENT_ID=123456789-abc.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=GOCSPX-your-secret-here
# Verify it works
curl "https://accounts.google.com/o/oauth2/v2/auth?client_id=${GOOGLE_CLIENT_ID}&redirect_uri=http://localhost:8080/realms/myrealm/broker/google/endpoint&response_type=code&scope=openid+email+profile"