X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/5aa13410812d3fc4b35c039bdc3f0a2edc5185a1..24f677a3979ba3f1bdfe420c03ad5e3f8b0398c2:/src/api/drf_auth.py diff --git a/src/api/drf_auth.py b/src/api/drf_auth.py new file mode 100644 index 000000000..26018c61e --- /dev/null +++ b/src/api/drf_auth.py @@ -0,0 +1,20 @@ +""" +Transitional code: bridge between Piston's OAuth implementation +and DRF views. +""" +from piston.authentication import OAuthAuthentication +from rest_framework.authentication import BaseAuthentication + + +class PistonOAuthAuthentication(BaseAuthentication): + def __init__(self): + self.piston_auth = OAuthAuthentication() + + def authenticate_header(self, request): + return 'OAuth realm="API"' + + def authenticate(self, request): + if self.piston_auth.is_valid_request(request): + consumer, token, parameters = self.piston_auth.validate_token(request) + if consumer and token: + return token.user, token