Skip to content

Enable Notion Social Login Using Django Allauth #7

Description

@antoinebou12

Overview

This ticket is to create a feature for enabling social login using Notion 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 Notion social login to enhance user authentication and streamline the login process.

Steps to Implement Notion Social Login

  1. Install Django Allauth:

    • Ensure Django Allauth is installed 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.oauth2',
          ...
      ]
      
      SITE_ID = 1
      
      AUTHENTICATION_BACKENDS = [
          ...
          'allauth.account.auth_backends.AuthenticationBackend',
          ...
      ]
      
      LOGIN_REDIRECT_URL = '/'
      LOGOUT_REDIRECT_URL = '/'
  3. Create a Custom Notion Provider:

    • Since Django Allauth does not come with a built-in Notion provider, create a custom provider by following the Django Allauth documentation on custom providers.
  4. Configure URLs:

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

    • Go to the Notion Developer Console and create a new integration.
    • Get the Integration Token and add it to the settings.py:
      SOCIALACCOUNT_PROVIDERS = {
          'notion': {
              'SCOPE': [
                  'user.read',
                  'database.read',
              ],
              'AUTH_PARAMS': {
                  'access_type': 'offline',
              },
          }
      }
      
      SOCIAL_AUTH_NOTION_KEY = '<your-client-id>'
      SOCIAL_AUTH_NOTION_SECRET = '<your-client-secret>'
  6. Update Database:

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

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

Expected Behavior

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

Additional Information

Ensure that the Notion integration is properly configured in the Notion Developer Console, and the Client ID and Secret are kept secure.


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