Verifing Credentials question

Apr 28, 2014 at 4:02 PM
I'm having some issue authorizing twitter on the application of mine.

Here is what my authorization code looks like
        public Uri CreateOptInUrl(string redirectUri)
        {
            var applicationCredentials = CredentialsCreator.GenerateApplicationCredentials(Settings.ApiKey, Settings.ApiSecret);
            var url = CredentialsCreator.GetAuthorizationURLForCallback(applicationCredentials, redirectUri);

            return new Uri(url);
        }
the issue comes when I return to my application and my callback code fires:
        public IExternalApp HandleOptInResponse(HttpRequestBase request, string redirectUri)
        {
            try
            {
                IExternalApp app = new ExternalApp {ExternalAppType = ExternalAppType.Twitter};

                var data = request.Params;

                var applicationCredentials = CredentialsCreator.GenerateApplicationCredentials(Settings.ApiKey, Settings.ApiSecret);

                var verifyAuth = CredentialsCreator.GetCredentialsFromVerifierCode(data["oauth_verifier"], applicationCredentials);

                var usr = Tweetinvi.User.GetLoggedUser();
                app.Uid = usr.Id;
                app.Token = verifyAuth.AccessToken;
                app.TokenSecret = verifyAuth.AccessTokenSecret;
                app.Username = usr.ScreenName;
                app.Name = usr.Name;

                return app;
            }
            catch
            {
                return null;
            }
        }
verifyAuth come back as null which usr then is null.

I'm hoping someone can help me as I already tried another 3rd party client and this is starting to anger me.

Thanks.
Coordinator
Apr 28, 2014 at 4:43 PM
Hi,

I assume you are currently using tweetinvi from an ASP application.
If so, please read the following post: https://tweetinvi.codeplex.com/discussions/536895.
Use the solution marked as answer.

The problem comes from the fact that even static credentials are not shared between different sessions of ASP and consequently you lose the previous application credentials.
As Tweetinvi relies on these credentials to continue the sign in process you need to set them a second time.

I am here to help so please feel free to ask any question. I will answer at the end of my working day.

Regards,
Linvi
Apr 28, 2014 at 6:07 PM
Edited Apr 28, 2014 at 7:19 PM
I am using it on a asp.net MVC 5 project.

using sessions may be a hard thing to use as the twitter code is in another layer that is all business logic.
Coordinator
Apr 28, 2014 at 7:26 PM
Hi,

At some point, you need to store the credentials information somewhere. So that you ensure that your credentials are always up to date and not cleanup by a new session.

Linvi
Marked as answer by linvi on 4/29/2014 at 7:55 AM
Apr 29, 2014 at 1:22 PM
I did some looking and its possible my isue is that AuthorizationKey & AuthorizationSecret are null. did I miss a step?
Apr 29, 2014 at 1:39 PM
I see that I missed a step, once I can find a way to keep the one values in play, I'll report back.
Apr 29, 2014 at 2:10 PM
I got it working, the issue was I didn't setup the access token and access secret.
Coordinator
Apr 29, 2014 at 2:54 PM
Sorry for the time I took to reply, I am quite busy.
Thank you for your feedback. And please know that if you have any issue the forum is open and I will always reply.

Linvi