I'm using Django 1.5.4 and Django Social Auth 0.7.28 without a problem but wanted to make a switch because of deprecation. During connecting procedure with facebook i can never complete the procedure. I've tried going throught python-social-auth code to see what was going on but couldn't figure it out beside the django authenticate() returning None.
Connecting procedure:
click on:
127.0.0.1 - - [26/Sep/2013 11:33:52] "GET /login/facebook/ HTTP/1.1" 302 -
127.0.0.1 - - [26/Sep/2013 11:33:53] "GET /complete/facebook/?redirect_state=n4Bm...SeNJw&code=AQASofC...MRa57z3o&state=n4Bm...SeNJw HTTP/1.1" 302 -
127.0.0.1 - - [26/Sep/2013 11:33:53] "GET /accounts/login-error/ HTTP/1.1" 404 - (i dont have login-error currently implemented)
This is roughly the state of the various functions that python-social-auth calls
- do_auth facebook -> redirect /dialog/oauth
- complete facebook
do_complete
strategy.request_data()
data: {u'state': u'n4Bm...SeNJw', u'code': u'AQASofC...MRa57z3o', u'redirect_state': u'n4Bm...SeNJw'}
partial is None
- FacebookOAuth2 auth_complete
state: n4BmS...SeNJw
key: 211331415633513
url: https://graph.facebook.com/oauth/access_token
access_token: CAAD...yDE
- FacebookOAuth2 do_auth ---
- FacebookOAuth2 user_data ---
data: {u'username': u'ho...c', ..., u'id': u'100...92'}
- DjangoStrategy authenticate--
args: ()
kwargs contains complete request
kwargs response: {
u'username': u'ho...c', ..., # other profile data
'access_token': u'CAAD...yDE',
u'id': u'100004043024192'
}
kwargs user: None
kwargs backend: social.backends.facebook.FacebookOAuth2
DjangoStrategy backend: social.backends.facebook.FacebookOAuth2
django.contrib.auth.authenticate returns None
not authenticated, not user hence
url = login_error_url # /accounts/login-error/
I've also documented all the changes from django-social-auth (OLD) to python-social-auth (NEW):
Django==1.5.4
django-social-auth==0.7.28
python-social-auth==0.1.13
/accounts/middleware.py
OLD:
from social_auth.middleware import SocialAuthExceptionMiddleware
from social_auth.exceptions import AuthCanceled
NEW:
from social.apps.django_app.middleware import SocialAuthExceptionMiddleware
from social.exceptions import AuthCanceled
accounts/templates/accounts/index.html
OLD
{% if not social_auth.facebook %}
a href="{% url 'socialauth_associate_begin' 'facebook' %}"
NEW
{% if not social.facebook %}
a href="{% url 'social:begin' 'facebook' %}"
accounts/templates/accounts/login.html
OLD:
href="{% url 'socialauth_begin' 'facebook' %}"
NEW:
href="{% url 'social:begin' 'facebook' %}"
cstorm/settings/base.py
OLD INSTALLED_APPS
'social_auth',
NEW INSTALLED_APPS
'social.apps.django_app.default',
OLD:
AUTHENTICATION_BACKENDS = (
'social_auth.backends.facebook.FacebookBackend',
'accounts.auth_backends.EmailOrUsernameBackend',
)
NEW:
AUTHENTICATION_BACKENDS = (
'social.backends.facebook.FacebookOAuth2',
'accounts.auth_backends.EmailOrUsernameBackend',
# 'django.contrib.auth.backends.ModelBackend', #doesnt make a difference
)
OLD:
LOGIN_REDIRECT_URL = '/accounts/postlogin/'
LOGIN_ERROR_URL = '/accounts/login-error/'
NEW:
SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/accounts/postlogin/'
SOCIAL_AUTH_LOGIN_ERROR_URL = '/accounts/login-error/'
OLD:
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.tz',
'django.core.context_processors.request',
'django.contrib.messages.context_processors.messages',
'social_auth.context_processors.social_auth_by_name_backends',
)
NEW:
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.tz',
'django.core.context_processors.request',
'django.contrib.messages.context_processors.messages',
'social.apps.django_app.context_processors.backends',
)
OLD:
SOCIAL_AUTH_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',
'accounts.social_auth_pipeline.get_profile_data', # custom
'accounts.social_auth_pipeline.get_profile_avatar', # custom
)
NEW:
SOCIAL_AUTH_PIPELINE = (
'social.pipeline.social_auth.social_user',
'social.pipeline.social_auth.associate_by_email',
'social.pipeline.user.get_username',
'social.pipeline.user.create_user',
'social.pipeline.social_auth.associate_user',
'social.pipeline.social_auth.load_extra_data',
'social.pipeline.user.user_details',
'accounts.social_auth_pipeline.get_profile_data', # custom
'accounts.social_auth_pipeline.get_profile_avatar', # custom
)
OLD:
FACEBOOK_EXTENDED_PERMISSIONS = ['email', 'user_birthday']
NEW:
#FACEBOOK_EXTENDED_PERMISSIONS = ['email', 'user_birthday']
SOCIAL_AUTH_FACEBOOK_EXTENDED_PERMISSIONS = ['email', 'user_birthday']
SOCIAL_AUTH_FACEBOOK_SCOPE = ['email', 'user_birthday']
OLD:
FACEBOOK_APP_ID = '...'
FACEBOOK_API_SECRET = '...'
NEW:
SOCIAL_AUTH_FACEBOOK_KEY = '...'
SOCIAL_AUTH_FACEBOOK_SECRET = '...'
urls.py
OLD:
(r'^sso/', include('social_auth.urls')),
NEW:
(r'^sso/', include('social.apps.django_app.urls', namespace='social')),