Search code examples
oauthtwitter-oauthtweetsharpoauthtwitterwrapper

TweetSharp works but requires app authentication every time user logs in


I have the authentication process working great with TweetSharp to log my users into my app. I then fetch and save the oauth_token and oauth_token_verifier on my system.

I have tried to use that same token/verifier combo to log the user back in which does prevent the necessity to have the user authorize the app again...however, I've noticed when I log in to twitter on the web, that token/verifier combination no longer is valid and so trying to log them in again doesn't work.

I dont' mind requesting a new token/verifier combo every time, but I dont' want to force my users to have to authorize the app every time. Is there a way around this?

here is the relevant code from my twitterloginhelper class:

LocalUser lsuser = new LocalUser();
        TwitterService service = new TwitterService(consumer_key, consumer_secret);
        OAuthAccessToken accessToken = service.GetAccessToken(requestToken, oauth_verifier);
        service.AuthenticateWith(accessToken.Token, accessToken.TokenSecret);
        TwitterUser user = service.VerifyCredentials(new VerifyCredentialsOptions());

        lsuser.oauth_token = oauth_token;
        lsuser.oauth_token_secret = oauth_verifier;
        lsuser.profile_pic = user.ProfileImageUrl;
        lsuser.login_type = "Twitter";
        lsuser.username = user.Name;
        lsuser.oauth_uid = user.Id.ToString();
        lsuser.email = "";
        return lsuser;
    }

Solution

  • got this figured out.

    once you have the requestToken, instead of calling TwitterService.GetAuthorizationUrl, call TwitterService.GetAuthenticationUrl.

    that will make it authorize the app only once, and each subsequent time, allow the user to just log in w/o re-authorizing.