diff --git a/pount/apps/iiif/views.py b/pount/apps/iiif/views.py index a765bea63abb221dc5512b8a1833f6ff3746a3b0..e0ec212b3ec22b362b3e6ee6b46f018079f98fea 100644 --- a/pount/apps/iiif/views.py +++ b/pount/apps/iiif/views.py @@ -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()