Results 1 to 2 of 2

Thread: How to presist request token for access on callback page using for Twitter

  1. #1
    Join Date
    Mar 2012

    Question How to presist request token for access on callback page using for Twitter

    I am new to using the Spring.NET Social Framework DLLs.
    I downloaded the 1.0.0 package and from a test ASP.NET application using .net framework 2.0.

    I am having difficulties utilizing the call-back technique for getting authorization for my Twitter application to access a test twitter account I created.

    When utilizing the DLLs, following the example in documentation, I am unable to figure out how to persist the original oAuthToken request token that is generated in the 1st step of the authentication process and passed to FetchRequestToken() method:

    oTwitterProvider = New Spring.Social.Twitter.Connect.TwitterServiceProvid er(TwitterConsumerKey, TwitterConsumerSecret)
    oRequestToken = oTwitterProvider.OAuthOperations.FetchRequestToken ("", Nothing)
    UserAuthenticationURL = oTwitterProvider.OAuthOperations.BuildAuthorizeUrl (oRequestToken.Value, Nothing)
    Response.Redirect(UserAuthenticationURL, True)

    The above step works, user redirects to Twitter, authorizes the app, and then gets redirected to MyCallbackPage.aspx with appropriate oauth_token and oauth_verifie query string variables.

    On callback page:

    oTwitterProvider = New Spring.Social.Twitter.Connect.TwitterServiceProvid er(TwitterConsumerKey, TwitterConsumerSecret)
    oAuthorizedRequestToken = New Spring.Social.OAuth1.AuthorizedRequestToken(oRequestToken, Request.QueryString("oauth_token").ToString)
    oAccessToken = oTwitterProvider.OAuthOperations.ExchangeForAccess Token(oAuthorizedRequestToken, Nothing)

    Problem is that the MyCallbackPage.aspx page needs to refrence the original oRequestToken so that it can use in the Spring.Social.OAuth1.AuthorizedRequestToken() to get the authorized request token. Since the ASP.NET page is state-less, the original oRequestToken doesn't exists any more by the time user is redirected back to my ASP.NET application from twitter. Is there a way to recreate it, somehow save its value/secret in database and recreate it on the call-back page? The example given in documentation seems to suggest that somehow the callback page maintains the reference to original request token, but how is it done? Using a session variable to store entire object? Is there any way to do this without using session state, my application doesn't use any session state.

    Thank you I appreciate any hints.

  2. #2
    Join Date
    Mar 2012

    Lightbulb problem addressed using binary serialization

    Hello, I figured out the answer to my own question. It might be useful to others.
    Thankfully, the entire original request token object (the Spring.Social.OAuth1.OAuthToken) can be serialized into an array of bytes using System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter and then written into a a database field of type varbinay() for future reference. When at some point user gets redirected from Twitter to callback URL, the callback aspx page can reload/recreate the original token object from database (based on token value string in oauth_token query string variable) and complete the exchange of request token for access token.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts