OAuth with Google
Enable Google Sign-In for InstaCRUD users. This guide walks through setting up OAuth 2.0 credentials in Google Cloud Console.
Overview
Google OAuth allows users to:
- Sign in with their Google account
- Skip manual registration
- Use their existing Google identity
Step 1: Create Google Cloud Project
- Go to Google Cloud Console
- Create a new project or select an existing one
- Note your Project ID
Step 2: Configure OAuth Consent Screen
- Navigate to APIs & Services > OAuth consent screen
- Select External user type (or Internal for Google Workspace)
- Fill in required fields:
- App name: Your application name
- User support email: Your email
- Developer contact email: Your email
- Click Save and Continue
Scopes
Add these scopes:
emailprofileopenid
Test Users (Development)
While in testing mode, add email addresses of users who can test the OAuth flow.
Step 3: Create OAuth Credentials
-
Go to APIs & Services > Credentials
-
Click Create Credentials > OAuth client ID
-
Select Web application
-
Configure:
- Name: InstaCRUD Backend
- Authorized JavaScript origins:
http://localhost:3000
https://your-domain.com - Authorized redirect URIs:
http://localhost:8000/oauth/google/callback
https://your-domain.com/oauth/google/callback
-
Click Create
-
Copy the Client ID and Client Secret
Step 4: Configure InstaCRUD
Add credentials to your backend .env file:
# Google OAuth
GOOGLE_CLIENT_ID=your-client-id.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=your-client-secret
Step 5: Verify Configuration
Restart the backend server. The OAuth endpoint should be available:
GET /oauth/google/login
This redirects users to Google's consent screen.
Environment-Specific URLs
Local Development
Authorized JavaScript origins:
http://localhost:3000
Authorized redirect URIs:
http://localhost:8000/oauth/google/callback
ngrok Development
Authorized JavaScript origins:
https://your-frontend.ngrok-free.app
Authorized redirect URIs:
https://your-backend.ngrok-free.app/oauth/google/callback
Production
Authorized JavaScript origins:
https://app.your-domain.com
Authorized redirect URIs:
https://api.your-domain.com/oauth/google/callback
Publishing to Production
To allow any Google user to sign in:
- Go to OAuth consent screen
- Click Publish App
- Complete verification if required (for sensitive scopes)
Without publishing, only test users can authenticate.
Troubleshooting
"Access Blocked" Error
- Verify redirect URI matches exactly (including trailing slashes)
- Check that the user is added as a test user (if in testing mode)
"Invalid Client" Error
- Verify Client ID and Secret are correct
- Ensure no extra whitespace in environment variables
Callback URL Mismatch
- The redirect URI in Google Console must match
BASE_URL/oauth/google/callbackexactly - Include both HTTP (development) and HTTPS (production) URLs
Summary
Google OAuth configuration requires:
- Google Cloud project with OAuth consent screen
- OAuth 2.0 credentials (Client ID + Secret)
- Correct redirect URIs for each environment
- Environment variables in InstaCRUD backend