Thursday, March 25, 2010

Twitter OAuth Login - Part 1

You must have noticed that lately a lot of sites have started to use login via Twitter and you migt already have used a screen like the following,



So that's what we will be discussing today, that's how to integrate Twitter login.

Why should we go for login via Twitter (or for that matter any other service like FaceBook)?

Login using a popular third party website is a good option both for the site and the user. User wouldn't have to go through the pain of entering all the sign up details and thus site wouldn't loose a user just because he was too lazy to fill in the sign up information. But offcourse no user wouldn't want to give their Twitter login credentials to just about any site who may end up storing your details in their database and misuse it or their database get hacked. Twitter understands it and therefore supports OAuth.

So what's OAuth and how does this address this issue?
If you're storing protected data on your users' behalf, they shouldn't be spreading their passwords around the web to get access to it. Use OAuth to give your users access to their data while protecting their account credentials.
If you want to understand the A-Z of how OAuth works, go here : http://www.oauth.net/core/1.0/

Let me give you a short summary in plain English. In order to understand how OAuth works, let's define two terminologies in terms of integrating Twitter login,

Consumer - This is the site which wants to integrate Twitter login.
Service provider - Twitter.

Here's the OAuth cycle.

1. Consumer sends a request token to Service provider.

2. Service provider grants a request token. This token is mainly to authorize the consumer using an id and secret key combination. It would be use to get Access token for user.

3. End user gets redirected to service provider's website.

4. User authorizes and gets redirected back to the consumer site

4. Consumer site requests service provider for a access token.

5. Service provider grants the token.

6. User is redirected to protected site pages.

So how could we integrate Twitter login to our website ?

Twitter is a good service but when it comes to API it's quite a pain mainly because it doesn't really have an official library, so you are left with two options: either to build one yourself or try to find a good an reliable library on the net. Twitter suggests some libraries but they aren't official. Secondly Twitter OAuth login is still a ...... beta! And beta services mean only one thing : they can change anytime! But as everybody is using it these days so I hope Twitter will not make any ground breaking changes.

So this post was to give you all the introduction. In next post we will be discussing the actual integration.

1. Part 2
2. Part 3

No comments:

Post a Comment