views:

1040

answers:

2

Hi folks,

i'm trying to OAuth to Twitter and it then returns back to our localhost:port (eg. http://localhost:6969).

I'm also trying to use Linq2Twitter. When I try and setup my application in Twitter, it's not allowing me to set the

  1. Application Website.
  2. Website.
  3. Callback URL.

to be http://localhost:6969

So, how can i make twitter OAuth against my localhost development machine?

EDIT: I'm secretly hoping AArnott will find/read this post :)

EDIT 2:

Now that Andrew posted his thoughts, I'm adding some more info to get some more clarification of this reply.

So if this is the sample code (not mine btw, but some hire'd gun, here at work) to redirect to the SP (which is Twitter, in this case...)

public void StartOAuthAuthorize()
{
    string link = twitterContext.GetAuthorizationPageLink(false, false);
    var uri = new Uri(link);
    NameValueCollection urlParams = HttpUtility.ParseQueryString(uri.Query);
    OAuthToken = urlParams["oauth_token"];

    HttpContext.Current.Session["twitterService"] = this;
    HttpContext.Current.Response.Redirect(link);
}

This would be the place i would hijack the callback url.... ?

+1  A: 

The answer may surprise you...

Give Twitter any callback URI it permits (probably the URL you imagine using in production) for your oauth client registration page.

When you send your OAuth unauthorized token request, you have the option to provide a callback URL at that time, which Twitter will prefer to use instead. You can supply localhost at that time and it works perfectly.

Since you're using LinqToTwitter, which internally uses DotNetOpenAuth, there's no need to specify 'localhost' when you're issuing your request for authorization to the SP. DotNetOpenAuth automatically sees that you're on localhost and sends that callback URI.

Update: And be sure you're running the latest version of LinqToTwitter (at least changeset 56159... more recent than release v1.11). Otherwise you're using OAuth 1.0, and Twitter ignores the callback URL sent in the authorization request for OAuth 1.0 clients.

Andrew Arnott
So why does Twitter request the callback URL in it's settings page (as Twitter is a SP, in this case)? I've also provided some sample code (read: i've edited my initial post) to help explain my thinking .... which is ... Does my server code ask twitter for all the info BEFORE i redirect to it. This means twitter (or the SP) returns the default callback url. Then, before i bounce off to the SP, i change that callback url. Is this correct?
Pure.Krome
Before asking questions like this, some people would probably read the rather simple OAuth spec, where all such things become pretty obvious:http://oauth.net/core/1.0ahttp://oauth.net/core/1.0a#rfc.section.6.1.1
andrewbadera
@andrewbadera: bad day at work? shees....
Pure.Krome
Pure.Krome, I've updated my answer here (I also posted an answer on your cross-post to the linqtotwitter discussions page). Don't sweat the callback URL. It all happens automagically. Just give twitter.com/oauth_clients your public URL -- or any URL really -- for your callback URI and everything will just work, even if you're on localhost. DotNetOpenAuth (which LinqToTwitter uses) automatically handles sending the callback URI of 'localhost:port' to Twitter at the right time.
Andrew Arnott
Pure.Krome
Answer was what andrew said about the latest version -> needs to be after changeset 56159. Thanks heaps Andrew :)
Pure.Krome
A: 

I setup my oAuth to use http://example.site then created that site in Apache so I know exactly where it's going and there's no confusion with localhost, different ports etc

Tom