Skip to content

Commit

Permalink
Merge pull request #12 from Budulianin/ISSUE-11_remove_django_conf_ur…
Browse files Browse the repository at this point in the history
…ls_patterns_from_code

ISSUE-11: remove django.conf.urls.patterns from code and some refactoring
  • Loading branch information
st4lk committed Jan 5, 2016
2 parents 1f8e135 + b6eab9f commit 9f36b2c
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 26 deletions.
Empty file removed rest_social_auth/models.py
Empty file.
11 changes: 8 additions & 3 deletions rest_social_auth/serializers.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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):
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion rest_social_auth/strategy.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
16 changes: 9 additions & 7 deletions rest_social_auth/urls_jwt.py
Original file line number Diff line number Diff line change
@@ -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<provider>[a-zA-Z0-9_-]+)/?)?$', views.SocialJWTUserAuthView.as_view(),
url(r'^social/jwt_user/(?:(?P<provider>[a-zA-Z0-9_-]+)/?)?$',
views.SocialJWTUserAuthView.as_view(),
name='login_social_jwt_user'),

# returns jwt only
url(r'^social/jwt/(?:(?P<provider>[a-zA-Z0-9_-]+)/?)?$', views.SocialJWTOnlyAuthView.as_view(),
name='login_social_jwt'),
)
url(r'^social/jwt/(?:(?P<provider>[a-zA-Z0-9_-]+)/?)?$',
views.SocialJWTOnlyAuthView.as_view(),
name='login_social_jwt'),)
12 changes: 6 additions & 6 deletions rest_social_auth/urls_session.py
Original file line number Diff line number Diff line change
@@ -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<provider>[a-zA-Z0-9_-]+)/?)?$', views.SocialSessionAuthView.as_view(),
name='login_social_session'),
)

urlpatterns = (
url(r'^social/session/(?:(?P<provider>[a-zA-Z0-9_-]+)/?)?$',
views.SocialSessionAuthView.as_view(),
name='login_social_session'),)
16 changes: 9 additions & 7 deletions rest_social_auth/urls_token.py
Original file line number Diff line number Diff line change
@@ -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<provider>[a-zA-Z0-9_-]+)/?)?$', views.SocialTokenUserAuthView.as_view(),
url(r'^social/token_user/(?:(?P<provider>[a-zA-Z0-9_-]+)/?)?$',
views.SocialTokenUserAuthView.as_view(),
name='login_social_token_user'),

# returns token only
url(r'^social/token/(?:(?P<provider>[a-zA-Z0-9_-]+)/?)?$', views.SocialTokenOnlyAuthView.as_view(),
name='login_social_token'),
)
url(r'^social/token/(?:(?P<provider>[a-zA-Z0-9_-]+)/?)?$',
views.SocialTokenOnlyAuthView.as_view(),
name='login_social_token'),)
5 changes: 3 additions & 2 deletions rest_social_auth/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import logging
import warnings
try:
Expand Down Expand Up @@ -27,6 +26,7 @@
from .serializers import (OAuth2InputSerializer, OAuth1InputSerializer, UserSerializer,
TokenSerializer, UserTokenSerializer, JWTSerializer, UserJWTSerializer)


l = logging.getLogger(__name__)


Expand Down Expand Up @@ -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()]
Expand Down
1 change: 1 addition & 0 deletions tests/test_social.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from rest_social_auth.views import load_strategy
from .utils import modify_settings


l = logging.getLogger(__name__)


Expand Down

0 comments on commit 9f36b2c

Please sign in to comment.