Skip to content

Commit 94e02d9

Browse files
committed
AuthorizationView now returns a successful redirect response if user has previous authorized client.
1 parent ac09b56 commit 94e02d9

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

oauth2_provider/views/base.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import datetime
23

34
from django.http import HttpResponse, HttpResponseRedirect
45
from django.views.generic import View, FormView
@@ -113,6 +114,17 @@ def get(self, request, *args, **kwargs):
113114
# following code is here only because of https://code.djangoproject.com/ticket/17795
114115
form = self.get_form(self.get_form_class())
115116
kwargs['form'] = form
117+
118+
# Check to see if the user has already granted access and return
119+
# a successful response
120+
if request.user.accesstoken_set.filter(
121+
application=kwargs['application'],
122+
expires__gt=datetime.datetime.now()).count():
123+
uri, headers, body, status = self.create_authorization_response(
124+
request=self.request, scopes=" ".join(scopes),
125+
credentials=credentials, allow=True)
126+
self.success_url = uri
127+
return HttpResponseRedirect(self.success_url)
116128
return self.render_to_response(self.get_context_data(**kwargs))
117129

118130
except OAuthToolkitError as error:

0 commit comments

Comments
 (0)