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
6 from .request_validator import PistonRequestValidator
7 from .utils import oauthlib_request
10 class PistonOAuthAuthentication(BaseAuthentication):
12 validator = PistonRequestValidator()
13 self.provider = ResourceEndpoint(validator)
15 def authenticate_header(self, request):
16 return 'OAuth realm="API"'
18 def authenticate(self, request):
19 v, r = self.provider.validate_protected_resource_request(
20 **oauthlib_request(request)
23 return r.token.user, r.token