Skip to content

Commit 8b66536

Browse files
Psykopearsynasius
authored andcommitted
Fixed DEFAULT_SCOPES to be a list
1 parent 9924b26 commit 8b66536

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

oauth2_provider/oauth2_validators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def validate_scopes(self, client_id, scopes, client, request, *args, **kwargs):
278278
return set(scopes).issubset(set(oauth2_settings._SCOPES))
279279

280280
def get_default_scopes(self, client_id, request, *args, **kwargs):
281-
return oauth2_settings._DEFAULT_SCOPES or oauth2_settings._SCOPES
281+
return oauth2_settings._DEFAULT_SCOPES
282282

283283
def validate_redirect_uri(self, client_id, redirect_uri, request, *args, **kwargs):
284284
return request.client.redirect_uri_allowed(redirect_uri)

oauth2_provider/settings.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import six
2121

2222
from django.conf import settings
23+
from django.core.exceptions import ImproperlyConfigured
2324
try:
2425
# Available in Python 2.7+
2526
import importlib
@@ -36,7 +37,7 @@
3637
'OAUTH2_VALIDATOR_CLASS': 'oauth2_provider.oauth2_validators.OAuth2Validator',
3738
'OAUTH2_BACKEND_CLASS': 'oauth2_provider.oauth2_backends.OAuthLibCore',
3839
'SCOPES': {"read": "Reading scope", "write": "Writing scope"},
39-
'DEFAULT_SCOPES': {},
40+
'DEFAULT_SCOPES': ['__all__'],
4041
'READ_SCOPE': 'read',
4142
'WRITE_SCOPE': 'write',
4243
'AUTHORIZATION_CODE_EXPIRE_SECONDS': 60,
@@ -131,7 +132,17 @@ def __getattr__(self, attr):
131132
if attr == '_SCOPES':
132133
val = list(six.iterkeys(self.SCOPES))
133134
if attr == '_DEFAULT_SCOPES':
134-
val = list(six.iterkeys(self.DEFAULT_SCOPES))
135+
if '__all__' in self.DEFAULT_SCOPES:
136+
# If DEFAULT_SCOPES is set to ['__all__'] the whole set of scopes is returned
137+
val = list(self._SCOPES)
138+
else:
139+
# Otherwise we return a subset (that can be void) of SCOPES
140+
val = []
141+
for scope in self.DEFAULT_SCOPES:
142+
if scope in self._SCOPES:
143+
val.append(scope)
144+
else:
145+
raise ImproperlyConfigured("Defined DEFAULT_SCOPES not present in SCOPES")
135146

136147
self.validate_setting(attr, val)
137148

0 commit comments

Comments
 (0)