1 # This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
4 from oauthlib.oauth1 import ResourceEndpoint
5 from rest_framework.authentication import BaseAuthentication, TokenAuthentication
6 from .request_validator import PistonRequestValidator
7 from .utils import oauthlib_request
8 from .models import Token
11 class PistonOAuthAuthentication(BaseAuthentication):
13 validator = PistonRequestValidator()
14 self.provider = ResourceEndpoint(validator)
16 def authenticate_header(self, request):
17 return 'OAuth realm="API"'
19 def authenticate(self, request):
20 v, r = self.provider.validate_protected_resource_request(
21 **oauthlib_request(request)
24 return r.token.user, r.token
27 class WLTokenAuthentication(TokenAuthentication):