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

 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. OracleAuthBackend by nosrednakram 3 years, 9 months ago
  2. HTTPS redirections middleware with updated URL template tag by xlq 7 months ago
  3. SSL / HTTPS Middleware for Redirection and href Rewriting by DrMeers 3 years ago
  4. Admin App/Model Custom Ordering by stephen_mcd 3 years, 2 months ago
  5. Require login by url by zbyte64 4 years, 9 months ago

Comments

cigpure (on May 20, 2013):

ok thank yout for the snippet i will try it. ecigarette

#

(Forgotten your password?)