Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added automatic login for token owner for Bearer auth.
  • Loading branch information
idlesign committed Jan 31, 2012
1 parent dd0ea3e commit 3d2035f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions oauthost/auth_handlers.py
@@ -1,5 +1,6 @@
from datetime import datetime

from django.contrib.auth import login
from django.core.exceptions import ObjectDoesNotExist
from django.template import loader, RequestContext
from django.http import HttpResponse
Expand Down Expand Up @@ -73,6 +74,13 @@ def validate_token(self):
self._error = 'insufficient_scope'
return False

# Token is valid and now we'll log it's owner in.

# Manual .backend attribute is set as an alternative to `authenticate()`.
# For now this hardcoded backend will do.
token.user.backend = 'django.contrib.auth.backends.ModelBackend'
login(self._request, token.user)

return True

def prepare_response(self):
Expand Down

0 comments on commit 3d2035f

Please sign in to comment.