X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/1434b3dfc0495e885921acb726df6cc06e00c5ed..733a35d165f8fa095c3dfcbb74ac7aae3c320a2e:/src/api/utils.py diff --git a/src/api/utils.py b/src/api/utils.py index 6dc7e4505..a3a1f893a 100644 --- a/src/api/utils.py +++ b/src/api/utils.py @@ -2,8 +2,10 @@ # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # -from django.http import HttpResponse +from django.http import HttpResponse, HttpResponseRedirect +from django.utils.decorators import method_decorator from django.utils.encoding import iri_to_uri +from django.views.decorators.vary import vary_on_headers def oauthlib_request(request): @@ -23,11 +25,19 @@ def oauthlib_request(request): "headers": headers, } -def oauthlib_response((headers, body, status)): +def oauthlib_response(response_tuple): """Creates a django.http.HttpResponse from (headers, body, status) tuple from OAuthlib.""" + headers, body, status = response_tuple response = HttpResponse(body, status=status) for k, v in headers.items(): if k == 'Location': v = iri_to_uri(v) response[k] = v return response + + +vary_on_auth = method_decorator(vary_on_headers('Authorization'), 'dispatch') + + +class HttpResponseAppRedirect(HttpResponseRedirect): + allowed_schemes = HttpResponseRedirect.allowed_schemes + ['wolnelekturyapp']