Settings Reference ¶
All settings are defined in your Django project's settings.py.
Required Settings¶
These must be set or your app won't start
GOOGLE_CLIENT_ID¶
-
Your Google OAuth2 client identifier.
Type:
str· Default: None (required)
GOOGLE_CLIENT_SECRET¶
-
Your Google OAuth2 client secret.
Type:
str· Default: None (required)
Optional Settings¶
SCOPE¶
-
List of OAuth2 scopes defining what access your app requests.
SCOPE = [ "https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/userinfo.profile", "openid", ]Type:
list[str]· Default:[](with warning)Common Scopes
Scope What it grants openidBasic identity (required for ID token) .../userinfo.emailUser's email .../userinfo.profileName, picture, locale .../driveFull Google Drive access .../drive.readonlyRead-only Drive access .../calendarGoogle Calendar
GOOGLE_AUTH_FINAL_REDIRECT_URL¶
-
Where to redirect after successful authentication. Must be a fully-qualified URL when set to a non-empty value.
# Development GOOGLE_AUTH_FINAL_REDIRECT_URL = "http://127.0.0.1:8000/dashboard/" # Production GOOGLE_AUTH_FINAL_REDIRECT_URL = "https://myapp.example.com/dashboard/" # Or omit / set to None to fall back to the /gauth/ landing page GOOGLE_AUTH_FINAL_REDIRECT_URL = NoneType:
Optional[str]· Default:None(redirects to/gauth/)URL format validated at startup
Django Gauth validates this setting using URL parsing (both
schemeandhostmust be present). A non-empty value without a scheme or host — such as a bare relative path like"/dashboard/"— produces anInfo-level system check entry.Noneand empty string""are silently treated as "not configured".
CREDENTIALS_SESSION_KEY_NAME¶
-
The session key where OAuth2 credentials are stored.
Type:
str· Default:"credentials"
STATE_KEY_NAME¶
-
The session key where the OAuth2 state parameter is stored.
Type:
str· Default:"oauth_state"
GOOGLE_LOGIN_PROMPT¶
-
Controls the Google consent screen behaviour passed as the
promptparameter to Google's authorization endpoint.# Default — always show account picker AND re-confirm consent GOOGLE_LOGIN_PROMPT = "select_account consent" # Show account picker only (re-consent on scope change only) GOOGLE_LOGIN_PROMPT = "select_account" # Force consent page every time (useful when testing scopes) GOOGLE_LOGIN_PROMPT = "consent" # No prompt — silently use existing session (SSO-style) GOOGLE_LOGIN_PROMPT = "none"Type:
str· Default:"select_account consent"Accepted values
Value Behaviour select_accountForce account selection even if one session exists consentForce the consent screen every time select_account consentBoth — recommended default noneNo UI shown; fails if interaction is required When to change this
- Set to
"select_account"if users have only one account and re-confirming consent on every login is intrusive. - Set to
"none"for silent SSO flows where the user has previously consented.
- Set to
GOOGLE_TOKEN_REVOKE_ON_LOGOUT¶
-
Whether the
logout()view best-effort revokes the upstream Google token before flushing the local session. Revoking withdraws access on Google's side too, not just locally.# Default — revoke the Google token on logout GOOGLE_TOKEN_REVOKE_ON_LOGOUT = True # Only clear the local session; leave the Google grant intact GOOGLE_TOKEN_REVOKE_ON_LOGOUT = FalseType:
bool· Default:TrueBest-effort by design
The
refresh_tokenis preferred for revocation (revoking it also invalidates derived access tokens). A revocation failure never blocks logout — the local session is always cleared.
GOOGLE_AUTH_LOGOUT_REDIRECT_URL¶
-
Where the
logout()view redirects to when called with the default?response=redirect.Nonefalls back to the/gauth/index page.# Send users to your marketing site after logout GOOGLE_AUTH_LOGOUT_REDIRECT_URL = "https://myapp.example.com/goodbye/" # Or fall back to the /gauth/ landing page GOOGLE_AUTH_LOGOUT_REDIRECT_URL = NoneType:
Optional[str]· Default:None(redirects to/gauth/)SPA logout
Frontends usually call
/gauth/logout/?response=jsonand handle navigation themselves — in that case this setting is not consulted. See Session Lifecycle.
GOOGLE_SESSION_AUTO_REFRESH¶
-
Master switch for transparent token refresh. When
True(default),get_credentials()and the/gauth/sessionprobe silently refresh an expired access token (using the storedrefresh_token) so the session survives past Google's ~1 hour ID-token lifetime. WhenFalse, an expired session simply ends and the user must re-authenticate.# Default — keep users signed in via silent refresh GOOGLE_SESSION_AUTO_REFRESH = True # Force re-login once the ID token expires (no silent refresh) GOOGLE_SESSION_AUTO_REFRESH = FalseType:
bool· Default:True
GOOGLE_SESSION_MAX_AGE¶
-
Absolute session cap, in seconds. When set, a session is never extended past
login_time + GOOGLE_SESSION_MAX_AGE— even when a validrefresh_tokenis available.Nonedisables the cap (sessions roll forward indefinitely via refresh).# Force a fresh login at least every 8 hours, regardless of activity GOOGLE_SESSION_MAX_AGE = 8 * 60 * 60 # No absolute cap (default) GOOGLE_SESSION_MAX_AGE = NoneType:
Optional[int]· Default:NoneCompliance-friendly
Many security policies (PCI-DSS, HIPAA, internal SOC 2 controls) require an absolute re-authentication interval. This setting enforces exactly that, independent of whether Google would still honour the refresh token.
The cap is not lifted by
GOOGLE_SESSION_AUTO_REFRESHThis is a hard ceiling, measured from the original login and never moved by a refresh. With
AUTO_REFRESH=TrueandMAX_AGEset, hitting/gauth/sessionafter the cap elapses returnsauthenticated: false— it does not refresh. That is intended: an ever-refreshable cap would never fire. For "extend while active, up to a limit", pair it withGOOGLE_SESSION_IDLE_TIMEOUT. See Session Lifecycle → Precedence.
GOOGLE_SESSION_IDLE_TIMEOUT¶
-
Idle timeout, in seconds. When set, a session that has been inactive for longer than this window ends and the user must re-authenticate. Activity is measured by successful calls to
get_credentials()(e.g. each/gauth/sessionprobe or protected API call).Nonedisables the idle timeout.# Sign users out after 30 minutes of inactivity GOOGLE_SESSION_IDLE_TIMEOUT = 30 * 60 # No idle timeout (default) GOOGLE_SESSION_IDLE_TIMEOUT = NoneType:
Optional[int]· Default:NoneAbsolute cap + idle timeout compose
GOOGLE_SESSION_MAX_AGEandGOOGLE_SESSION_IDLE_TIMEOUTare independent — set either, both, or neither. A session must satisfy all configured caps to be extended. See Session Lifecycle → Choosing a session policy.
DJANGO_GAUTH_UI_CONFIG¶
-
Customize the appearance of the built-in landing page.
DJANGO_GAUTH_UI_CONFIG = { "index": { "navbar": { "logo": "https://example.com/my-logo.png", "profile_picture_absence": "https://example.com/placeholder.png", } } }Type:
dict· Default: Not set (uses built-in assets)See UI Customization for details.
Django User Integration Settings¶
Opt-in — off by default
These settings power the optional bridge to Django's own auth system
(request.user, @login_required, the admin). They do nothing unless
GOOGLE_USER_INTEGRATION = True. See
Django User Integration for the full
walkthrough, including the required AUTHENTICATION_BACKENDS entry.
GOOGLE_USER_INTEGRATION¶
-
Master switch. When
True, a successful callback also opens a Django auth session (viaGoogleAuthBackend), sorequest.useris the Google-authenticated user.Type:
bool· Default:FalseAlso register the backend
Enabling this flag is not enough on its own — add the backend to
AUTHENTICATION_BACKENDS(keepModelBackendtoo):AUTHENTICATION_BACKENDS = [ "django_gauth.backends.GoogleAuthBackend", "django.contrib.auth.backends.ModelBackend", ]manage.py checkwill warn (django_gauth.W001–W003) if the backend,django.contrib.auth, orAuthenticationMiddlewareis missing.
GOOGLE_USER_AUTO_CREATE¶
-
Whether to create a new
Userwhen no existing account matches the Google identity. WhenFalse, only pre-existing users can sign in (a missing match is refused).Type:
bool· Default:True
GOOGLE_USER_LOOKUP_FIELD¶
-
The
Userfield used to find an existing account. The match is case-insensitive ({field}__iexact).emailreads the Googleemailclaim; any other field name is read from the correspondingid_infoclaim.Type:
str· Default:"email"
GOOGLE_USER_REQUIRE_VERIFIED_EMAIL¶
-
When
True, sign-in is refused unless Google reports the email as verified (email_verifiedclaim). This is the primary guard against account hijacking via an unverified address — keep it on unless you fully trust every issuer.Type:
bool· Default:True
GOOGLE_USER_MAPPER¶
-
Optional dotted path to a callable
(id_info, user, created) -> Nonethat runs on every sign-in, letting you copy claims onto theUser(roles, avatar, groups, …) before it is saved. When unset, a built-in mapper fillsfirst_name/last_namefrom thegiven_name/family_nameclaims if they are empty.# myapp/auth.py def map_google_user(id_info, user, created): user.is_staff = id_info.get("hd") == "mycompany.com"Type:
str | None· Default:None
Environment Variable¶
OAUTHLIB_INSECURE_TRANSPORT¶
-
Allows OAuth2 over HTTP (non-HTTPS). Development only!
Never enable in production
This disables HTTPS requirement. In production, always use HTTPS.
Settings Summary Table¶
| Setting | Required | Type | Default |
|---|---|---|---|
GOOGLE_CLIENT_ID |
✅ | str |
— |
GOOGLE_CLIENT_SECRET |
✅ | str |
— |
SCOPE |
⚠️ | list |
[] |
GOOGLE_AUTH_FINAL_REDIRECT_URL |
❌ | str\|None |
None |
CREDENTIALS_SESSION_KEY_NAME |
❌ | str |
"credentials" |
STATE_KEY_NAME |
❌ | str |
"oauth_state" |
GOOGLE_LOGIN_PROMPT |
❌ | str |
"select_account consent" |
GOOGLE_TOKEN_REVOKE_ON_LOGOUT |
❌ | bool |
True |
GOOGLE_AUTH_LOGOUT_REDIRECT_URL |
❌ | str\|None |
None |
GOOGLE_SESSION_AUTO_REFRESH |
❌ | bool |
True |
GOOGLE_SESSION_MAX_AGE |
❌ | int\|None |
None |
GOOGLE_SESSION_IDLE_TIMEOUT |
❌ | int\|None |
None |
GOOGLE_USER_INTEGRATION |
❌ | bool |
False |
GOOGLE_USER_AUTO_CREATE |
❌ | bool |
True |
GOOGLE_USER_LOOKUP_FIELD |
❌ | str |
"email" |
GOOGLE_USER_REQUIRE_VERIFIED_EMAIL |
❌ | bool |
True |
GOOGLE_USER_MAPPER |
❌ | str\|None |
None |
DJANGO_GAUTH_UI_CONFIG |
❌ | dict |
Not set |
System Checks¶
Django Gauth validates your settings when the server starts:
| Code | Level | Message |
|---|---|---|
django_gauth.E001 |
Error | SECRET_KEY not defined |
django_gauth.E002 |
Error | SessionMiddleware not in MIDDLEWARE |
django_gauth.E003 |
Error | GOOGLE_CLIENT_ID or GOOGLE_CLIENT_SECRET missing |
django_gauth.E004 |
Warning | SCOPE not defined |
django_gauth.W001 |
Warning | GOOGLE_USER_INTEGRATION on, but django.contrib.auth missing |
django_gauth.W002 |
Warning | GOOGLE_USER_INTEGRATION on, but AuthenticationMiddleware missing |
django_gauth.W003 |
Warning | GOOGLE_USER_INTEGRATION on, but GoogleAuthBackend missing |
Run checks manually: