views:

877

answers:

5

I'm a bit confused about all this OAuth bruhaha in the sense that all the examples I can find are for web applications and none of them for desktop applications.

I understand the Web application work flow, but that includes some redirections between the web app and twitter.

  • How does one do this in an desktop application?
  • How does the redirects work?
  • Should I have to include a Web Browser object?
  • Is there a way to go around this?
  • Could anyone point me to resources instead of a full blown solution please?

Thanks

+3  A: 

Not sure which language you're using, but the .NET library for Twitter called Tweetsharp has a post on using Tweetsharp from a desktop app and authenticating via OAuth. See http://tweetsharp.com/?p=68. If you're not using .NET then perhaps it will inspire something you can do?

Basically, what tweetsharp does is launch the browser to the authentication URL and then waits for the user to return. I don't know of any way to do this other than something like that (Or include a WebBrowser control of some kind to launch the authentication URL in your own window).

Ryan Farley
Thanks mate, but that still involves going out of my way and wait for some external app. I need to contain it all in my App. It makes sense to have the login and password in your desktop app, hell, tell me of one that doesn't have... That really does not solve my problem, but thanks anyway.
Gustavo Carreno
Yeah, I understand. However, for OAuth in a desktop app, there is no other option. The whole point of OAuth is to *not* have your app ask for credentials.
Ryan Farley
A: 

After some poking around and asking some questions about this subject to some other programmers, it looks like it's still an ongoing discussion, with no visible light at the end of the tunnel.

But for people interested on the ongoing discussion, here's the best link to have:
OAuth Desktop Discussion

Gustavo Carreno
After my "conversation" with xoxo it looks like a possible answer can be better than mine. Will hold for xoxo to get some stuff up.
Gustavo Carreno
A: 

I've seen a few desktop apps get around this by effectively embedding a browser into their program, so they can just open the in-app browser window to let you do the login and authorisation. This strikes me as a bit of a cheat or defeat of purpose because you still end up typing your ID and password inside the application anyway.

One possibility I was thinking of was, your desktop application could embed a mini HTTP server inside it. So then it launches the default browser to perform the authorisation, with a callback URL something like http://127.0.0.1:8765/oauthorized and then just listen for it.

Would that work?

Not sure what you would do for console applications... spawn a copy of lynx?

Evan
The HTTP server could work. I'll have to look into the localhost issue that aroused earlier just to confirm that it's still possible. Thanks for that suggestion, looks interesting.
Gustavo Carreno
A: 
  1. Include a WebBrowser control in your app. Put it in a panel or a separate form that you'll Form.ShowDialog().
  2. Create a callback for the browser's successful posting of OAuth and one for a rejection. Don't forget to check for a FailWhale.
  3. In the callback, you close the panel or form and store the token.

Here's a nice overview with sample code and everything: http://tweetsharp.com/2009/04/how-to-authenticate-a-desktop-application-with-oauth/

Rap
A: 

Here's a straightforward solution, implemented as a set of PHP scripts for running from the command line. Well documented and explained, with a helpful 'verbose' option for debugging.

http://nullinfo.wordpress.com/oauth-twitter/

Gabe

related questions