File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -70,3 +70,4 @@ Vinay Karanam
7070Eduardo Oliveira
7171Andrea Greco
7272Dominik George
73+ David Hill
Original file line number Diff line number Diff line change @@ -78,3 +78,35 @@ Now supposing your access token value is `123456` you can try to access your aut
7878::
7979
8080 curl -H "Authorization: Bearer 123456" -X GET http://localhost:8000/secret
81+
82+ Working with Rest_framework generic class based views
83+ -----------------------------------------------------
84+
85+ If you have completed the `Django REST framework tutorial
86+ <https://www.django-rest-framework.org/tutorial/3-class-based-views/#using-generic-class-based-views> `_,
87+ you will be familiar with the 'Snippet' example, in particular the SnippetList and SnippetDetail classes.
88+
89+ It would be nice to reuse those views **and ** support token handling. Instead of reworking
90+ those classes to be ProtectedResourceView based, the solution is much simpler than that.
91+
92+ Assume you have already modified the settings as was already shown.
93+ The key is setting a class attribute to override the default *permissions_classes * with something that will use our :term: `Access Token ` properly.
94+
95+ .. code-block :: python
96+
97+ from oauth2_provider.contrib.rest_framework import TokenHasReadWriteScope
98+
99+ class SnippetList (generics .ListCreateAPIView ):
100+ ...
101+ permission_classes = [TokenHasReadWriteScope]
102+
103+ class SnippetDetail (generics .ListCreateAPIView ):
104+ ...
105+ permission_classes = [TokenHasReadWriteScope]
106+
107+ Note that this example overrides the Django default permission class setting. There are several other
108+ ways this can be solved. Overriding the class function *get_permission_classes * is another way
109+ to solve the problem.
110+
111+ A detailed dive into the `Dango REST framework permissions is here. <https://www.django-rest-framework.org/api-guide/permissions/ >`_
112+
You can’t perform that action at this time.
0 commit comments