Skip to content
Advertisement

dj-rest-auth limit social sign up to a specific email address domain

I’m getting started with dj-rest-auth and I have an app which allows user to only sign in via google. However, I want users to only be able to access my service with a specific google apps email domain.

I’m using dj-rest-auth in conjunction with django-allauth.

This is what I tried: I created allauth adapters like this:

JavaScript

and in my settings I have

JavaScript

With this solution, if the user tries to sign in with a valid email, everything works, whereas if they use a non-allowed email domain, I get this error in my console:

JavaScript

What I would like to do is for my django app to send a 403 response to the user (or similar) with a message like “You can only access this service with an [at] whatever email address”. I’m trying to figure out at which point the dj-rest-auth views call the user adapters and what to do to handle the failure and achieve what I’m after.

Advertisement

Answer

When you return is_open_for_signup==False, internally django-allauth returns a template:

JavaScript

That template extends a template account/base.html (inside django-allauth project) and in this template you have the problematic URL defined <li><a href="{% url 'account_login' %}">Sign In</a></li>

You can override your signup_closed.html template and solve this error, but if you need to return a Json (because of the API), you should use your own implementation of django-allauth.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement