Search code examples
c#asp.net-mvcoauth-2.0xero-api

Xero request access token is timing out


I'm trying to setup my old ASP.NET MVC app with Xero's latest OAuth 2.0 protocol. As per the documentation, I'm using the official Xero-NetStandard library.

I can successfully redirect the user to Xero's consent page, and also get redirected back to localhost with a valid-looking code as expected. However, problems arise when I try to retrieve the Access Token.

var xeroToken = _xeroClient.RequestAccessTokenAsync( code ).Result;

When this code is executed on my localhost environment, very little seems to happen. The request just gets stuck and won't continue past this point. The only occasional error I see is a 'request timeout' after quite a few minutes.

Please understand I have looked at all the references and examples I can find, but most of them either have specific Dotnet Core stuff, or are completely out of date (the Xero client seems to have changed quite a bit since they were created 5+ months ago).

Maybe I'm going crazy but this was working as expected a couple of months ago when I started work on our new Xero integration, but now I have no clue what's wrong 😢


Solution

  • It looks like that function requires being called in an async fashion:

    await client.RequestAccessTokenAsync(code);
    

    https://github.com/XeroAPI/Xero-NetStandard/blob/df9051feee2b49c0cdd3253bb6acafc4491869b5/Xero.NetStandard.OAuth2Client/src/Client/XeroClient.cs#L132