Django Social Auth
Django Social Auth is an easy to setup social authentication/registration mechanism for Django projects.
- OpenId support depends on python-openid
- Twitter and Facebook support demands an application registration on their corresponding sites.
Add social_auth app to your PYTHONPATH
- Add social_auth application to your installed apps::
- INSTALLED_APPS = (
- Add desired authentication backends to AUTHENTICATION_BACKENDS setting::
- AUTHENTICATION_BACKENDS = (
'social_auth.backends.TwitterOAuthBackend', 'social_auth.backends.FacebookOAuthBackend', 'social_auth.backends.OpenIDBackend', 'django.contrib.auth.backends.ModelBackend',
- Setup Twitter and Facebook keys (see below)::
TWITTER_CONSUMER_KEY = '' TWITTER_CONSUMER_SECRET = '' FACEBOOK_APP_ID = '' FACEBOOK_API_SECRET = ''
- Setup login urls::
LOGIN_URL = '/login-form/' LOGIN_REDIRECT_URL = '/logged-in/'
- Sync database to create needed models::
OpenId support is simpler to implement than OAuth, by Google and Yahoo providers are supported by default, others are supported by POST method providing endpoint Url.
OAuth communication demands a set of keys exchange to validate the client authenticity prior to user approbation, Twitter and Facebook facilitates these keys by application registration.
Twitter offers per application keys named "Consumer Key" and "Consumer Secret". To enable Twitter these two keys are needed. Further documentation at Twitter development resources
Register a new app at Twitter App Creation,
mark the "Yes, use Twitter for login" checkbox, and
- fill "Consumer Key" and "Consumer Secret" settings::
Twitter demands a redirect url configuration and will force the user to that address when redirecting, and http://127.0.0.1:8000 won't work. As a development hack, I suggest to setup something like http://myvirtualapp.com and adding an entry in /etc/hosts for that address pointing to localhost, port will be missed, but will do the trick for testing.
If you cannot resit the missing port issue, play a bit with dnsmasq.
Facebook works similar to Twitter but it's simpler to setup and redirect url is passed as a parameter when issuing an authorization. Further documentation at Facebook development resources
Register a new app at Facebook App Creation, and
- fill "App Id" and "App Secret" values in settings::
Several, maybe, please report :-)
Base work is copyrighted by:
- Original Copyright goes to Henrik Lied (henriklied) Code borrowed from https://github.com/henriklied/django-twitter-oauth
- django-openid-auth - OpenID integration for django.contrib.auth Copyright (C) 2007 Simon Willison Copyright (C) 2008-2010 Canonical Ltd.