This project has moved and is read-only. For the latest updates, please go here.

How do I hijack the callback url BEFORE I redirect to the SP?

Aug 7, 2009 at 3:02 AM
Edited Aug 7, 2009 at 3:03 AM

Hi folks,

I wish to hijack the callback url of my application before I redirect to the SP to authenticate. The reason is because Twitter doesn't allow me to put the following url in the callback url: http://localhost:6969

As such, could someone explain how I could/would do this?

Here's some sample code to help explain what I'm trying to do.... (Also, this is not my ugly code, so please forgive the crap)

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;

Cheers :)

Aug 7, 2009 at 2:54 PM

Hi Pure.Krome.  Have we exchanged messages on StackOverflow?

So first let's talk about your original problem.  Twitter doesn't accept 'localhost'?  In my test yesterday this worked fine.  Twitter doesn't accept 'localhost' in the callback that you register with them at, but it does seem to accept it and behave correctly if you pass localhost from your actual web app, and it works fine from my dev box.  Have you tried putting a regular URL into /oauth_clients and then allowing localhost to go in from linq2twitter?

If that doesn't work, we should explore why, since it works for me.  But I'm also curious what you would put instead of localhost, since anything else wouldn't complete the OAuth flow and you wouldn't regain control after sending the user to Twitter.  "oob" perhaps?

Finally, if you really want to customize the callback parameter, you'd have to modify the LinqToTwitter.WebOAuthAuthorization class's BeginAuthorization method to call the overload that takes a customized callback parameter.


        public void BeginAuthorize()

        public void BeginAuthorize()


            this.Consumer.Channel.Send(this.Consumer.PrepareRequestUserAuthorization(new Uri("someUri"), null, null));



Aug 7, 2009 at 3:13 PM

:) yep, we did. I wasn't sure if it was an issue with twitter OR OAuth or linq-to-twitter. Once you confirmed my thoughts (it's an issue with L-to-T), I jumped on here because I thought I'd get an answer, quicker :) I knew u're on SA .. but I'm not sure about this krew...

Which .... is exactly what you have answered in the second part of your post, above. To elaborate on your answer, where is the WebOAuthAuthorization class used? I was wondering if the TwitterContext should be modified by adding a property which is the CallbackUri, which can be set before the client is redirected. But you're suggesting otherwise .. which is great .. but i'm not sure where this is getting used .. especially in relation to my sample code, 2 posts above.


Aug 8, 2009 at 1:18 AM

So if you're getting redirected to a coworkers computer (from your StackOverflow comment), I'd say that you're probably on a special network, or behind a firewall or NAT box, or something, such that your public-facing IP address and/or port are not readily detectable by DNOA.  I suggest you turn on logging and see what the callback URL is that is being sent to Twitter (it's in the initial request for an unauthorized request token).  Once you see what the callback URL actually is that's being sent to Twitter you can try it in your own browser to see where it takes you.  If it's to the wrong place, then DNOA is auto-detecting the wrong callback URL.  If it's the right place, then Twitter is probably screwing it up somehow.

If DNOA's auto-detection is wrong, there are a few things we can do to correct it.  But let's start with the investigation I suggest above, and if you could please send me the callback URL that L2T sends to Twitter, and the callback URL you want it to send, we can figure out what to do next.

Aug 11, 2009 at 2:16 AM
Edited Aug 11, 2009 at 2:17 AM

Hi Aarnot,

ok. This is embarassing, but I've finally got it working .. sorta :( It took me ages, but i can now log stuff to the visual studio DEBUGGER OUTPUT window. That said, there is no data coming from the DotNetOpenAuth log stuff.

EDIT: the only data i'm seeing, is any data when i manually add a line to log stuff .. eg. log.Info("blah");

here's my xml config data...

        <appender name="TraceAppender" type="log4net.Appender.TraceAppender">
            <layout type="log4net.Layout.PatternLayout">
                <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />

        <!-- Setup the root category, add the appenders and set the default level -->
            <level value="ALL" />
            <appender-ref ref="TraceAppender" />
        <!-- Specify the level for some specific categories -->
        <logger name="DotNetOpenAuth">
            <level value="ALL" />



(PS. i tried using a file .. which it created but contained no data .. go figure)...

So to confirm, twitter is always returning to the url which is put into the CallbackUri defined in their website.

Aug 11, 2009 at 3:38 AM

My gosh, there's something strange going on for your web site.  Logging should work with the .config file you have, and Twitter should be using your current callback rather than its preconfigured one, based on my experience.  

Can you confirm the version of log4net.dll that you're using?  (It should be exactly in order to work with DotNetOpenAuth messages).

Beyond that, I wonder if you'd consider sending me a Remote Assistance request so we can share your desktop and see what's going on.