Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
125 lines (98 sloc) 4.13 KB

Django Social Auth

Django Social Auth is an easy to setup social authentication/registration mechanism for Django projects.

Crafted using base code from django-twitter-oauth and django-openid-auth, implements a common interface to define new authentication providers from third parties.

#. Dependencies

  • OpenId support depends on python-openid
  • Twitter and Facebook support demands an application registration on their corresponding sites.

#. Installation

  1. Add social_auth app to your PYTHONPATH

  2. Add social_auth application to your installed apps::

    ... 'social_auth'


  3. Add desired authentication backends to AUTHENTICATION_BACKENDS setting::

    'social_auth.backends.TwitterOAuthBackend', 'social_auth.backends.FacebookOAuthBackend', 'social_auth.backends.OpenIDBackend', 'django.contrib.auth.backends.ModelBackend',


  4. Setup Twitter and Facebook keys (see below)::


  5. Setup login urls::

    LOGIN_URL = '/login-form/' LOGIN_REDIRECT_URL = '/logged-in/'

    Check docs at LOGIN_URL and LOGIN_REDIRECT_URL.

  1. Sync database to create needed models::

    ./manage syncdb

#. OpenId

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

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

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 won't work. As a development hack, I suggest to setup something like 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

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::


#. Bugs

Several, maybe, please report :-)

5. Copyrights

Base work is copyrighted by:

Original Copyright goes to Henrik Lied (henriklied) Code borrowed from
django-openid-auth - OpenID integration for django.contrib.auth Copyright (C) 2007 Simon Willison Copyright (C) 2008-2010 Canonical Ltd.
Jump to Line
Something went wrong with that request. Please try again.