C# OAuth Call to login.MicrosoftOnline.com Results in TLS/SSL Error Sporadically
Hi Microsoft Q&A,
I wrote a C# application that attempts to get an OAuth token from https://login.microsoftonline.com. The resulting access token is in turn used to call a Microsoft D365 Cloud application web service.
My problem is the my C# application is randomly throwing the below SSL error when it attempts to refresh the OAuth token from https://login.microsoftonline.com:
System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
The SSL error appears randomly. Some connections connect successfully, but others fail with an SSL certificate error.
It feels like login.microsoftonline.com is a load balanced server and one or more of its nodes has a different ssl that my system cannot accept. If my C# calls the correct server on the load balancer node, it connects fine, but if it happens to call the bad load balanced server node, it fails.