-
Notifications
You must be signed in to change notification settings - Fork 0
Setting Up Google OAuth
Manu Murugesan edited this page Mar 13, 2026
·
2 revisions
The web interface uses Google OAuth 2.0 for authentication. This guide walks through creating the credentials.
- Go to Google Cloud Console.
- Click Select a project → New Project.
- Name it (e.g., "Urn Randomizer") and click Create.
- Navigate to APIs & Services → OAuth consent screen.
- Select Internal (if using Google Workspace) or External.
- Fill in:
- App name: Urn Randomizer
- User support email: your email
-
Authorized domains: your deployment domain (e.g.,
onrender.com) - Developer contact: your email
- Click Save and Continue.
- Under Scopes, add:
emailprofile
- Click Save and Continue through the remaining steps.
- Navigate to APIs & Services → Credentials.
- Click Create Credentials → OAuth client ID.
- Select Web application.
- Set:
- Name: Urn Randomizer
-
Authorized redirect URIs:
- For local development:
http://localhost:5000/login/google/authorized - For production:
https://your-domain.com/login/google/authorized
- For local development:
- Click Create.
- Copy the Client ID and Client Secret.
Add the credentials to your .env file:
GOOGLE_OAUTH_CLIENT_ID=your-client-id.apps.googleusercontent.com
GOOGLE_OAUTH_CLIENT_SECRET=your-client-secret
FLASK_SECRET_KEY=a-random-secret-key-for-sessionsOr set them as environment variables in your deployment platform (Render, Heroku, etc.).
OAuth alone doesn't grant access — users must be pre-registered:
flask add_user alice alice@gmail.comThe email must match the Google account the user will log in with. When a user signs in with Google for the first time, the system matches their Google email to the registered user record.
- Check that the redirect URI exactly matches what's configured in Google Cloud Console.
- The path must be
/login/google/authorized(not/login/google/callback).
- For External apps, you may need to add test users in the OAuth consent screen while in testing mode.
- Or publish the app (requires Google verification for sensitive scopes).
- Make sure you added the production redirect URI to the Google Cloud Console.
- Ensure HTTPS is enabled — Google requires HTTPS for redirect URIs in production.
- Check that
FLASK_SECRET_KEYis set — without it, sessions won't persist.
- The user's Google email must match a registered user. Run:
to verify, then add missing users with
flask list_users
flask add_user.
Set DEMO_MODE=true to skip OAuth entirely:
export DEMO_MODE=true
flask runThis auto-logs in all visitors as a demo user. Never use this in production with real data.