1

I'm using Octokit to authenticate a user from my app. I'm successfully getting the Code and State parameters back from Github. But when I try to create an access token, it throws an exception. What am i doing wrong?

Here is the code in my Authorize function -

    public async Task<ActionResult> Authorize(string code, string state)
    {
       var req = new OauthTokenRequest(clientId, clientSecret, code);
       var token = await client.Oauth.CreateAccessToken(req);
       Session["OAuthToken"] = token.AccessToken;
    }

I get a very generic error - "An error occured with this API request".

RJP
  • 385
  • 5
  • 19

1 Answers1

0

Start adding an exception handling in order to get more information from the exception (at least to catch Octokit.ApiException):

try
{
    var req = new OauthTokenRequest(clientId, clientSecret, code);
    var token = await client.Oauth.CreateAccessToken(req);
    Session["OAuthToken"] = token.AccessToken;
}
catch (Octokit.ApiException ex)
{
    Console.WriteLine(ex.ApiError.Message);
    foreach(var error in ex.ApiError.Errors)
    {
        Console.WriteLine(error.Message);
    }
}
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250