Skip to content

Instantly share code, notes, and snippets.

@WillianFuks
Created June 30, 2021 00:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WillianFuks/8d366c8ef04c99bba5da90622adb5254 to your computer and use it in GitHub Desktop.
Save WillianFuks/8d366c8ef04c99bba5da90622adb5254 to your computer and use it in GitHub Desktop.
# ./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