diff --git a/rest_social_auth/models.py b/rest_social_auth/models.py deleted file mode 100644 index e69de29..0000000 diff --git a/rest_social_auth/serializers.py b/rest_social_auth/serializers.py index 3b70ab1..f6fcf07 100644 --- a/rest_social_auth/serializers.py +++ b/rest_social_auth/serializers.py @@ -1,13 +1,15 @@ -# -*- coding: utf-8 -*- import logging import warnings from rest_framework import serializers from rest_framework.authtoken.models import Token from django.contrib.auth import get_user_model + l = logging.getLogger(__name__) + class OAuth2InputSerializer(serializers.Serializer): + provider = serializers.CharField(required=False) code = serializers.CharField() redirect_uri = serializers.CharField(required=False) @@ -25,10 +27,11 @@ class UserSerializer(serializers.ModelSerializer): class Meta: model = get_user_model() exclude = ('is_staff', 'is_active', 'date_joined', 'password', - 'last_login', 'user_permissions', 'groups', 'is_superuser') + 'last_login', 'user_permissions', 'groups', 'is_superuser',) class TokenSerializer(serializers.Serializer): + token = serializers.SerializerMethodField() def get_token(self, obj): @@ -41,11 +44,13 @@ class UserTokenSerializer(TokenSerializer, UserSerializer): class JWTSerializer(TokenSerializer): + def get_token(self, obj): try: from rest_framework_jwt.settings import api_settings except ImportError: - warnings.warn('djangorestframework-jwt must be installed for JWT autthentication', ImportWarning) + warnings.warn('djangorestframework-jwt must be installed for JWT authentication', + ImportWarning) raise jwt_payload_handler = api_settings.JWT_PAYLOAD_HANDLER diff --git a/rest_social_auth/strategy.py b/rest_social_auth/strategy.py index 3bff979..3b56342 100644 --- a/rest_social_auth/strategy.py +++ b/rest_social_auth/strategy.py @@ -1,17 +1,19 @@ -# -*- coding: utf-8 -*- from social.strategies.django_strategy import DjangoStrategy class DRFStrategy(DjangoStrategy): + def __init__(self, storage, request=None, tpl=None): self.request = request self.session = {} + if request: try: self.session = request.session except AttributeError: # in case of token auth session can be disabled at all pass + super(DjangoStrategy, self).__init__(storage, tpl) def request_data(self, merge=True): diff --git a/rest_social_auth/urls_jwt.py b/rest_social_auth/urls_jwt.py index f5fa233..d2820a8 100644 --- a/rest_social_auth/urls_jwt.py +++ b/rest_social_auth/urls_jwt.py @@ -1,13 +1,15 @@ -# -*- coding: utf-8 -*- -from django.conf.urls import patterns, url +from django.conf.urls import url from . import views -urlpatterns = patterns('', + +urlpatterns = ( # returns jwt + user_data - url(r'^social/jwt_user/(?:(?P[a-zA-Z0-9_-]+)/?)?$', views.SocialJWTUserAuthView.as_view(), + url(r'^social/jwt_user/(?:(?P[a-zA-Z0-9_-]+)/?)?$', + views.SocialJWTUserAuthView.as_view(), name='login_social_jwt_user'), + # returns jwt only - url(r'^social/jwt/(?:(?P[a-zA-Z0-9_-]+)/?)?$', views.SocialJWTOnlyAuthView.as_view(), - name='login_social_jwt'), -) + url(r'^social/jwt/(?:(?P[a-zA-Z0-9_-]+)/?)?$', + views.SocialJWTOnlyAuthView.as_view(), + name='login_social_jwt'),) diff --git a/rest_social_auth/urls_session.py b/rest_social_auth/urls_session.py index bdccaf0..427f51e 100644 --- a/rest_social_auth/urls_session.py +++ b/rest_social_auth/urls_session.py @@ -1,9 +1,9 @@ -# -*- coding: utf-8 -*- -from django.conf.urls import patterns, url +from django.conf.urls import url from . import views -urlpatterns = patterns('', - url(r'^social/session/(?:(?P[a-zA-Z0-9_-]+)/?)?$', views.SocialSessionAuthView.as_view(), - name='login_social_session'), -) + +urlpatterns = ( + url(r'^social/session/(?:(?P[a-zA-Z0-9_-]+)/?)?$', + views.SocialSessionAuthView.as_view(), + name='login_social_session'),) diff --git a/rest_social_auth/urls_token.py b/rest_social_auth/urls_token.py index 7aadbe1..9fdfd90 100644 --- a/rest_social_auth/urls_token.py +++ b/rest_social_auth/urls_token.py @@ -1,13 +1,15 @@ -# -*- coding: utf-8 -*- -from django.conf.urls import patterns, url +from django.conf.urls import url from . import views -urlpatterns = patterns('', + +urlpatterns = ( # returns token + user_data - url(r'^social/token_user/(?:(?P[a-zA-Z0-9_-]+)/?)?$', views.SocialTokenUserAuthView.as_view(), + url(r'^social/token_user/(?:(?P[a-zA-Z0-9_-]+)/?)?$', + views.SocialTokenUserAuthView.as_view(), name='login_social_token_user'), + # returns token only - url(r'^social/token/(?:(?P[a-zA-Z0-9_-]+)/?)?$', views.SocialTokenOnlyAuthView.as_view(), - name='login_social_token'), -) + url(r'^social/token/(?:(?P[a-zA-Z0-9_-]+)/?)?$', + views.SocialTokenOnlyAuthView.as_view(), + name='login_social_token'),) diff --git a/rest_social_auth/views.py b/rest_social_auth/views.py index 1b9cdc0..782ffe0 100644 --- a/rest_social_auth/views.py +++ b/rest_social_auth/views.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- import logging import warnings try: @@ -27,6 +26,7 @@ from .serializers import (OAuth2InputSerializer, OAuth1InputSerializer, UserSerializer, TokenSerializer, UserTokenSerializer, JWTSerializer, UserJWTSerializer) + l = logging.getLogger(__name__) @@ -197,7 +197,8 @@ def get_authenticators(self): try: from rest_framework_jwt.authentication import JSONWebTokenAuthentication except ImportError: - warnings.warn('djangorestframework-jwt must be installed for JWT autthentication', ImportWarning) + warnings.warn('djangorestframework-jwt must be installed for JWT authentication', + ImportWarning) raise return [JSONWebTokenAuthentication()] diff --git a/tests/test_social.py b/tests/test_social.py index 582c78e..a70d811 100644 --- a/tests/test_social.py +++ b/tests/test_social.py @@ -20,6 +20,7 @@ from rest_social_auth.views import load_strategy from .utils import modify_settings + l = logging.getLogger(__name__)