Skip to content

Enable Google Social Login Using Django Allauth #6

Description

@antoinebou12

Overview

This ticket is to create a feature for enabling social login using Google with Django Allauth on the Simulateur stock market simulation platform. The platform is built using Django and includes features for managing stock market scenarios, teams, user profiles, and an admin dashboard for controlling simulation parameters. The objective is to integrate Google social login to enhance user authentication and streamline the login process.

Steps to Implement Google Social Login

  1. Install Django Allauth:

    • Install Django Allauth by adding it to your project's requirements.txt file or running the command:
      pip install django-allauth
  2. Update Settings:

    • Update the settings.py file to include Allauth configurations:
      INSTALLED_APPS = [
          ...
          'django.contrib.sites',
          'allauth',
          'allauth.account',
          'allauth.socialaccount',
          'allauth.socialaccount.providers.google',
          ...
      ]
      
      SITE_ID = 1
      
      AUTHENTICATION_BACKENDS = [
          ...
          'allauth.account.auth_backends.AuthenticationBackend',
          ...
      ]
      
      LOGIN_REDIRECT_URL = '/'
      LOGOUT_REDIRECT_URL = '/'
  3. Configure URLs:

    • Update the urls.py file to include Allauth URLs:
      from django.urls import path, include
      
      urlpatterns = [
          ...
          path('accounts/', include('allauth.urls')),
          ...
      ]
  4. Set Up Google Social Account:

    • Go to the Google Developer Console and create a new project.
    • Set up OAuth consent screen.
    • Create OAuth 2.0 Client IDs and get the Client ID and Client Secret.
    • Add these credentials to the settings.py:
      SOCIALACCOUNT_PROVIDERS = {
          'google': {
              'SCOPE': [
                  'profile',
                  'email',
              ],
              'AUTH_PARAMS': {
                  'access_type': 'online',
              },
              'OAUTH_PKCE_ENABLED': True,
          }
      }
      
      SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = '<your-client-id>'
      SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = '<your-client-secret>'
  5. Update Database:

    • Run migrations to apply changes:
      python manage.py migrate
  6. Test the Integration:

    • Start the server and test the Google login by navigating to /accounts/login/.

Expected Behavior

Users should be able to log in using their Google accounts. Upon successful authentication, users will be redirected to the homepage or a specified URL.

Additional Information

Ensure that the OAuth consent screen is properly configured in the Google Developer Console, and the Client ID and Secret are kept secure.


  • Simulateur: Stock market simulation platform using Django.
  • Feature: Enable Google social login using Django Allauth.
  • Steps: Install Django Allauth, update settings and URLs, configure Google OAuth, update database, and test the integration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions