Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
OAuth2 client allows to override secrets
Artur Smętf88b282b1694
diff --git a/saleor/registration/tests.py b/saleor/registration/tests.pyindex b2999c96d5..826f3e5f6e 100644--- a/saleor/registration/tests.py+++ b/saleor/registration/tests.py@@ -2,6 +2,7 @@ from unittest import TestCasefrom django.contrib.auth import get_user_modelfrom django.core.urlresolvers import resolve+from django.conf import settingsfrom mock import call, Mock, MagicMock, patch, sentinelfrom purl import URL@@ -302,3 +303,33 @@ class EmailChangeTestCase(TestCase):user.save.assert_called_once_with()# user email gets changedself.assertEqual(user.email, token_object.email)+++class OAuthClientTestCase(TestCase):+ def setUp(self):+ self.fake_client_id = 'test'+ self.fake_client_secret = 'testsecret'++ def test_google_secrets_override(self):+ client = GoogleClient(local_host='http://localhost',+ client_id=self.fake_client_id,+ client_secret=self.fake_client_secret)+ self.assertEqual(client.client_id, self.fake_client_id)+ self.assertEqual(client.client_secret, self.fake_client_secret)++ def test_google_secrets_fallback(self):+ client = GoogleClient(local_host='http://localhost')+ self.assertEqual(client.client_id, settings.GOOGLE_CLIENT_ID)+ self.assertEqual(client.client_secret, settings.GOOGLE_CLIENT_SECRET)++ def test_facebook_secrets_override(self):+ client = FacebookClient(local_host='http://localhost',+ client_id=self.fake_client_id,+ client_secret=self.fake_client_secret)+ self.assertEqual(client.client_id, self.fake_client_id)+ self.assertEqual(client.client_secret, self.fake_client_secret)++ def test_facebook_secrets_fallback(self):+ client = FacebookClient(local_host='http://localhost')+ self.assertEqual(client.client_id, settings.FACEBOOK_APP_ID)+ self.assertEqual(client.client_secret, settings.FACEBOOK_SECRET)diff --git a/saleor/registration/utils.py b/saleor/registration/utils.pyindex 664a67800d..ec6e8bfa38 100644--- a/saleor/registration/utils.py+++ b/saleor/registration/utils.py@@ -75,8 +75,14 @@ class OAuth2Client(object):scope = None- def __init__(self, local_host, code=None):+ def __init__(self, local_host, code=None,+ client_id=None, client_secret=None):self.local_host = local_host++ if client_id and client_secret:+ self.client_id = client_id+ self.client_secret = client_secret+if code:access_token = self.get_access_token(code)self.authorizer = OAuth2RequestAuthorizer(@@ -137,9 +143,6 @@ class GoogleClient(OAuth2Client):service = GOOGLE- client_id = settings.GOOGLE_CLIENT_ID- client_secret = settings.GOOGLE_CLIENT_SECRET-auth_uri = 'https://accounts.google.com/o/oauth2/auth'token_uri = 'https://accounts.google.com/o/oauth2/token'user_info_uri = 'https://www.googleapis.com/oauth2/v1/userinfo'@@ -147,6 +150,12 @@ class GoogleClient(OAuth2Client):scope = ' '.join(['https://www.googleapis.com/auth/userinfo.email','https://www.googleapis.com/auth/plus.me'])+ def __init__(self, *args, **kwargs):+ super(GoogleClient, self).__init__(*args, **kwargs)+ if not self.client_id and self.client_secret:+ self.client_id = settings.GOOGLE_CLIENT_ID+ self.client_secret = settings.GOOGLE_CLIENT_SECRET+def get_user_info(self):response = super(GoogleClient, self).get_user_info()if response['verified_email']:@@ -162,15 +171,18 @@ class FacebookClient(OAuth2Client):service = FACEBOOK- client_id = settings.FACEBOOK_APP_ID- client_secret = settings.FACEBOOK_SECRET-auth_uri = 'https://www.facebook.com/dialog/oauth'token_uri = 'https://graph.facebook.com/oauth/access_token'user_info_uri = 'https://graph.facebook.com/me'scope = ','.join(['email'])+ def __init__(self, *args, **kwargs):+ super(FacebookClient, self).__init__(*args, **kwargs)+ if not self.client_id and self.client_secret:+ self.client_id = settings.FACEBOOK_APP_ID+ self.client_secret = settings.FACEBOOK_SECRET+def get_user_info(self):response = super(FacebookClient, self).get_user_info()if response['verified']: