Skip to content
Snippets Groups Projects
Commit a811d304 authored by Mickael Desfrenes's avatar Mickael Desfrenes
Browse files

trap InvalidToken

parent af772b6a
Branches
No related merge requests found
......@@ -5,6 +5,7 @@ from django.contrib.auth import get_user_model
from django.core.exceptions import PermissionDenied
from django.shortcuts import get_object_or_404
from rest_framework_simplejwt.authentication import JWTAuthentication
from rest_framework_simplejwt.exceptions import InvalidToken
from revproxy.views import ProxyView
from pount.apps.api.models import MediaFile
......@@ -53,16 +54,19 @@ def get_request_headers(self):
ProxyView.get_request_headers = get_request_headers
class TestProxyView(ProxyView):
class IIIFProxyView(ProxyView):
upstream = environ.get("IIIF_UPSTREAM_URL", "http://localhost:8182/iiif/")
add_x_forwarded = True
def dispatch(self, request, *args, **kwargs):
response = JWT_authenticator.authenticate(request)
if response is not None:
user, _ = response
file_id = request.path.lstrip("iiif/3").split(".tiled.tif")[0]
file = get_object_or_404(MediaFile, id=file_id)
if user.has_perm(ITEM_VIEW, file.item):
return super().dispatch(request, *args, **kwargs)
try:
response = JWT_authenticator.authenticate(request)
if response is not None:
user, _ = response
file_id = request.path.lstrip("iiif/3").split(".tiled.tif")[0]
file = get_object_or_404(MediaFile, id=file_id)
if user.has_perm(ITEM_VIEW, file.item):
return super().dispatch(request, *args, **kwargs)
except InvalidToken:
pass # should renew ?
raise PermissionDenied()
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment