Skip to content

Commit fed892b

Browse files
committed
fixed #182: added TokenHasReadWrite docs
1 parent 7a96af7 commit fed892b

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

docs/rest-framework/permissions.rst

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ More details on how to add custom permissions to your API Endpoints can be found
1111
TokenHasScope
1212
-------------
1313

14-
The `TokenHasScope` permission class will allow the access only when the current access token has been
15-
authorized for all the scopes listed in the `required_scopes` field of the view.
14+
The `TokenHasScope` permission class allows the access only when the current access token has been
15+
authorized for **all** the scopes listed in the `required_scopes` field of the view.
1616

1717
For example:
1818

@@ -29,5 +29,22 @@ The `required_scopes` attribute is mandatory.
2929
TokenHasReadWriteScope
3030
----------------------
3131

32-
TODO: add docs for TokenHasReadWriteScope permission class with usage examples
32+
The `TokenHasReadWriteScope` permission class allows the access based on the `READ_SCOPE` and `WRITE_SCOPE` configured in the settings.
33+
34+
When the current request's method is one of the "safe" methods `GET`, `HEAD`, `OPTIONS`
35+
the access is allowed only if the access token has been authorized for the `READ_SCOPE` scope.
36+
When the request's method is one of `POST`, `PUT`, `PATCH`, `DELETE` the access is allowed if the access token has been authorized for the `WRITE_SCOPE`.
37+
38+
The `required_scopes` attribute is optional and can be used to other scopes needed by the view.
39+
40+
For example:
41+
42+
.. code-block:: python
43+
44+
class SongView(views.APIView):
45+
authentication_classes = [OAuth2Authentication]
46+
permission_classes = [TokenHasReadWriteScope]
47+
required_scopes = ['music']
48+
49+
When a request is performed both the `READ_SCOPE`\`WRITE_SCOPE` and 'music' scopes are required to be authorized for the current access token.
3350

0 commit comments

Comments
 (0)