Skip to content

Instantly share code, notes, and snippets.

@aw3s0me
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save aw3s0me/96b51f3a4329776fa65f to your computer and use it in GitHub Desktop.

Select an option

Save aw3s0me/96b51f3a4329776fa65f to your computer and use it in GitHub Desktop.
Django Rest Session Authentication
from rest_framework.authentication import SessionAuthentication
class SuperUserAuth(SessionAuthentication):
def authenticate(self, request):
request = request._request
user = getattr(request, 'username', None)
#if not user or not user.is_active or not user.is_superuser:
#return None
if not username:
return None
try:
user = User.objects.get(username=username)
except User.DoesNotExist:
raise exceptions.AuthenticationFailed('No such user')
return (user, None)
#self.enforce_csrf(request)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment