Google OAuth Setup
This guide walks you through setting up Google OAuth for your application. After completing this guide, your users will be able to sign in using their Google accounts.
Prerequisites
- A Google account
- Access to Google Cloud Console
- Your application's redirect URI ready
Step 1: Create a Google Cloud Project
- Go to the Google Cloud Console
- Click on the project dropdown at the top of the page
- Click New Project
- Enter a project name (e.g., "MyApp OAuth")
- Click Create
Tip: Use a descriptive project name that identifies your application for easier management.
Step 2: Enable Required APIs
- In the Google Cloud Console, go to APIs & Services > Library
- Search for "Google Identity" or "People API"
- Click on Google Identity Services (or Google+ API for legacy) and Enable
- For basic OAuth 2.0 flows, the OAuth consent screen and credentials are sufficient; no additional APIs are required for email/profile scopes
Step 3: Configure OAuth Consent Screen
- Go to APIs & Services > OAuth consent screen
- Select External user type (or Internal if using Google Workspace)
- Click Create
- Fill in the required information:
| Field | Description | Example |
|---|---|---|
| App name | Your application name | MyApp |
| User support email | Contact email for users | support@myapp.com |
| App logo | Your app icon (optional) | - |
| App domain | Your website domain | myapp.com |
| Developer contact email | Your email | dev@myapp.com |
- Click Save and Continue
Add Scopes
- Click Add or Remove Scopes
- Select the following scopes:
email- View user's email addressprofile- View user's basic profile infoopenid- Authenticate using OpenID Connect
- Click Update
- Click Save and Continue
Step 4: Create OAuth Credentials
- Go to APIs & Services > Credentials
- Click Create Credentials > OAuth client ID
- Select the application type:
For Web Applications
- Application type: Web application
- Name: "MyApp Web Client"
- Authorized JavaScript origins:
https://yourdomain.com
http://localhost:3000 (for development)
- Authorized redirect URIs:
https://yourdomain.com/auth/google/callback
http://localhost:3000/auth/google/callback
For iOS Applications
- Application type: iOS
- Name: "MyApp iOS Client"
- Bundle ID:
com.yourcompany.myapp
For Android Applications
- Application type: Android
- Name: "MyApp Android Client"
- Package name:
com.yourcompany.myapp - SHA-1 certificate fingerprint: (your signing certificate)
- Click Create
- Save the Client ID and Client Secret
Important: Keep your Client Secret secure. Never expose it in client-side code.
Step 5: Configure in OpenDev
Now configure your Google OAuth credentials in OpenDev:
- Log in to OpenDev Platform
- Navigate to OAuth Channels
- Click Add OAuth Channel or edit existing Google channel
- Fill in the configuration:
{
"provider": "google",
"clientId": "YOUR_CLIENT_ID.apps.googleusercontent.com",
"clientSecret": "YOUR_CLIENT_SECRET",
"scopes": ["email", "profile", "openid"],
"callbackUrl": "https://yourdomain.com/auth/google/callback"
}
Configuration Fields
| Field | Required | Description |
|---|---|---|
| Client ID | Yes | OAuth 2.0 Client ID from Google Console |
| Client Secret | Yes | OAuth 2.0 Client Secret |
| Scopes | Yes | Permission scopes to request |
| Callback URL | Yes | Your authorized redirect URI |
Step 6: Test the Integration
- In your application, trigger the Google OAuth flow
- You should see the Google sign-in page
- After authorization, you'll be redirected back with user data
Sample OAuth Response
{
"provider": "google",
"providerId": "123456789",
"email": "user@gmail.com",
"name": "John Doe",
"avatar": "https://lh3.googleusercontent.com/..."
}
Troubleshooting
Error: redirecturimismatch
The redirect URI in your request doesn't match any authorized URIs.
Solution: Add the exact redirect URI to your Google Cloud Console credentials.
Error: invalid_client
The OAuth client was not found or credentials are wrong.
Solution: Verify your Client ID and Client Secret are correct.
Error: access_denied
The user denied the authorization request.
Solution: This is expected behavior when users click "Cancel".
Best Practices
- Use HTTPS in production for all redirect URIs
- Validate state parameter to prevent CSRF attacks
- Store tokens securely using encryption
- Implement token refresh for long-lived sessions
- Handle errors gracefully with user-friendly messages