Django-SocialAuth – Login via twitter, facebook, openid, yahoo, google using a single app.

by shabda on August 27, 2009

TL;DR version: Here is an app to allow logging in via twitter, facebook, openid, yahoo, google, which should work transparently with Django authentication system. (@login_required, User and other infrastructure work as expected.) Demo and Code.Longer version follow:


We are releasing our new app. Django-Socialauth. This app makes it awfully easy, to allow users to login your site using Yahoo/Google/Twitter/Facebook/Openid. A demo is available here.

This is released under an Attribution Assurance License. A copy of the same is provided included with the code.

After installing this app, you can use @login_required on any view and users identified via any means can access protected content.


We provide services to integrate and implement this, for a low price of USD 1600. Please contact us at licenses@uswaretech.com to discuss your exact needs.


The README is copied here for convenience.

What it does.

Allow logging in via various providers.

Logging In

This is a application to enable authentication via various third party sites. In particular it allows logging in via

  1. Twitter
  2. Gmail
  3. Facebook
  4. Yahoo(Essentially openid)
  5. OpenId

Libs you need to install

  1. python-openid (easy_install)
  2. python-yadis (easy_install)
  3. python-oauth(easy_install)

The API Keys are available from

How it works.

Openid: Users need to provide their openid providers. Talk to the providers and login.
Yahoo: Yahoo is an openid provider. Talk to Yahoo endpoints. (Endpoint: http://yahoo.com)
Google: Google is a provider. Talk to them. (Endpoint: https://www.google.com/accounts/o8/id)
Facebook: Facebook connect provides authentication framework.
Twitter: We use Twitter Oauth for authentication. In theory, Oauth shouldn’t be used for authentication. (It is an autorisation framework, not an authentication one), In practice it works pretty well. Once you have an access_token, and a name, essentially authenticated.

References

  1. Demo of app
  2. Code for app
  3. http://openid.net/developers/
  4. http://developer.yahoo.com/openid/
  5. http://code.google.com/apis/accounts/docs/OpenID.html
  6. http://apiwiki.twitter.com/OAuth-FAQ
  7. http://developers.facebook.com/connect.php

Below the hoods

  1. For all providers(except Facebook) there are two urls and views. (start and done)
  2. Start sets up the required tokens, and redirects and hands off to the correct provider.
  3. Provider handles authentication on their ends, and hands off to Us, providing authorization tokens.
  4. In done, we check if the user with these details already exists, if yes, we log them in. Otherwise we create a new user, and log them in.

For all of these, we use standard django authenication system, with custom auth_backends, hence all existing views, and decorators as login_required will work as expected.

Urls

/login/ Login page. Has all the login options  
/openid_login/ AND /openid_login/done/  
/yahoo_login/ AND /yahoo_login/done/  
/gmail_login/ AND /gmail_login/done/  
/twitter_login/ AND /twitter_login/done/  
/facebook_login/done/ We dont have a start url here, as the starting tokens are  
set in a popup, as per FB Connect recommendations.

Implementation

  1. Install required libraries.
  2. Get tokens and populate in localsettings.py
  3. Set the token callback urls correctly at Twitter and Facebook.
  4. Add the OpenId middleware. Set the Authentication backends. (Set in localsettings.example.py)

Related posts:

  1. Develop Twitter API application in django and deploy on Google App Engine
  2. How to build a Facebook app in Django
  3. Parable of the single sheep – Or How Google is destroying the internet, and nobody seems to know.
  4. Yahoo BOSS python api
  5. New tutorial – Building a search engine with Appengine and Yahoo

1 Comment 82 Tweets 23 Comments

{ 19 trackbacks }

Django-SocialAuth – Login via twitter, facebook, openid, yahoo … « Blogging
August 27, 2009 at 6:48 am
Django-SocialAuth – Login via twitter, facebook, openid, yahoo, google using a single app. — The Uswaretech Blog – Django Web Development « Netcrema – creme de la social news via digg + delicious + stumpleupon + reddit
August 27, 2009 at 7:46 am
pligg.com
August 27, 2009 at 7:57 am
29 fresh design, seo, dev and tech related links to tutorials and blogs of all kind =) « Adrian Zyzik’s Weblog
August 27, 2009 at 8:48 am
Social Milestone » Blog Archive » Django-SocialAuth – Login via twitter, facebook, openid, yahoo …
August 27, 2009 at 10:02 am
Django-SocialAuth – Login via twitter, facebook, openid, yahoo, google using a single app. — The Uswaretech Blog – Django Web Development
August 27, 2009 at 1:35 pm
links for 2009-08-27 .:: [aka щямукюшт] Ozver.in | Озверин
August 27, 2009 at 10:03 pm
The Abarentos Narrative » links for 2009-08-28
August 28, 2009 at 6:01 pm
Daily Digest for August 28th | William Stearns
August 28, 2009 at 10:19 pm
Delicious Bookmarks (2009-09-02 – 2009-09-08) | Josh Babetski : Quixotic Bravado
September 8, 2009 at 12:02 am
links for 2009-09-09 « Gatunogatuno’s Weblog
September 9, 2009 at 4:08 am
Josh Mather » Bookmarks for August 18th through September 14th
September 14, 2009 at 5:25 pm
@TheKeyboard » Blog Archive » Chris’ Brain – Almost October 2009 Edition
September 24, 2009 at 3:56 pm
Django-SocialAuth « …got brain?
October 26, 2009 at 9:02 am
Django Tools and Links « streamhacker.com
February 14, 2010 at 11:41 am
Generic Discussion – Multiple Login Library - xBlurb
May 26, 2010 at 7:52 am
Django 1.2 on App Engine with 3rd party libraries | Pycruft Blog
May 28, 2010 at 5:04 pm
Maybe defecting back to Google’s AppEngine Django Helper | Pycruft Blog
June 3, 2010 at 4:14 pm
App Engine User handling on Django Nonrel | Pycruft Blog
June 8, 2010 at 5:48 am

{ 125 comments… read them below or add one }

1 shabda August 27, 2009 at 1:16 pm

Yes, these are just exposed as authentication_backends, any existing ones will work alongside.

This comment was originally posted on Hacker News

4 nuggien August 27, 2009 at 1:51 pm

You’re setting the base path wrong for xd_receiver.htm would be my guess. FB connect is redirecting to http://socialauth.uswaretech.net/accounts/login/?next=/../xd…;

This comment was originally posted on Hacker News

7 ricree August 27, 2009 at 3:10 pm

Depending on what you want it for, I’ve had good experiences with django-authopenid ( bitbucket.org/benoitc/django-authopenid ).It doesn’t have the facebook or twitter, but it does work well with most openid providers (google, yahoo, etc). Plus, it lets users go ahead and just create a normal login if they don’t want to use openid.

There’s an example at openid-example.e-engura.org if you’re interested.

This comment was originally posted on Hacker News

10 farmerbuzz August 27, 2009 at 7:17 pm

Chrome/IE8 actually do a reasonable job of addressing this by greying out everything but the domain in the address bar. Its something I’d like to see in FF — if anyone knows of an add-on to do this let me know.

This comment was originally posted on Hacker News

11 yish August 27, 2009 at 8:48 pm

One challenge I have with all these logins options is that it becomes hard to remember which provider you logged in with. We have an issue already with Facebook connect and standard Django auth of duplicate accounts for a single user being created. Often times merging these can be rough. Has anyone come up with an elegant solution to this problem?

This comment was originally posted on Hacker News

12 shabda August 27, 2009 at 9:41 pm

Pretty closely integrated, as I wanted a seamless experience as close to normal django auth in part. But talking to providers is generic. Let me know if you would need my help porting this to Pytlons.

This comment was originally posted on Hacker News

18 scotth August 28, 2009 at 10:13 am

Locationbar²!https://addons.mozilla.org/en-US/firefox/addon/4014

This comment was originally posted on Hacker News

24 plisk September 8, 2009 at 1:53 am

Nice, thank you..

This comment was originally posted on Reddit

Leave a Comment

Additional comments powered by BackType

Previous post:

Next post: