Skip to content

Commit b3c1cee

Browse files
n2ygkjleclanche
authored andcommitted
Rename TokenHasMethodScopeAlternative to TokenMatchesOASRequirements
1 parent b4378b3 commit b3c1cee

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
* **Compatibility**: Python 3.4 is the new minimum required version.
44
* **Compatibility**: Django 2.0 is the new minimum required version.
5-
* **New feature**: Added TokenHasMethodScopeAlternative Permissions.
5+
* **New feature**: Added TokenMatchesOASRequirements Permissions.
66

77
### 1.1.1 [2018-05-08]
88

docs/rest-framework/permissions.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ For example:
8484
The `required_scopes` attribute is mandatory.
8585

8686

87-
TokenHasMethodScopeAlternative
87+
TokenMatchesOASRequirements
8888
------------------------------
8989

90-
The `TokenHasMethodScopeAlternative` permission class allows the access based on a per-method basis
90+
The `TokenMatchesOASRequirements` permission class allows the access based on a per-method basis
9191
and with alternative lists of required scopes. This permission provides full functionality
9292
required by REST API specifications like the
9393
`OpenAPI Specification (OAS) security requirement object <https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#securityRequirementObject>`_.
@@ -102,7 +102,7 @@ etc.
102102
103103
class SongView(views.APIView):
104104
authentication_classes = [OAuth2Authentication]
105-
permission_classes = [TokenHasMethodScopeAlternative]
105+
permission_classes = [TokenMatchesOASRequirements]
106106
required_alternate_scopes = {
107107
"GET": [["read"]],
108108
"POST": [["create"], ["post", "widget"]],
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# flake8: noqa
22
from .authentication import OAuth2Authentication
33
from .permissions import (
4-
TokenHasScope, TokenHasReadWriteScope, TokenHasMethodScopeAlternative,
4+
TokenHasScope, TokenHasReadWriteScope, TokenMatchesOASRequirements,
55
TokenHasResourceScope, IsAuthenticatedOrTokenHasScope
66
)

oauth2_provider/contrib/rest_framework/permissions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def has_permission(self, request, view):
123123
return (is_authenticated and not oauth2authenticated) or token_has_scope.has_permission(request, view)
124124

125125

126-
class TokenHasMethodScopeAlternative(BasePermission):
126+
class TokenMatchesOASRequirements(BasePermission):
127127
"""
128128
:attr:alternate_required_scopes: dict keyed by HTTP method name with value: iterable alternate scope lists
129129
@@ -165,7 +165,7 @@ def has_permission(self, request, view):
165165
log.warning("no scope alternates defined for method {0}".format(m))
166166
return False
167167

168-
assert False, ("TokenHasMethodScope requires the"
168+
assert False, ("TokenMatchesOASRequirements requires the"
169169
"`oauth2_provider.rest_framework.OAuth2Authentication` authentication "
170170
"class to be used.")
171171

@@ -174,5 +174,5 @@ def get_required_alternate_scopes(self, request, view):
174174
return getattr(view, "required_alternate_scopes")
175175
except AttributeError:
176176
raise ImproperlyConfigured(
177-
"TokenHasMethodScopeAlternative requires the view to"
177+
"TokenMatchesOASRequirements requires the view to"
178178
" define the required_alternate_scopes attribute")

tests/test_rest_framework.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
from oauth2_provider.contrib.rest_framework import (
1616
IsAuthenticatedOrTokenHasScope, OAuth2Authentication,
17-
TokenHasMethodScopeAlternative, TokenHasReadWriteScope,
18-
TokenHasResourceScope, TokenHasScope
17+
TokenHasReadWriteScope, TokenHasResourceScope,
18+
TokenHasScope, TokenMatchesOASRequirements
1919
)
2020
from oauth2_provider.models import get_access_token_model, get_application_model
2121
from oauth2_provider.settings import oauth2_settings
@@ -69,7 +69,7 @@ class ResourceScopedView(OAuth2View):
6969

7070

7171
class MethodScopeAltView(OAuth2View):
72-
permission_classes = [TokenHasMethodScopeAlternative]
72+
permission_classes = [TokenMatchesOASRequirements]
7373
required_alternate_scopes = {
7474
"GET": [["read"]],
7575
"POST": [["create"]],
@@ -79,7 +79,7 @@ class MethodScopeAltView(OAuth2View):
7979

8080

8181
class MethodScopeAltViewBad(OAuth2View):
82-
permission_classes = [TokenHasMethodScopeAlternative]
82+
permission_classes = [TokenMatchesOASRequirements]
8383

8484

8585
class MissingAuthentication(BaseAuthentication):
@@ -96,7 +96,7 @@ class TokenHasScopeViewWrongAuth(BrokenOAuth2View):
9696

9797

9898
class MethodScopeAltViewWrongAuth(BrokenOAuth2View):
99-
permission_classes = [TokenHasMethodScopeAlternative]
99+
permission_classes = [TokenMatchesOASRequirements]
100100

101101

102102
urlpatterns = [

0 commit comments

Comments
 (0)