Search code examples
c#asp.net-mvc-3oauthtwitter-oauthtwitterizer

Twitter OAuth doesn't redirect back to my web site properly


Disclaimer: I'm still starting out with MVC3 (and OAuth in particular). I might be making a basic mistake.

The Problem

My Controller sees that the cookie isn't stored [Note: yes, I'm using cookies per a different discussion. Let's accept that and move on.] and directs me to Twitter. Great. However, when I click authorize, I come right back to Twitter's authorization page.

My Hunch So Far

It seems that my app isn't correctly handling the Twitter postback/callback to my page.

The Ingredients

  • ASP.NET MVC 3
  • Twitterizer library
  • C#

The General Idea / Logic Flow

There might be an issue with this, as this is my first go-round with MVC3 and OAuth.

http://i56.tinypic.com/2rxchw7.png

The Code

I'm hesitant to post it at first because I want to make sure my perception of how this should flow is correct, and because there's understandably a little bit of it to dig through.

Thanks in advance for any help you can give!


Solution

  • I am not 100% sure since I am not a Twitter API pro. But I think Twitter disallows localhost as callback. And it may be that they do a lookup that an URL resolves before allowing a redirect to take place. They wont be able to reach something specified in your .hosts file.

    Consider simply issuing oauth_callback to a live URL, preferably one you yourself control. Check that you end up there. Then you can work out how to get hold of the oauth_token and oauth_verifier. (pro-tip: scrape the URL, or if you can, have the page print the variables on screen for easier scraping).

    Also test specifying "oob" as callback, see what happens.

    EDIT: I just realized that scraping the URL wont work since you are doing a web application. Sorry. But how about having a live URL take the oauth_token and oauth_verifier and from that page redirect to localhost or whatever?