Tuesday, 22nd January, 2008

Using Yahoo BBAuth with Django

Category: Yahoo , Python , Django

Today I tried Yahoo's Browser based authentication service.

Yahoo BBAuth also offers a Single Sign-On (SSO) facility so that existing Yahoo! users can use your services without having to complete yet another registration process.

To enable Yahoo SSO in your application all you need to do is register your application, download this quick start package and integrate it with your application.

I tried integrating with Django and it was pretty easy.

Download Yahoo BBAuth python classes here

Extract ybrowserauth.py in your django project directory

Create a bbauth_config.py file into your root project directory

Add the following lines, replacing it with your appid and secret

# Put your Application ID and Secret hereAPPID = ‘5KzQuKHIkxxxxxxxxxxxxxxxxxxSztLwiAF7SECRET = ‘0e68e582xxxxxxxxxxxxxxxxxxxx0f25f4

In your views.py file add the following import statement.

from mysite import ybrowserauth, bbauth_config

Now assuming that I want to protect my photos view with YAHOO BBAuth I will add the following code in my photos view


def photos(self, ts, sig, token, userhas, appdata)# Instantiate the class    cptr = ybrowserauth.YBrowserAuth(APPID, SECRET, ts, sig, token, userhash, appdata)    if token == None: # If no token is found, create the authentication URL and display it      req.content_type = "text/html"      outstuff = cptr.getAuthURL('someappdata', 1)      from django.http import HttpResponseRedirect        #this will redirect to YAHOO login page       return HttpResponseRedirect(outstuff)    else:      # If a token is found, it must be Yahoo!'s bbauth coming back as the      # "success" URL. So, we validate the signature and do all the work      request_uri = req.parsed_uri[6]+ '?' + req.parsed_uri[7]      cptr.validate_sig(ts, sig, request_uri)      userhash = cptr.userhash      appdata = cptr.appdata      cookie = cptr.cookie      token = cptr.token      wssid = cptr.wssid      # Your photos view definition goes follows

Use example bbatestMAIL.py and bbatestPHOTOS.py file that comes with the sample code


A php example can be found at Dan's Blog


Posted by Amaltas Bohra at 11:06 a.m.

23 comments »

Love was the only one who stayed. Love wanted to hold out until the last possible moment.

When the island had almost sunk, Love decided to ask for help.

Richness was passing by Love in a grand boat. Love said,

"Richness, can you take me with you?"

Cheap Beats by Dr Dre says : 3rd January, 2012

To change the world
Through every life you touched.
You sparked the creativity
In the students whom you taught,
And helped them strive for goals
That could not be bought,
You are such a special teacher
That no words can truly tell
However much you're valued
For the work you do so well.

Red bottom shoes says : 2nd January, 2012

Customization of Jackets are started to give wearer an exclusive fit. You can design your own shirt considering the comfort level.

Moncler down jackets says : 6th December, 2011

dealer looks after like Tag Heuer, Cartier or Omega are throughout the world renowned for his / her exceptional qualities, too as for his / her really outstanding cost tag. circular the years

Chritmas gift canada goose says : 1st December, 2011

They are always in experimenting mood with their wardrobes to look awesome and unique. After all who don’t want to look good?

Canada Goose outlet says : 29th November, 2011

The real truth that the number of them purchased great signature purse does not imply its a wonderful item of work, but at situations it does imply that individuals will give considered to it to become one and consequently most maybe obtain it

cheap Beats by Dr Dre says : 21st November, 2011

If you recently received an invitation to a wedding that read "formal attire requested," and it left you scratching your head in wonderment, don't worry. In today's typically casual world, it can be difficult to determine what counts as "formal" and what doesn't.

new winter gife of the canada goose says : 11th November, 2011

.To complete the Four-In-Hand-Place the tie around the back of your neck with the skinny end hanging on one shoulder and the thicker end on the other shoulder. Make sure the underside of the tie, the side with the label, is facing your shirt and not the outside world.Slide the tie to adjust the length of the skinny end by making it longer or shorter, depending on the size of your neck.

authentic canada goose parka says : 11th November, 2011

First off, let me say that I've owned several Military Issue A-2 Bomber Jackets, so I have a pretty good idea of how this compares the original. The color is very close, if not, slightly darker than some of the originals out there (Avirex, Cooper, etc..). The best way to describe it is that it's 'chocolate' in color. Pretty dark, but nice. The sewing is tight and the leather seems to be nice quality as well. I have no idea what others were saying about the leather being thin. This is not thin for an A-2 Jacket, and actually thicker than the first original horsehide A-2 that I owned.

discount canada goose parka says : 7th November, 2011

Comfortable, soft and warm this Solaris Parka is. The color is wonderful for the coming Christmas and New Year! Also the pice is reasonable one.

discount canada goose parka says : 5th November, 2011

top quality product that is certainly certainly not been recently suited for a new hockey footwear ahead of.

cheap canada goose parka says : 4th November, 2011

To view a range of fashionable footwear including the latest El Naturalista collection, visit the Sarenza website.

discount canada goose parka says : 3rd November, 2011

I just received my chilliwack parka by post having ordered it online. I thought that I had researched my size correctly (42 Europe) but the medium is a bit snug, therefore my advice is not to buy it online and try it on before you purchase it. also remember it is very waisted so if it is very cold your legs will feel it. finally for this price i'm not convinced it is good value.

b says : 2nd November, 2011

The reasoning is simple, different styles are designed to fit certain body types and achieve different looks. An extreme example of this is the skinny jean, designed for men of with a slight build interested in a trendy look. Lesser known, but with a wider appeal

nice canada goose parka says : 1st November, 2011

i help maintain the fitness level of 6 high level dressage horses in the winter. there is lots of standing around outside or in barns. this coat has made the work so much more tolerable. i am so toasty now. my only regret, is that i didn't buy it earlier in the season

nice canada goose parka says : 27th October, 2011

If I'm not instrested in BBAuth ,Is there any way to access Yahoo ,alike Client Login in Google .

Ganesh says : 8th June, 2009

I need an BBAUtH SUCCESS URL (ex. httpp://domain.com/path/to/web/app')

Gina says : 23rd February, 2009

You are right. BBAuth only returns a hash, which can be used to identify a returning user. But this is more then Google at the moment offers. Sad but true. And so I have to stick to Google ClientLogin so far. At least for the development phase of my project.

Oliver Andrich says : 30th January, 2008

The problem with Google Auth is, that using AuthSub (preferable over ClientLogin) can be used for simple webpages, but you can't use the Google ID for storing data in your web application. In contrast Yahoo supports the retrieval of the user id. But hopefully Google will add this too.\r
\r
And thanks for the Yahoo! code :)

Oliver Andrich says : 29th January, 2008

AFAIK, Yahoo do not give user id, but just give user hash which is unique to each user. There is no way to get the actual user ID, correct me if I am wrong.

Amaltas says : 29th January, 2008

have you tried integrating Google Auth in django apps ? or can you write about it ?

json says : 23rd January, 2008

Excellent Start! Good Luck....

Syed Abbas says : 23rd January, 2008

@json
\rI haven't tried Google Auth API yet. You can find detailed documentation at Google Auth for web applications.

Amaltas says : 23rd January, 2008

Have your say

Name

Spam is a pain. If you are posting comment on this site for the first time, we will send you an email to activate the comment. Once you activate the comment, you can post comments without activation. This is one time activity.

Email (not published)

Blog/Website URL

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>