'Tweetinvi: Store and use authenticated user credentials later

I am using Tweetinvi to authenticate users by using ASP C# Web Api. To authenticate the user i use the following code (Using https://linvi.github.io/tweetinvi/dist/authentication/authentication-url-redirect.html as reference):

IAuthenticationRequestStore _myAuthRequestStore = new LocalAuthenticationRequestStore();
var appClient = new TwitterClient("consumer_key", "consumer_secret");
var authenticationRequestId = Guid.NewGuid().ToString();
var redirectPath = "https://apisite/api/v1/twittercallback";
var redirectURL = _myAuthRequestStore.AppendAuthenticationRequestIdToCallbackUrl(redirectPath, authenticationRequestId);
var authenticationRequestToken = await appClient.Auth.RequestAuthenticationUrlAsync(redirectURL);
await _myAuthRequestStore.AddAuthenticationTokenAsync(authenticationRequestId, authenticationRequestToken);

And use the authenticationRequestToken.AuthorizationURL to get the url i redirect the user to.

This part works fine but the issue ends up being when trying to authenticate the user on callback or in the future. I am storing the following in my database: authenticationRequestId , authenticationRequestToken.AuthorizationKey, authenticationRequestToken.AuthorizationSecret from the above code, and the oauth_token and oauth_secret sent by twitter as get parameters when redirecting to the callback url.

The issue is that i am unable to authenticate user on callback to send a tweet or get user info. It works it i make the variable IAuthenticationRequestStore _myAuthRequestStore = new LocalAuthenticationRequestStore(); as global and static (as in the linked example) but that is something that works temporary as whenever if the app is restarted or updated it looses whatever is stored in that.

I read some old solutionswhere it was mentioned to use Auth or AuthFlow but i am unable to find what needs to be included for the "Auth" or "AuthFlow.CreateCredentialsFromVerifierCode" variable.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source