Google Cloud Setup ¶
This guide walks you through creating OAuth2 credentials in the Google Cloud Console.
Time needed
This takes about 10 minutes if you already have a Google account.
Step-by-Step Process¶
graph TD
A[Create Google Cloud Project] --> B[Enable APIs]
B --> C[Configure Consent Screen]
C --> D[Create OAuth2 Credentials]
D --> E[Set Redirect URIs]
E --> F[Copy Client ID & Secret]
F --> G[Add to Django Settings]
style G fill:#4CAF50,color:white,stroke:none
1. Create a Google Cloud Project¶
- Go to Google Cloud Console
- Click Select a Project → New Project
- Give it a name (e.g., "My Django App")
- Click Create
2. Configure OAuth Consent Screen¶
- Navigate to APIs & Services → OAuth consent screen
- Choose External (unless you're in a Google Workspace organization)
-
Fill in:
- App name: Your app's display name
- User support email: Your email
- Developer contact: Your email
-
Click Save and Continue
Add Scopes¶
Add at minimum:
| Scope | Purpose |
|---|---|
.../auth/userinfo.email |
Read user's email |
.../auth/userinfo.profile |
Read user's name & picture |
openid |
Required for OpenID Connect |
3. Create OAuth2 Credentials¶
- Navigate to APIs & Services → Credentials
- Click + Create Credentials → OAuth client ID
- Choose Web application
- Set a name (e.g., "Django Gauth Client")
Configure Redirect URIs¶
Critical Step
The redirect URI must exactly match what your Django app generates.
Add these Authorized redirect URIs:
Common Mistake
127.0.0.1 and localhost are different for OAuth2!
If your redirect URI uses 127.0.0.1, you must access your app at http://127.0.0.1:8000, not http://localhost:8000.
graph LR
subgraph "✅ Correct"
A1["Redirect URI: http://127.0.0.1:8000/gauth/login-callback"]
A2["Browser: http://127.0.0.1:8000/gauth/"]
end
subgraph "❌ Wrong"
B1["Redirect URI: http://127.0.0.1:8000/gauth/login-callback"]
B2["Browser: http://localhost:8000/gauth/"]
end
4. Copy Your Credentials¶
After creating, you'll see:
- Client ID:
123456789-abc.apps.googleusercontent.com - Client Secret:
GOCSPX-xxxxxxxxxxxxxxxx
Store securely
Never hardcode these in your source code. Use:
Summary Checklist¶
- Google Cloud project created
- OAuth consent screen configured
- OAuth2 Web Client credentials created
- Redirect URI set correctly
- Client ID and Secret added to Django settings