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;
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!