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

1 Comment 82 Tweets 23 Comments

{ 15 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

{ 120 comments… read them below or add one }

2 scorpion032 August 27, 2009 at 7:59 am

On one hand you don’t want to remember multiple passwords (on multiple sites) and on the other hand you don’t want to let people authenticate from your own trusted site.Most of the time, since you are already logged-in on Facebook google, yahoo or twitter, you will not be prompted for password, only for approval of authentication.

This comment was originally posted on Hacker News

7 flashingpumpkin August 27, 2009 at 8:20 am

Well, try the demo. The google login works with a mechanism on googles servers asking you explicitly to grant access to the referring site. If the user doesn’t check the address on the target … well … :/I’ve spotted another weakness though on the facebook login. The username’s are generated as facebook_$firstname, which will lead to duplicates on big sites quite fast. I’d like to see a mechanism asking the users to chose a username.

This comment was originally posted on Hacker News

8 flashingpumpkin August 27, 2009 at 8:20 am

Well, try the demo. The google login works with a mechanism on googles servers asking you explicitly to grant access to the referring site.

This comment was originally posted on Hacker News

9 jessep August 27, 2009 at 8:36 am

That’s pretty sweet! The demo worked well for me on everything but Facebook, where it reloaded the page within the facebook popup, a littttle odd. This is a great start, though, for developing services that integrate with the API’s of these services. Psyched to try it integrating it into an app.

This comment was originally posted on Hacker News

15 Steve0 August 27, 2009 at 8:57 am

I think this is a problem. Lot’s of users just type http://www.example.org in the google and click the first link. they hardly know what the address bar does.One way to look at it is: stupid user, you did it to yourself.

Another is: lots of people will be fooled, maybe we should rethink.

As I’ve said before, I have no solid solution.

This comment was originally posted on Hacker News

19 messel August 27, 2009 at 9:04 am

Wow I was looking for precisely this demo. Rockin’

This comment was originally posted on Hacker News

20 shabda August 27, 2009 at 9:05 am

Can you try it and let me know what address it shows in the popup bar? If you log a bug on github, we will definitely try to fix it.

This comment was originally posted on Hacker News

23 endlessvoid94 August 27, 2009 at 9:10 am

How integrated is this to Django? Would it be easy to adapt to other framework (I’m thinking of Pylons). I’m working on a little website and would love to add this functionality without switching to Django.

This comment was originally posted on Hacker News

24 kentf August 27, 2009 at 9:11 am

Let’s start working on one for Rails

This comment was originally posted on Hacker News

37 paulitex August 27, 2009 at 11:30 am

I’m already working on a similar authentication system for a rails app and this just really motivated me to release it as a plugin…That said, I’m sure lots of other Rails developers have already built their own solution. I’m also sure some are more mature than mine (i.e. in production). Isn’t uservoice.com backed by Rails? Their social authentication is so pretty Google uses it as a demo.

This comment was originally posted on Hacker News

38 paulitex August 27, 2009 at 11:30 am

I’m already working on a similar authentication system for a rails app and this just really motivated me to release it as a plugin…That said, I’m sure lots of other Rails developers have already built there own solution. I’m also sure they’re more mature than mine (i.e. in production). Isn’t uservoice.com backed by Rails? Their social authentication is so pretty Google uses it as a demo.

This comment was originally posted on Hacker News

44 coconutrandom August 27, 2009 at 12:43 pm

can you still login with django.contrib.auth?

This comment was originally posted on Hacker News

46 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

49 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

Leave a Comment

Additional comments powered by BackType

Previous post:

Next post: