Twitter xAuth with .NET
Twitter is shooting for a mid-2010 shutdown of Basic Auth for its API. That means that all the little scripts that we threw together over the years, just for fun, will no longer work. It also means that you will no longer be able to test an API call by simply pulling up your browser. Honestly, I’ll miss Basic Auth. I think the easy approach encouraged a lot of innovation, but it’s time to move on. Some folks have been dragging their feet, understandably, because there wasn’t a good oAuth solution for the desktop. With the release of the xAuth standard, however, there aren’t going to be any more excuses.
xAuth is a compromise. The user must provide a Twitter username and password to the desktop application. The desktop app will then contact Twitter and exchange the username and password for an oAuth token. All subsequent calls to the API should use the oAuth token, and the app must never store the user’s username and password.
You might be saying to yourself, “But a bad app can still grab the username and password” — and you’d be absolutely right, but that type of discussion is beyond this post, I just want to show you how to use xAuth.
I modified the code from my previous PIN-based desktop application example. Make sure you keep track of the token and secret that Twitter returns and save that in a datastore. A user should only need to provide their username and password in two scenarios, when they first begin using your app, or if they later revoke access for your app.
The xAuth access_token method is described here: http://apiwiki.twitter.com/Twitter-REST-API-Method:-oauth-access_token-for-xAuth
Please note the following requirement: “In order to get access to this method, you must apply by sending an email to api@twitter.com.”
Twitter is serious about ensuring that this method is only used for desktop apps. They will reject your application if it looks like it could possibly use standard oAuth.
Good luck with your conversions. Feel free to leave any xAuth issues you run into in the comments section.
Reference Lookup: Dictionary, Thesaurus, Encyclopedia, & More
powered by PostRef