Created
January 29, 2013 12:54
-
-
Save tomchristie/4664015 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NoCSRFSessionAuthentication(BaseAuthentication): | |
""" | |
Use Django's session framework for authentication. | |
""" | |
def authenticate(self, request): | |
""" | |
Returns a `User` if the request session currently has a logged in user. | |
Otherwise returns `None`. | |
""" | |
# Get the underlying HttpRequest object | |
http_request = request._request | |
user = getattr(http_request, 'user', None) | |
# Unauthenticated, CSRF validation not required | |
if not user or not user.is_active: | |
return None | |
# CSRF passed with authenticated user | |
return (user, None) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment