Integrate python-social-auth (social-app-django) to be used with the Django admin -


i want create app uses django admin, allows logins via google (my company google account) in place of django default modeladmin.

currently, looks social-app-django (google) way go, after having installed , setup project, it's not clear me how can allow django admin logins use social-app-django authentication. i've attempted configure project described here http://python-social-auth.readthedocs.io/en/latest/configuration/django.html isn't clear how can integrated django admin.

i found snippit (which seems out-of-date), , added it, 404 when try goto /admin/:

page not found (404) request method: request url: http://127.0.0.1:8000/accounts/login/?next=/admin/login/%3fnext%3d/admin/ using urlconf defined in telos.urls, django tried these url patterns, in order: ^login/(?p[^/]+)/$ [name='begin'] ^complete/(?p[^/]+)/$ [name='complete'] ^disconnect/(?p[^/]+)/$ [name='disconnect'] ^disconnect/(?p[^/]+)/(?p[^/]+)/$ [name='disconnect_individual'] ^admin/ current path, accounts/login/, didn't match of these.

if remove snippit, /admin/ redirect /admin/login/ , on login attempt return error text:

please enter correct username , password staff account. note both fields may case-sensitive.

in addition configuration, i've added following settings.py:

projects/models.py (myuser)

from django.contrib.auth.models import abstractuser  class myuser(abstractuser):     pass 

settings.py

# identification of social_auth_user # http://python-social-auth.readthedocs.io/en/latest/configuration/settings.html#user-model social_auth_user_model = 'projects.myuser' auth_user_model = 'projects.myuser'  # not sure if needed 

can direct me on how can setup project allow me login django admin through social-app-django (google)?

django admin uses auth contrib application, authentication process triggers same mechanism user logging in non-admin section , processed python-social-auth backends if defined in authentication_backends setting.

in order make work need to:

  1. add login google link (linking /login/google-oauth2) login form. can override default login form adding admin/login.html template or defining custom adminsite
  2. ensure user flagged is_staff, otherwise access admin forbidden.

Comments