Login

Use django-social-auth & Google Accounts for admin login

Author:
pmdarrow
Posted:
December 4, 2012
Language:
Python
Version:
1.4
Score:
0 (after 0 ratings)
  1. Create an app and place this in admin.py.
  2. Add url(r'^login/$', 'social_auth.views.auth', {'backend': 'google'}, name='login') to your urls.py.
  3. Add the app to your INSTALLED_APPS after django.contrib.admin.
  4. Set USE_SOCIAL_AUTH_AS_ADMIN_LOGIN = True in your settings.py.
  5. ...
  6. Profit.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
from django.conf import settings
from django.contrib import admin
from django.contrib.auth.views import redirect_to_login
from django.core.exceptions import PermissionDenied

# Support for allowing social_auth authentication for /admin (django.contrib.admin)
if getattr(settings, 'SOCIAL_AUTH_USE_AS_ADMIN_LOGIN', False):

    def _social_auth_login(self, request, **kwargs):
        if request.user.is_authenticated():
            if not request.user.is_active or not request.user.is_staff:
                raise PermissionDenied()
        else:
            return redirect_to_login(request.get_full_path())

    # Overide the standard admin login form.
    admin.sites.AdminSite.login = _social_auth_login

More like this

  1. Template tag - list punctuation for a list of items by shapiromatron 9 months ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 9 months, 1 week ago
  3. Serializer factory with Django Rest Framework by julio 1 year, 4 months ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 4 months ago
  5. Help text hyperlinks by sa2812 1 year, 5 months ago

Comments

Please login first before commenting.