mirror of
https://github.com/Tivix/django-rest-auth.git
synced 2024-11-16 06:06:34 +03:00
c5e0382d25
* Added twitter login test * pep8 * Fixes missing backend attr issue * Refactored login process * pep8 * Added more tests for twitter social login
54 lines
1.9 KiB
Python
54 lines
1.9 KiB
Python
from django.conf.urls import url, include
|
|
from django.views.generic import TemplateView
|
|
from . import django_urls
|
|
|
|
from allauth.socialaccount.providers.facebook.views import FacebookOAuth2Adapter
|
|
from allauth.socialaccount.providers.twitter.views import TwitterOAuthAdapter
|
|
|
|
from rest_framework.decorators import api_view
|
|
|
|
from rest_auth.urls import urlpatterns
|
|
from rest_auth.registration.views import SocialLoginView
|
|
from rest_auth.social_serializers import TwitterLoginSerializer
|
|
|
|
|
|
class FacebookLogin(SocialLoginView):
|
|
adapter_class = FacebookOAuth2Adapter
|
|
|
|
|
|
class TwitterLogin(SocialLoginView):
|
|
adapter_class = TwitterOAuthAdapter
|
|
serializer_class = TwitterLoginSerializer
|
|
|
|
|
|
class TwitterLoginSerializerFoo(TwitterLoginSerializer):
|
|
pass
|
|
|
|
|
|
@api_view(['POST'])
|
|
def twitter_login_view(request):
|
|
serializer = TwitterLoginSerializerFoo(
|
|
data={'access_token': '11223344', 'token_secret': '55667788'},
|
|
context={'request': request}
|
|
)
|
|
serializer.is_valid(raise_exception=True)
|
|
|
|
|
|
class TwitterLoginNoAdapter(SocialLoginView):
|
|
serializer_class = TwitterLoginSerializer
|
|
|
|
|
|
urlpatterns += [
|
|
url(r'^rest-registration/', include('rest_auth.registration.urls')),
|
|
url(r'^test-admin/', include(django_urls)),
|
|
url(r'^account-email-verification-sent/$', TemplateView.as_view(),
|
|
name='account_email_verification_sent'),
|
|
url(r'^account-confirm-email/(?P<key>\w+)/$', TemplateView.as_view(),
|
|
name='account_confirm_email'),
|
|
url(r'^social-login/facebook/$', FacebookLogin.as_view(), name='fb_login'),
|
|
url(r'^social-login/twitter/$', TwitterLogin.as_view(), name='tw_login'),
|
|
url(r'^social-login/twitter-no-view/$', twitter_login_view, name='tw_login_no_view'),
|
|
url(r'^social-login/twitter-no-adapter/$', TwitterLoginNoAdapter.as_view(), name='tw_login_no_adapter'),
|
|
url(r'^accounts/', include('allauth.socialaccount.urls'))
|
|
]
|