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