Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge remote-tracking branch 'upstream/master'

Conflicts:
	social_auth/tests/base.py
  • Loading branch information...
commit 772903287355b5ef88046c559bda23858120e887 2 parents 041354b + 4596ace
@krvss krvss authored
View
18 README.rst
@@ -302,11 +302,10 @@ Configuration
SOCIAL_AUTH_CREATE_USERS = False
It is also possible to associate multiple user accounts with a single email
- address as long as the rest of the user data is unique. Set value as True
- to enable, otherwise set as False to disable.
- This behavior is disabled by default (false) unless specifically set::
+ address, set value as True to enable, otherwise set as False to disable.
+ This behavior is enabled by default (True) unless specifically set::
- SOCIAL_AUTH_ASSOCIATE_BY_MAIL = True
+ SOCIAL_AUTH_ASSOCIATE_BY_MAIL = False
- You can send extra parameters on auth process by defining settings per
provider, example to request Facebook to show Mobile authorization page,
@@ -687,9 +686,16 @@ at `Facebook development resources`_:
FACEBOOK_APP_ID
FACEBOOK_API_SECRET
-- also it's possible to define extra permissions with::
+- Define ``FACEBOOK_EXTENDED_PERMISSIONS`` to get extra permissions from facebook.
+ NOTE: to get users' email addresses, you must request the 'email' permission::
- FACEBOOK_EXTENDED_PERMISSIONS = [...]
+ FACEBOOK_EXTENDED_PERMISSIONS = ['email']
+
+
+ Take into account that Facebook doesn't return user email by default, this
+ setting is needed if email is required::
+
+ FACEBOOK_EXTENDED_PERMISSIONS = ['email']
- Define ``FACEBOOK_PROFILE_EXTRA_PARAMS`` to pass extra parameters to
https://graph.facebook.com/me when gathering the user profile data, like::
View
10 doc/backends/facebook.rst
@@ -12,9 +12,15 @@ at `Facebook development resources`_:
FACEBOOK_APP_ID
FACEBOOK_API_SECRET
-- also it's possible to define extra permissions with::
+- Define ``FACEBOOK_EXTENDED_PERMISSIONS`` to get extra permissions from facebook.
+ NOTE: to get users' email addresses, you must request the 'email' permission::
- FACEBOOK_EXTENDED_PERMISSIONS = [...]
+ FACEBOOK_EXTENDED_PERMISSIONS = ['email']
+
+ Take into account that Facebook doesn't return user email by default, this
+ setting is needed if email is required::
+
+ FACEBOOK_EXTENDED_PERMISSIONS = ['email']
- Define ``FACEBOOK_PROFILE_EXTRA_PARAMS`` to pass extra parameters to
https://graph.facebook.com/me when gathering the user profile data, like::
View
8 doc/configuration.rst
@@ -195,11 +195,11 @@ Configuration
SOCIAL_AUTH_CREATE_USERS = False
- Also, it's possible to associate user accounts that share the same email
- address if the user entry is unique (that means that if the email is not used
- by more than one account). This behavior is disabled by default unless::
+ It is also possible to associate multiple user accounts with a single email
+ address, set value as True to enable, otherwise set as False to disable.
+ This behavior is enabled by default (True) unless specifically set::
- SOCIAL_AUTH_ASSOCIATE_BY_MAIL = True
+ SOCIAL_AUTH_ASSOCIATE_BY_MAIL = False
- You can send extra parameters on auth process by defining settings per
provider, example to request Facebook to show Mobile authorization page,
View
4 social_auth/backends/contrib/linkedin.py
@@ -62,10 +62,6 @@ def user_data(self, access_token):
except (ExpatError, KeyError, IndexError):
return None
- @classmethod
- def enabled(cls):
- return True
-
def to_dict(xml):
"""Convert XML structure to dict recursively, repeated keys entries
View
4 social_auth/backends/exceptions.py
@@ -39,14 +39,14 @@ def __unicode__(self):
class AuthUnknownError(AuthException):
"""Unknown auth process error."""
def __unicode__(self):
- msg = super(AuthFailed, self).__unicode__()
+ msg = super(AuthUnknownError, self).__unicode__()
return u'An unknown error happened while authenticating %s' % msg
class AuthTokenError(AuthException):
"""Auth token error."""
def __unicode__(self):
- msg = super(AuthFailed, self).__unicode__()
+ msg = super(AuthTokenError, self).__unicode__()
return u'Token error: %s' % msg
View
8 social_auth/backends/pipeline/user.py
@@ -31,7 +31,7 @@ def get_username(details, user=None, user_exists=simple_user_exists,
if setting('SOCIAL_AUTH_FORCE_RANDOM_USERNAME'):
username = uuid4().get_hex()
elif details.get(USERNAME):
- username = details[USERNAME]
+ username = unicode(details[USERNAME])
elif setting('SOCIAL_AUTH_DEFAULT_USERNAME'):
username = setting('SOCIAL_AUTH_DEFAULT_USERNAME')
if callable(username):
@@ -39,17 +39,17 @@ def get_username(details, user=None, user_exists=simple_user_exists,
else:
username = uuid4().get_hex()
- uuid_lenght = setting('SOCIAL_AUTH_UUID_LENGTH', 16)
+ uuid_length = setting('SOCIAL_AUTH_UUID_LENGTH', 16)
username_fixer = setting('SOCIAL_AUTH_USERNAME_FIXER', lambda u: u)
- short_username = username[:USERNAME_MAX_LENGTH - uuid_lenght]
+ short_username = username[:USERNAME_MAX_LENGTH - uuid_length]
final_username = username_fixer(username)[:USERNAME_MAX_LENGTH]
# Generate a unique username for current user using username
# as base but adding a unique hash at the end. Original
# username is cut to avoid any field max_length.
while user_exists(username=final_username):
- username = short_username + uuid4().get_hex()[:uuid_lenght]
+ username = short_username + uuid4().get_hex()[:uuid_length]
final_username = username_fixer(username)[:USERNAME_MAX_LENGTH]
return {'username': final_username}
View
4 social_auth/context_processors.py
@@ -3,8 +3,8 @@
from social_auth.models import User
-# Note: social_auth_backends and social_auth_by_type_backends don't play nice
-# together
+# Note: social_auth_backends, social_auth_by_type_backends and
+# social_auth_by_name_backends don't play nice together.
def social_auth_backends(request):
"""Load Social Auth current user data to context.
View
29 social_auth/tests/base.py
@@ -3,8 +3,9 @@
import cookielib
import urllib
import urlparse
-from django.test.simple import TestCase
+import unittest
from sgmllib import SGMLParser
+from django.conf import settings
from django.test.client import Client
from django.core.urlresolvers import reverse
@@ -14,7 +15,7 @@
REFRESH_RE = re.compile(r'\d;\s*url=')
-class SocialAuthTestsCase(TestCase):
+class SocialAuthTestsCase(unittest.TestCase):
"""Base class for social auth tests"""
SERVER_NAME = None
SERVER_PORT = None
@@ -27,18 +28,21 @@ def __init__(self, *args, **kwargs):
client_kwargs['SERVER_PORT'] = self.SERVER_PORT
self.jar = None
self.client = Client(**client_kwargs)
+ super(SocialAuthTestsCase, self).__init__(*args, **kwargs)
+
+ def setUp(self):
from social_auth import backends
self.old_PIPELINE = backends.PIPELINE
backends.PIPELINE = (
- 'social_auth.backends.pipeline.social.social_auth_user',
- 'social_auth.backends.pipeline.associate.associate_by_email',
- 'social_auth.backends.pipeline.user.get_username',
- 'social_auth.backends.pipeline.user.create_user',
- 'social_auth.backends.pipeline.social.associate_user',
- 'social_auth.backends.pipeline.social.load_extra_data',
- 'social_auth.backends.pipeline.user.update_user_details',
- )
- super(SocialAuthTestsCase, self).__init__(*args, **kwargs)
+ 'social_auth.backends.pipeline.social.social_auth_user',
+ 'social_auth.backends.pipeline.associate.associate_by_email',
+ 'social_auth.backends.pipeline.user.get_username',
+ 'social_auth.backends.pipeline.user.create_user',
+ 'social_auth.backends.pipeline.social.associate_user',
+ 'social_auth.backends.pipeline.social.load_extra_data',
+ 'social_auth.backends.pipeline.user.update_user_details',
+ )
+ super(SocialAuthTestsCase, self).setUp()
def tearDown(self):
from social_auth import backends
@@ -52,6 +56,9 @@ def test_backend_cache(self):
except AttributeError:
pass
else:
+ if self.name not in settings.SOCIAL_AUTH_ENABLED_BACKENDS:
+ # this backend is not enabled (for example, google-openid/google-oauth2)
+ return
from social_auth import backends
backends.BACKENDS = {}
self.client.get(self.reverse('socialauth_begin', self.name))
View
48 social_auth/tests/facebook.py
@@ -2,11 +2,17 @@
from social_auth.utils import setting
from social_auth.tests.base import SocialAuthTestsCase, FormParserByID
+from django.contrib.sites.models import Site
class FacebookTestCase(SocialAuthTestsCase):
SERVER_NAME = 'myapp.com'
SERVER_PORT = '8000'
+
+ def __init__(self, methodName='runTest'):
+ self.SERVER_NAME = Site.objects.get_current()
+ super(FacebookTestCase, self).__init__(methodName)
+
name = 'facebook'
def setUp(self, *args, **kwargs):
@@ -20,18 +26,20 @@ def setUp(self, *args, **kwargs):
REDIRECT_RE = re.compile('window.location.replace\("(.*)"\);')
-
class FacebookTestLogin(FacebookTestCase):
def test_login_succeful(self):
- response = self.client.get(self.reverse('socialauth_begin',
- 'facebook'))
+ """
+
+ """
+ response = self.client.get('http://%s%s' % (self.SERVER_NAME, self.reverse('socialauth_begin', 'facebook')))
# social_auth must redirect to service page
self.assertEqual(response.status_code, 302)
# Open first redirect page, it contains user login form because
# we don't have cookie to send to twitter
parser = FormParserByID('login_form')
- parser.feed(self.get_content(response['Location'], use_cookies=True))
+ content = self.get_content(response['Location'], use_cookies=True)
+ parser.feed(content)
auth = {'email': self.user,
'pass': self.passwd}
@@ -41,26 +49,36 @@ def test_login_succeful(self):
# Post login form, will return authorization or redirect page
parser.values.update(auth)
- content = self.get_content(parser.action, parser.values,
+ redirect = self.get_redirect(parser.action, parser.values,
use_cookies=True)
-
# If page contains a form#login_form, then we are in the app
# authorization page because the app is not authorized yet,
# otherwise the app already gained permission and twitter sends
# a page that redirects to redirect_url
- if 'uiserver_form' in content:
+ if 'login_form' in content:
# authorization form post, returns redirect_page
- parser = FormParserByID('uiserver_form').feed(content)
+ parser = FormParserByID('login_form')
+ parser.feed(content)
self.assertTrue(parser.action)
self.assertTrue(parser.values)
parser.values.update(auth)
- redirect_page = self.get_content(parser.action, parser.values,
+ redirect = self.get_redirect(parser.action, parser.values,
use_cookies=True)
+ redirect_page = redirect.read()
else:
- redirect_page = content
+ redirect = self.get_redirect(redirect.headers['Location'],
+ use_cookies=True)
+ redirect_page = redirect.read()
+
+ if 'uiserver_form' in redirect_page:
+ # authorization form post, returns redirect_page
+ parser = FormParserByID('uiserver_form')
+ parser.feed(redirect_page)
+ self.assertTrue(parser.action)
+ self.assertTrue(parser.values)
+ parser.values.update(auth)
+ redirect = self.get_redirect(parser.action, parser.values,
+ use_cookies=True)
+
- url = REDIRECT_RE.findall(redirect_page)
- self.assertTrue(url)
- # URL comes on JS scaped, needs to be clean first, any better way?
- url = url[0].replace('\u0025', '%').replace('\\', '')
- response = self.client.get(self.make_relative(url))
+ self.assertTrue(setting('LOGIN_REDIRECT_URL') in self.make_relative(redirect.headers['Location']))
View
4 social_auth/tests/google.py
@@ -3,7 +3,7 @@
from social_auth.utils import setting
from social_auth.tests.base import SocialAuthTestsCase, FormParserByID, \
FormParser, RefreshParser
-
+from django.conf import settings
class GoogleTestCase(SocialAuthTestsCase):
@@ -26,6 +26,8 @@ class GoogleOpenIdTestLogin(GoogleTestCase):
SERVER_PORT = '8000'
def test_login_succeful(self):
+ if self.name not in settings.SOCIAL_AUTH_ENABLED_BACKENDS:
+ self.skipTest('Google OpenID is not enabled')
response = self.client.get(self.reverse('socialauth_begin', 'google'))
parser = FormParserByID('openid_message')
Please sign in to comment.
Something went wrong with that request. Please try again.