Minimal Google Sign-In for Django. One Google Client ID, works on any Django project.
pip install git+https://github.com/akarca/django-google-auth.gitINSTALLED_APPS = [
...
"gsi",
]
TEMPLATES = [{
"OPTIONS": {
"context_processors": [
...
"gsi.context_processors.google_client_id",
],
},
}]
GOOGLE_CLIENT_ID = "your-client-id.apps.googleusercontent.com"from django.urls import include, path
urlpatterns = [
...
path("", include("gsi.urls")),
]{% load gsi_tags %}
<!-- In your login form -->
{% google_signin_button %}
<!-- In your register form -->
{% google_signin_button text="signup_with" %}That's it. Users who sign in with Google are automatically logged in (existing account) or registered (new account).
- User clicks the Google Sign-In button
- Google popup opens, user authorizes
- Google returns a JWT credential to the JavaScript callback
- JavaScript submits the credential to
/accounts/google/callback/with CSRF token - Backend verifies the JWT using
google-authlibrary - If email matches existing user → login
- If new email → create user with
unusable_password,email_confirmed=True - Redirect to
LOGIN_REDIRECT_URLor?next=parameter
| Setting | Default | Description |
|---|---|---|
GOOGLE_CLIENT_ID |
"" |
Google OAuth Client ID (required) |
LOGIN_REDIRECT_URL |
"/" |
Where to redirect after login |
LOGIN_URL |
"/accounts/login/" |
Where to redirect on error |
GSI_CALLBACK |
None |
Post-login hook (see below) |
For project-specific logic after Google login (cart migration, analytics, etc.):
# settings.py
GSI_CALLBACK = "myapp.auth.on_google_login"
# myapp/auth.py
def on_google_login(request, user, created):
"""Called after successful Google login/register."""
if created:
# New user — send welcome email, etc.
pass
# Migrate cart, set session data, etc.Works with any Django User model:
USERNAME_FIELD = "email"→ uses email as usernameUSERNAME_FIELD = "username"→ sets username to email- Has
full_namefield → sets from Google profile name - Has
first_name/last_name→ splits Google name - Has
email_confirmedfield → sets toTrue
- Go to Google Cloud Console
- Create a project (e.g. "Yuix Networks Inc")
- APIs & Services → Credentials → Create OAuth 2.0 Client ID
- Application type: Web application
- Authorized JavaScript origins: add all your domains
https://nameocean.nethttps://ipaddress.worldhttps://fenerbahce.fan
- Copy the Client ID to your Django settings
One Client ID works for all your sites.
MIT