Created
June 30, 2021 00:28
-
-
Save WillianFuks/8d366c8ef04c99bba5da90622adb5254 to your computer and use it in GitHub Desktop.
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
# ./testapp/views.py | |
import djwto.authentication as auth # type: ignore | |
from django.views import View | |
from django.utils.decorators import method_decorator | |
from django.http.response import HttpResponse | |
class ProtectedView(View): | |
def dispatch(self, request, *args, **kwargs): | |
return super().dispatch(request, *args, **kwargs) | |
@method_decorator(auth.jwt_login_required) | |
def get( | |
self, | |
request, | |
*args, | |
**kwargs | |
): | |
refresh_claims = request.payload | |
print(refresh_claims) | |
return HttpResponse('worked!') | |
class PermsProtectedView(View): | |
def dispatch(self, request, *args, **kwargs): | |
return super().dispatch(request, *args, **kwargs) | |
@method_decorator(auth.jwt_login_required) | |
@method_decorator(auth.jwt_perm_required(['perm1'])) | |
def get( | |
self, | |
request, | |
*args, | |
**kwargs | |
): | |
refresh_claims = request.payload | |
print(refresh_claims) | |
return HttpResponse('perms also worked!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment