1 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 from django.http import HttpResponse, HttpResponseRedirect
5 from django.utils.decorators import method_decorator
6 from django.utils.encoding import iri_to_uri
7 from django.views.decorators.vary import vary_on_headers
10 def oauthlib_request(request):
11 """Creates parameters for OAuthlib's Request from a Django Request."""
13 # We don't have request.content_type yet in 2015,
14 # while test client has no META['CONTENT_TYPE'].
15 ct = request.META.get('CONTENT_TYPE', getattr(request, 'content_type', None))
17 headers["Content-Type"] = ct
18 if 'HTTP_AUTHORIZATION' in request.META:
19 headers["Authorization"] = request.META['HTTP_AUTHORIZATION']
21 "uri": request.build_absolute_uri(),
22 "http_method": request.method,
27 def oauthlib_response(response_tuple):
28 """Creates a django.http.HttpResponse from (headers, body, status) tuple from OAuthlib."""
29 headers, body, status = response_tuple
30 response = HttpResponse(body, status=status)
31 for k, v in headers.items():
38 vary_on_auth = method_decorator(vary_on_headers('Authorization'), 'dispatch')
41 class HttpResponseAppRedirect(HttpResponseRedirect):
42 allowed_schemes = HttpResponseRedirect.allowed_schemes + ['wolnelekturyapp']