2

I'm using Twitterizer library with my website project. In our website we are using the Login in with Twitter button. The problem we have that on some computers it keeps directing the user to Twitter and ask him to authenticate and allow the application to interact. How can I stop that if the user has already authenticated our application from before?

This is the code I'm using to the button:

string callbackUrl = string.Concat(Request.Url.GetLeftPart(UriPartial.Authority), "/Callback.aspx");

        if (Request.UrlReferrer != null)
        {
            callbackUrl = string.Format("{0}?sendto={1}", callbackUrl, HttpUtility.UrlEncode(Request.UrlReferrer.AbsoluteUri));
        }
        OAuthTokenResponse requestTokenResponse = OAuthUtility.GetRequestToken(
            ConfigurationManager.AppSettings["Twitter.ConsumerKey"],
            ConfigurationManager.AppSettings["Twitter.ConsumerSecret"],
            callbackUrl);

        string authUrl = OAuthUtility.BuildAuthorizationUri(requestTokenResponse.Token,true).AbsoluteUri;
        Response.Redirect(authUrl);

Solved it by changing the authUrl to the following:

string authUrl = "https://api.twitter.com/oauth/authenticate?oauth_token=" + requestTokenResponse.Token;
Laila
  • 417
  • 1
  • 3
  • 14

1 Answers1

3

I don't believe there is a way to stop asking the user to authenticate themselves through Twitter. From previous experience using the SocialAuth.NET, Twitterizer and OAuth route, I've always experienced the authentication page and so have others in this discussion.

Update

This post should help you: https://stackoverflow.com/a/9910051/1300806.

I just tried using the approach stated in the post and I managed to get my Twitter implementation (using OAuth) working so that the user doesn't have to continuously give permission.

You learn something new everyday!

Community
  • 1
  • 1
SurinderBhomra
  • 2,169
  • 2
  • 24
  • 49
  • Well, is there any other way to do it without using the libraries that you mentioned like Twitterizer and others? because I think there must be a way. When I use different websites with the Login with Twitter button it directs me immediately to their website without the need to go to the authentication screen everytime. – Laila Oct 06 '12 at 07:14
  • @LailaAlshahed I have just updated my post with a solution. This could work for you. – SurinderBhomra Oct 10 '12 at 10:37
  • Thanks a lot, this is working with me very well till now. I just need to make sure it's working with all the users now. – Laila Oct 14 '12 at 07:10