Skip to content

Commit e8abb5e

Browse files
committed
Merge branch 'autoauthorize' of https://github.com/Natgeoed/django-oauth-toolkit into Natgeoed-autoauthorize
2 parents 16524e0 + 5ab6075 commit e8abb5e

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

oauth2_provider/views/base.py

Lines changed: 13 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
@@ -112,6 +113,18 @@ def get(self, request, *args, **kwargs):
112113
# following code is here only because of https://code.djangoproject.com/ticket/17795
113114
form = self.get_form(self.get_form_class())
114115
kwargs['form'] = form
116+
117+
# Check to see if the user has already granted access and return
118+
# a successful response
119+
require_approval = request.get('approval_prompt', 'auto') == 'auto'
120+
if not require_approval and 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)
115128
return self.render_to_response(self.get_context_data(**kwargs))
116129

117130
except OAuthToolkitError as error:

0 commit comments

Comments
 (0)