-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(social login): integrate social login
- add social authentication packages - add social authentication endpoint - add migrations to flake8 excluded folders [finishes #164046249]
- Loading branch information
Showing
8 changed files
with
195 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
[flake8] | ||
ignore = W391 | ||
max-line-length = 80 | ||
exclude = */tests/* */settings/* | ||
exclude = */tests/* */settings/* */migrations/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import os | ||
from django.urls import reverse | ||
from rest_framework import status | ||
from rest_framework.test import APITestCase, APIClient | ||
|
||
|
||
|
||
class Test_Social_Authentication(APITestCase): | ||
"""Tests social authentication""" | ||
url = reverse('authentication:social_login') | ||
|
||
def setUp(self): | ||
self.provider = "twitter" | ||
self.data = { | ||
"access_token": os.environ['TWITTER_ACCESS_TOKEN'], | ||
"access_token_secret": os.environ['TWITTER_ACCESS_TOKEN_SECRET'], | ||
"provider": self.provider | ||
} | ||
|
||
def test_user_successful_social_login(self): | ||
"""Test for successful user login""" | ||
response = self.client.post(self.url, self.data, format='json') | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
|
||
def test_wrong_provider_message(self): | ||
self.data = { | ||
"access_token": os.environ['TWITTER_ACCESS_TOKEN'], | ||
"access_token_secret": os.environ['TWITTER_ACCESS_TOKEN_SECRET'], | ||
"provider": "twitt" | ||
} | ||
error_msg = """Provider not supported, Please use 'google-oauth2', | ||
'facebook', or 'twitter'.""" | ||
response = self.client.post(self.url, self.data, format='json') | ||
self.assertEqual(response.data['error'], error_msg) | ||
|
||
def test_wrong_credentials(self): | ||
"""Test wrong credentials""" | ||
self.data = { | ||
"access_token": os.environ['TWITTER_ACCESS_TOKEN_INVALID'], | ||
"access_token_secret": os.environ['TWITTER_ACCESS_TOKEN_SECRET'], | ||
"provider": "twitter" | ||
} | ||
response = self.client.post(self.url, self.data, format='json') | ||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) | ||
|
||
def test_facebook_oauth(self): | ||
"""Test facebook Oauth""" | ||
self.data = { | ||
"access_token": os.environ['FACEBOOK_ACCESS_TOKEN'], | ||
"access_token_secret": os.environ['TWITTER_ACCESS_TOKEN_SECRET'], | ||
"provider": "facebook" | ||
} | ||
response = self.client.post(self.url, self.data, format='json') | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
|
||
def test_google_auth(self): | ||
"""Test Google Oauth""" | ||
self.data = { | ||
"access_token": os.environ['GOOGLE_ACCESS_TOKEN'], | ||
"access_token_secret": os.environ['TWITTER_ACCESS_TOKEN_SECRET'], | ||
"provider": "google-oauth2" | ||
} | ||
|
||
response = self.client.post(self.url, self.data, format='json') | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
from django.urls import path | ||
|
||
from .views import (LoginAPIView, RegistrationAPIView, | ||
UserRetrieveUpdateAPIView) | ||
UserRetrieveUpdateAPIView, SocialAuthenticationView) | ||
|
||
app_name = 'authentication' | ||
|
||
urlpatterns = [ | ||
path('user/', UserRetrieveUpdateAPIView.as_view(), name='get users'), | ||
path('users/', RegistrationAPIView.as_view(), name='register'), | ||
path('users/login/', LoginAPIView.as_view(), name='login'), | ||
path('users/oauth/', SocialAuthenticationView.as_view(), | ||
name='social_login') | ||
|
||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters