0
votes

In python social auth library:

I am making a social auth for my django project. I want to disable social auth for admin. how it works by default:

  1. social auth url is visited and permissions granted
  2. new Python Social Auth › User social auths object is created for Admin
  3. this social account logs in admin

How I want it to work:

  1. social auth url is visited and permissions granted
  2. new Python Social Auth › User social auths object is created along with new regular user, as if admin was not logged in
  3. this social account logs in a regular user

Is there an elegant way of doing this? Overriding the least amount of pipeline functions as possible.

1

1 Answers

0
votes

The way to solve this is to directly forbid admin users from using the social authentication process, for that you need a custom function in the pipeline that would raise AuthForbidden if the user is an admin.

This function should be after the social_user step to ensure that already associated accounts are identified. The code for that function should be something simple like:

def disable_admin(backend, user=None, *args, **kwargs):
    if user and user.is_admin:
        raise AuthForbidden(backend)

More docs about extending the pipeline here.