question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RequestCredentialsParameters.FromCallbackUrlAsync error when no oauth_verifier returned

See original GitHub issue

When 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:open
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
redoc209commented, Nov 16, 2020

That seems like a good solution.

0reactions
linvicommented, Nov 15, 2020

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:

enum AuthenticationResult 
{
    ApprovedByUser,
    CancelledByUser,
    NeverRequestedByApp
}

Let me know what you think

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found