------------
Dependencies
------------
-Dependencies that must be meet to use the app:
+Dependencies that *must* be meet to use the application:
- OpenId_ support depends on python-openid_
because the backend string stored in session (like backends.TwitterBackend)
won't match the new paths.
-- The app will try to import custom backends from the sources defined in::
+- The application will try to import custom backends from the sources defined in::
SOCIAL_AUTH_IMPORT_BACKENDS = (
'myproy.social_auth_extra_services',
This way it's easier to add new providers, check the already defined ones
in social_auth.backends for examples.
- Take into account that backends must be defined in AUTHENTICATION_BACKENDS_
+ Take into account that backends *must* be defined in AUTHENTICATION_BACKENDS_
or Django won't pick them when trying to authenticate the user.
- Setup Twitter, Facebook, Orkut and Google OAuth keys (see OAuth_ section
from social_auth.signals import pre_update
from social_auth.backends.facebook import FacebookBackend
- def facebook_extra_values(sender, user, response, details):
+ def facebook_extra_values(sender, user, response, details, **kwargs):
user.gender = response.get('gender')
return True
pre_update.connect(facebook_extra_values, sender=FacebookBackend)
New data updating is made automatically but could be disabled and left only to
-signal handler if this setting value::
+signal handler if this setting value is set to True::
SOCIAL_AUTH_CHANGE_SIGNAL_ONLY = False
-is set to True.
+Take into account that when defining a custom User model and declaring signal
+handler in models.py, the imports and handler definition *must* be made after
+the custom User model is defined or circular imports issues will be raised.
------
OAuth_ communication demands a set of keys exchange to validate the client
authenticity prior to user approbation. Twitter, Facebook and Orkut
facilitates these keys by application registration, Google works the same,
-but provides the option for unregisterd applications.
+but provides the option for unregistered applications.
Check next sections for details.
from django.template import RequestContext
from django.shortcuts import render_to_response
+from social_auth import __version__ as version
+
def home(request):
"""Home view, displays login mechanism"""
if request.user.is_authenticated():
return HttpResponseRedirect('done')
else:
- return render_to_response('home.html', None, RequestContext(request))
+ return render_to_response('home.html', {'version': version},
+ RequestContext(request))
@login_required
def done(request):
"""Login complete view, displays user data"""
names = request.user.social_auth.values_list('provider', flat=True)
- return render_to_response('done.html',
- dict((name.lower().replace('-', '_'), True)
- for name in names),
- RequestContext(request))
+ ctx = dict((name.lower().replace('-', '_'), True) for name in names)
+ ctx['version'] = version
+ return render_to_response('done.html', ctx, RequestContext(request))
def error(request):
"""Error view"""
- return render_to_response('error.html', None, RequestContext(request))
+ return render_to_response('error.html', {'version': version},
+ RequestContext(request))
def logout(request):
"""Logs out user"""