RequestCredentialsParameters.FromCallbackUrlAsync error when no oauth_verifier returned
See original GitHub issueWhen authenticating a Twitter app, if the user selects “Cancel” instead of “Authorize App” a “denied” parameter is sent back and no “oauth_token” which causes an error in RequestCredentialsParameters.FromCallBackURLAsync.
ERROR: “System.ArgumentException: oauth_verifier query parameter not found, this is required to authenticate the user Parameter name: callbackUrl”
public async Task<ActionResult> TwitterUserAuthCallbackAsync()
{
var appClient = new TwitterClient(TWITTER_API_KEY, TWITTER_API_SECRET);
string q = Request.QueryString.ToString();
// Extract the information from the redirection url
var requestParameters = await RequestCredentialsParameters.FromCallbackUrlAsync(q, _myAuthRequestStore);
// Request Twitter to generate the credentials.
var userCreds = await appClient.Auth.RequestCredentialsAsync(requestParameters);
var userClient = new TwitterClient(userCreds);
var user = await userClient.Users.GetAuthenticatedUserAsync();
}
Steps to recreate: Send request to connect to Twitter. Instead of Authorize App button, click Cancel button and Twitter sends user to another page with “return to MyApp” button. The button has a Twitter generated return URL that looks like this. https://mydomain.com/TwitterUserAuthCallbackAsync?tweetinvi_auth_request_id=XXXXXXXXXXdenied=XXXXXX
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Version 5.0 Milestone
RequestCredentialsParameters.FromCallbackUrlAsync error when no oauth_verifier returned enhancement. #1081 opened on Nov 1, 2020 by redoc209.
Read more >C# (CSharp) TwitterClient Examples
Params.Get("oauth_verifier"); var authenticationRequestId = Request.Params.Get(TWITTER_AUTH_QUERY_PARAMETER); if (verifierCode == null) { return(View()); } ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That seems like a good solution.
So I have thought about it. I do think it makes sense for
RequestCredentialsParameters.FromCallbackUrlAsync
to throw an exception when providing invalid parameters. The reason is that a factory cannot create an object if you provide invalid parameters, it does make sense for a factory method to throw an InvalidParameterException.Though I do understand that you might not want to be aware of the cancellation via an exception. My current approach to this problem is that I will add a new method similar to
client.Auth.GetAuthenticationResult(string url)
.This would return an enum:
Let me know what you think