Open mattpawson opened 2 years ago
@mattpawson just looking into WebApi2 and see that it can be run server-side or client-side. Can you please confirm which you are doing for your use case?
Hi @RettBehrens. I'm running it as a server side application. Basically, in this instance, the client facing web portal connects to a WebAPI2 API that then utilises the SDK to pull the account codes and which it then passes back to the client.
Hmm, my best guess was that it was an issue running from client-side but since we've ruled that out, do you have visibility into the inner exception messages? Can you post the stack trace?
There doesn't appear to be an inner exception:
Message: "An error occurred while sending the request."
Source: "Xero.NetStandard.OAuth2Client"
Stacktrace: " at Xero.NetStandard.OAuth2.Client.XeroClient.
@mattpawson if you're using an older .NET 4.x project you'll need to ensure that your requests are being sent using TLS 1.2.
Add this line to your startup configuration:
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
I had this exact issue and after digging into it found this was the culprit.
@mattpawson if you're using an older .NET 4.x project you'll need to ensure that your requests are being sent using TLS 1.2.
Add this line to your startup configuration:
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
I had this exact issue and after digging into it found this was the culprit.
What a star you are!!
That was the exact same problem! How did you manage to find out what the problem was just from the exception / stacktrace?
Cheers!
Pulled down the Xero library to debug it locally, found it was using IdentityModel to execute the requests for oauth2. So pulled that library and ran them all locally to determine that the underlying exception was "The request was aborted: Could not create SSL/TLS secure channel" which lead me to the TLS 1.2 solution.
You're a better man than I then! Thanks for your help!
Begs the question why this exception wasn't bubbled up to OAuth2Client, even if in an inner exception though...
SDK you're using (please complete the following information):
Describe the bug Unable to use the call "token = await client.RequestClientCredentialsTokenAsync();". It results in "An error occurred while sending the request." This code works fine, without issues, when called from a console application, but when attempted to be used within a WebApi2 application the issue occurs.
To Reproduce
Expected behavior Expect to receive token to allow continuation of processing requests.