Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix get_access_token, multiple tokens created at once #111

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions provider/oauth2/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def authenticate(self, request=None):
if request is None:
return None

form = ClientAuthForm(request.REQUEST)
form = ClientAuthForm(request.POST)

if form.is_valid():
return form.cleaned_data.get('client')
Expand All @@ -74,7 +74,7 @@ def authenticate(self, request=None):
if request is None:
return None

form = PublicPasswordGrantForm(request.REQUEST)
form = PublicPasswordGrantForm(request.POST)

if form.is_valid():
return form.cleaned_data.get('client')
Expand Down
6 changes: 6 additions & 0 deletions provider/oauth2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ def get_access_token(self, request, user, scope, client):
# None found... make a new one!
at = self.create_access_token(request, user, scope, client)
self.create_refresh_token(request, user, scope, at, client)
except AccessToken.MultipleObjectsReturned:
# Simultaneously created tokens must be destroyeds
at = AccessToken.objects.filter(user=user, client=client,
scope=scope, expires__gt=now()).latest("pk")
AccessToken.objects.filter(user=user, client=client,
scope=scope, expires__gt=now()).exclude(pk=at.pk).delete()
return at

def create_access_token(self, request, user, scope, client):
Expand Down
6 changes: 3 additions & 3 deletions provider/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def error_response(self, error, mimetype='application/json', status=400,
Return an error response to the client with default status code of
*400* stating the error as outlined in :rfc:`5.2`.
"""
return HttpResponse(json.dumps(error), mimetype=mimetype,
return HttpResponse(json.dumps(error), content_type=mimetype,
status=status, **kwargs)

def get(self, request):
Expand Down Expand Up @@ -463,7 +463,7 @@ def error_response(self, error, mimetype='application/json', status=400,
Return an error response to the client with default status code of
*400* stating the error as outlined in :rfc:`5.2`.
"""
return HttpResponse(json.dumps(error), mimetype=mimetype,
return HttpResponse(json.dumps(error), content_type=mimetype,
status=status, **kwargs)

def access_token_response(self, access_token):
Expand All @@ -488,7 +488,7 @@ def access_token_response(self, access_token):
pass

return HttpResponse(
json.dumps(response_data), mimetype='application/json'
json.dumps(response_data), content_type='application/json'
)

def authorization_code(self, request, data, client):
Expand Down