Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for scopes backends to allow easier customization of scopes
- Loading branch information
1 parent
50e02b4
commit 4553923
Showing
12 changed files
with
94 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from __future__ import absolute_import | ||
from __future__ import unicode_literals | ||
|
||
from .settings import oauth2_settings | ||
|
||
|
||
class BaseScopes(object): | ||
def get_all_scopes(self): | ||
""" | ||
Return a dict-like object with all the scopes available in the | ||
system. The key should be the scope name and the value should be | ||
the description. | ||
ex: {'read': 'A read scope', 'write': 'A write scope'} | ||
""" | ||
raise NotImplementedError("") | ||
|
||
def get_available_scopes(self, application=None, request=None, *args, **kwargs): | ||
""" | ||
Return a list of scopes available for the current application/request. | ||
TODO: add info on where and why this method is called. | ||
ex: ['read', 'write'] | ||
""" | ||
raise NotImplementedError("") | ||
|
||
def get_default_scopes(self, application=None, request=None, *args, **kwargs): | ||
""" | ||
Return a list of the default scopes for the current application/request. | ||
This MUST be a subset of the scopes returned by `get_available_scopes`. | ||
TODO: add info on where and why this method is called. | ||
ex: ['read'] | ||
""" | ||
raise NotImplementedError("") | ||
|
||
|
||
class SettingsScopes(BaseScopes): | ||
def get_all_scopes(self): | ||
return oauth2_settings.SCOPES | ||
|
||
def get_available_scopes(self, application=None, request=None, *args, **kwargs): | ||
return oauth2_settings._SCOPES | ||
|
||
def get_default_scopes(self, application=None, request=None, *args, **kwargs): | ||
return oauth2_settings._DEFAULT_SCOPES | ||
|
||
|
||
def get_scopes_backend(): | ||
scopes_class = oauth2_settings.SCOPES_BACKEND_CLASS | ||
return scopes_class() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,7 +124,3 @@ | |
}, | ||
} | ||
} | ||
|
||
OAUTH2_PROVIDER = { | ||
'_SCOPES': ['example'] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from __future__ import absolute_import | ||
from __future__ import unicode_literals | ||
|
||
from oauth2_provider.scopes import SettingsScopes | ||
|
||
|
||
def test_settings_scopes_get_available_scopes(): | ||
scopes = SettingsScopes() | ||
assert scopes.get_available_scopes() == ['read', 'write'] | ||
|
||
|
||
def test_settings_scopes_get_default_scopes(): | ||
scopes = SettingsScopes() | ||
assert scopes.get_default_scopes() == ['read', 'write'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters