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 oauthlib.oauth1 import ResourceEndpoint
6 from rest_framework.authentication import BaseAuthentication
7 from .request_validator import PistonRequestValidator
8 from .utils import oauthlib_request
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