-# -*- coding: utf-8 -*-
-# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
-# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+# This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
#
from oauthlib.oauth1 import ResourceEndpoint
-from rest_framework.authentication import BaseAuthentication
+from rest_framework.authentication import BaseAuthentication, TokenAuthentication
from .request_validator import PistonRequestValidator
+from .utils import oauthlib_request
+from .models import Token
class PistonOAuthAuthentication(BaseAuthentication):
def authenticate(self, request):
v, r = self.provider.validate_protected_resource_request(
- request.build_absolute_uri(),
- http_method=request.method,
- body=request.body,
- headers={
- "Authorization": request.META['HTTP_AUTHORIZATION'],
- "Content-Type": request.content_type,
- } if 'HTTP_AUTHORIZATION' in request.META else None
+ **oauthlib_request(request)
)
if v:
return r.token.user, r.token
+
+
+class WLTokenAuthentication(TokenAuthentication):
+ model = Token