Question

I have a web application in which any user if opt for social media automation such as twitter, they click on twitter button and a oauth procedure is done. That oauth process is done using php.

I store the oauth token and oauth secret for that particular user in the database.

Now I have four keys:

ConsumerKey // common for all as it is the key of app in dev.twitter.com
ConsumerSecret // common for all as it is the secret of app in dev.twitter.com
OauthToken //store in database, which keeps on changing as other user activates the socia media
OauthTokenSecret //store in database, which keeps on changing

I have applied all the authorizing technique like below:

 var auth = new MvcAuthorizer
            {
                Credentials = new InMemoryCredentials
                {
                    ConsumerKey = "###################",
                    ConsumerSecret = "##################",
                    OAuthToken = token,
                    AccessToken = secret
                }
            };
            auth.Authorize(); 


 var auth = new SingleUserAuthorizer
            {
                Credentials = new InMemoryCredentials
                {
                    ConsumerKey = "###############",
                    ConsumerSecret = "#############################",
                    OAuthToken = token,
                    AccessToken = secret
                }
            };
            auth.Authorize();

The problem is if I enter the Token and secret which is given on the site dev.twitter.com everything works fine but if I provide the token and secret stored in the database it does not authenticate the user.

Était-ce utile?

La solution

On SingleUserAuthorizer, don't call Authorize. Also, any time you provide all 4 credentials to any authorizer, you don't need to call Authoirize. LINQ to Twitter will use those credentials to build the authorization header.

The case where you would call authorize is if you only provided ConsumerKey and ConsumerSecret and the authorizer type is not SingleUserAuthorizer. Authorize implements the part of the OAuth protocol that gets the OAuthToken and AccessToken.

Your syntax for SingleUserAuthorizer should work, but here's another way that matches keys to how the Twitter app page names them:

        var auth = new SingleUserAuthorizer
        {
            Credentials = new SingleUserInMemoryCredentials
            {
                ConsumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"],
                ConsumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"],
                TwitterAccessToken = ConfigurationManager.AppSettings["twitterAccessToken"],
                TwitterAccessTokenSecret = ConfigurationManager.AppSettings["twitterAccessTokenSecret"]
            }
        };
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top