0

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

Jonty Morris
  • 797
  • 1
  • 10
  • 25
  • The use of async functions in all the APIs led me to switch to raw HTTP get, put and post calls, which seems to be much less complicated. – droopsnoot Aug 13 '20 at 08:33
  • After much frustration I learnt you cannot use .Result or .Wait() on the Xero-NetStandard library as it creates a deadlock. I was forced to refactor my legacy code base to be asynchronous and use await on all the methods. – Jonty Morris Aug 31 '20 at 08:44

1 Answers1

1

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

SerKnight
  • 2,502
  • 1
  • 16
  • 18