DEV Community

abhiphull
abhiphull

Posted on

How To Set Up Django Social User Management Using Allauth

In this post, I will go in brief about setting up Django Social login system. There are lot of articles on this topic online already. I will not repeat the stuff which is already available online. I want to go through couple of pain points which I faced while setting allauth user management.

First follow the following tutorial to setup the Django Allauth
https://django-allauth.readthedocs.io/en/latest/installation.html

Important Points:

  1. For Google login. make sure your Redirect URI in the google console follows following pattern... http://domain_or_localhost/accounts/google/login/callback/
    • For localhost do... http://127.0.0.1/accounts/google/login/callback/
    • For your IP http://IP/accounts/google/login/callback/
    • For your domain http://domain/accounts/google/login/callback/
      • If you are using actual domain, make sure you add following in your settings.py file...
         USE_X_FORWARDED_HOST = True
  2. If you want to restrict the social login to pre-approved users only look at following snippet of code... https://www.code-fetcher.com/code-examples/django-allauth-social-login-for-pre-approved-users-only/
  3. SITE_ID is another important parameter in the settings.py file. For me SITE_ID = 2 worked for Google login but it could be SITE_ID = 1 depending upon which version of the allauth you are using. So make sure you check that If you run in to any issues.

I hope these suggestions would help.

Top comments (0)