Skip to content

Authentication and Google OAuth

Authentication runs on django-allauth: email-based login (no username), email verification, multi-factor authentication, and social login through Google.

The Google provider is configured in config/settings/base.py, with EMAIL_AUTHENTICATION enabled — a user whose verified email matches an existing account can sign in with Google — and OAUTH_PKCE enabled.

Creating the credentials

  1. Open the Google Cloud Console and select or create a project.
  2. Go to APIs & Services → Credentials → Create Credentials → OAuth client ID, and choose Web application.
  3. Add the authorized redirect URIs:
    • Development: http://localhost:8000/accounts/google/login/callback/
    • Production: https://yourdomain.com/accounts/google/login/callback/
  4. Copy the client ID and client secret.

Configuring the project

Add the credentials to your .env:

GOOGLE_OAUTH_CLIENT_ID=your-client-id.apps.googleusercontent.com
GOOGLE_OAUTH_CLIENT_SECRET=your-client-secret

Alternatively, register them from the Django admin at /admin/ under Social applications: provider Google, the client ID and secret from the console, and your site selected in Sites.

What the integration does

  • Google One Tap sign-in — returning users get a one-click popup.
  • Name and email are populated automatically from the Google profile.
  • Anonymous session claiming — a recommendation session started before login is preserved and attached to the account.
  • Custom adapters in sad_pulm/users/adapters.py hold this business logic.

URLs

Path Purpose
/accounts/login/ Login page
/accounts/signup/ Signup page
/accounts/google/login/callback/ Google OAuth callback
/accounts/ Account management (allauth)

Templates

  • sad_pulm/templates/account/login.html
  • sad_pulm/templates/account/signup.html
  • sad_pulm/templates/socialaccount/snippets/login.html — the Google button