How to use OAuth Authentication For Twitter Applications

by Naveen 14. June 2010 03:28

Its been long since I updated my existing Twitter applications. Recently one of my clients told me that Twitter is not going to support basic authentication at the end of this month, so I decided to get back to my handy console application that I use to test my objects. This post will provide you some details on how to use OAuth in Twitter applications.

OAuth Authentication

Twitter API team has done excellent job of explaining how OAuth mechanism work. The following link will provide you more details on Twitter OAuth request-response mechanism.

OAuth Authentication Mechanism

This post demostrates how you can implement OAuth authentication in a desktop application. Yes, the underlying mechanism for exchange of request and access tokens in same in web or desktop applications. But the big difference is notification of authorization from the user who is using your application.

In case of web applications you register a callback URL with twitter where you get notified if user has accepted to allow your application to access their account or not. But in case of desktop applications, this is not the case because you have no callback URL. So you rely on one manaual step by the user of the application to enter the PIN provided by twitter when they accept your application. The basic steps involved in authntication and authorization are:

  • During authentication process, your application launches web browser on user's machine.
  • User is taken to twitter authentication page
  • User will be presented with login screen (if they are not already logged into their twitter account).

    twitter login

  • User will log in and after successful login, they are presented with screen with a PIN number on it.

    twitter oauth pin

  • You will need to ask your users to provide your application with that PIN number
  • Once PIN has been confirmed, Twitter provides you will that user's access token. You can serialize that access toekn to save it for future use. Otherwise you will have to get your user to goto Twitter site to get new PIN verytime which can be very annoying.

Sample Project For Twitter OAuth Authentication

I have been using Tweetsharp opensource library for quite some time for all my Twitter needs and I am continuing with that. I have included required binaries in BIN folder of the project. You will need to add consumerkey, consumersecret and test twitter account name in app.settings file of the project. Without consumekey and consumersecret information, Twitter application will not be able to recoganize your requests and you will get HTTP errors.

 

Views: 5621

Tags:

blog comments powered by Disqus

Smart Phones Poll

What smart phone do you currently own?





Show Results

Month List

Powered by BlogEngine.NET 2.0.0.49
Theme by Naveen Kohli