Skip to content

Commit 549d6e6

Browse files
committed
Created a setting for the default value for approval prompt.
1 parent 6be74fc commit 549d6e6

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed

oauth2_provider/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
'AUTHORIZATION_CODE_EXPIRE_SECONDS': 60,
3636
'ACCESS_TOKEN_EXPIRE_SECONDS': 36000,
3737
'APPLICATION_MODEL': getattr(settings, 'OAUTH2_PROVIDER_APPLICATION_MODEL', 'oauth2_provider.Application'),
38+
'REQUEST_APPROVAL_PROMPT': 'force',
3839

3940
# Special settings that will be evaluated at runtime
4041
'_SCOPES': [],

oauth2_provider/tests/test_authorization_code.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,50 @@ def test_pre_auth_approval_prompt(self):
118118
response = self.client.get(url)
119119
self.assertEqual(response.status_code, 200)
120120

121+
def test_pre_auth_approval_prompt_default(self):
122+
"""
123+
124+
"""
125+
self.assertEqual(oauth2_settings.REQUEST_APPROVAL_PROMPT, 'force')
126+
127+
AccessToken.objects.create(user=self.test_user, token='1234567890',
128+
application=self.application,
129+
expires=timezone.now()+datetime.timedelta(days=1),
130+
scope='read write')
131+
self.client.login(username="test_user", password="123456")
132+
query_string = urlencode({
133+
'client_id': self.application.client_id,
134+
'response_type': 'code',
135+
'state': 'random_state_string',
136+
'scope': 'read write',
137+
'redirect_uri': 'http://example.it',
138+
})
139+
url = "{url}?{qs}".format(url=reverse('oauth2_provider:authorize'), qs=query_string)
140+
response = self.client.get(url)
141+
self.assertEqual(response.status_code, 200)
142+
143+
def test_pre_auth_approval_prompt_default_override(self):
144+
"""
145+
146+
"""
147+
oauth2_settings.REQUEST_APPROVAL_PROMPT = 'auto'
148+
149+
AccessToken.objects.create(user=self.test_user, token='1234567890',
150+
application=self.application,
151+
expires=timezone.now()+datetime.timedelta(days=1),
152+
scope='read write')
153+
self.client.login(username="test_user", password="123456")
154+
query_string = urlencode({
155+
'client_id': self.application.client_id,
156+
'response_type': 'code',
157+
'state': 'random_state_string',
158+
'scope': 'read write',
159+
'redirect_uri': 'http://example.it',
160+
})
161+
url = "{url}?{qs}".format(url=reverse('oauth2_provider:authorize'), qs=query_string)
162+
response = self.client.get(url)
163+
self.assertEqual(response.status_code, 302)
164+
121165
def test_pre_auth_default_redirect(self):
122166
"""
123167
Test for default redirect uri if omitted from query string with response_type: code

oauth2_provider/views/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def get(self, request, *args, **kwargs):
116116

117117
# Check to see if the user has already granted access and return
118118
# a successful response depending on 'approval_prompt' url parameter
119-
require_approval = request.GET.get('approval_prompt', 'force')
119+
require_approval = request.GET.get('approval_prompt', oauth2_settings.REQUEST_APPROVAL_PROMPT)
120120
if require_approval == 'auto':
121121
tokens = request.user.accesstoken_set.filter(application=kwargs['application'],
122122
expires__gt=timezone.now()).all()

requirements/testing.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
-r optional.txt
22
coverage==3.6
3-
mock
3+
mock
4+
ipdb

0 commit comments

Comments
 (0)