Get LaunchBase

Authentcation page!

Integrating social authentication into your Django application can greatly enhance user experience by allowing users to sign in using their existing social media accounts such as Google, GitHub, and Twitter. This guide will walk you through setting up Django social auth and updating your secrets.json file to securely store your credentials.


Add the authentication backends for the social platforms you intend to use:

# Oauth provider settings
AUTHENTICATION_BACKENDS = (
    #django default user model - for admin page
    'django.contrib.auth.backends.ModelBackend',
    #social auth backends
    'social_core.backends.google.GoogleOAuth2',
    'social_core.backends.twitter.TwitterOAuth',
    'social_core.backends.github.GithubOAuth2',
    # other providers
    #'social_core.backends.facebook.FacebookOAuth2',
    #'microsoft_auth.backends.MicrosoftAuthenticationBackend',
)

Secrets Management

It is critical to manage your API keys and secrets securely. Store these sensitive keys in a secrets.json file and load them into your django settings.

    "SOCIAL_AUTH_GOOGLE_OAUTH2_KEY": "",
    "SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET": "",
    "SOCIAL_AUTH_GITHUB_KEY": "",
    "SOCIAL_AUTH_GITHUB_SECRET": "",
    "SOCIAL_AUTH_TWITTER_KEY": "",
    "SOCIAL_AUTH_TWITTER_SECRET": "",

Register Your Application

For each platform you intend to use, you must register your application to obtain API keys and secrets:

  • Google: Register your app in the Google Developer Console, enable the Google+ API, and set the callback URL.
https://domain.com/social-auth/complete/google-oauth2/
  • GitHub: Register your app in the GitHub Developer Settings, and set the callback URL.
https://domain.com/social-auth/complete/github/
  • Twitter: Create an app in the Twitter Developer Portal, enable it with the necessary permissions, and set the callback URL.
https://domain.com/social-auth/complete/twitter/