We encounter a very bizarre issue with Azure AD library in a asp.net web api app. When we try to get token using AcquireTokenAsync with a Certificate, there is no response and then time out.
Bizarre part:
If we copy the same code in a console app, console app works, get token instantly.
if we use fiddler to start a proxy which overtake our company's default proxy, webapi app works.
The testing code we are using is exactly from the documentation.
Sample code we use :
public async Task < string > GetTokenAsync() {
var context = new AuthenticationContext(authority);
var store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly);
var results = store.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false);
var cert = new ClientAssertionCertificate(clientid, results[0]);
var token = await context.AcquireTokenAsync(resource, cert).AccessToken;
return token;
}
Basically the code should work properly since it is from documentation directly. is it something relative to the networking?
The Error we get in short:
at System.Web.Http.Results.ExceptionResult..ctor(Exception exception, IDependencyProvider dependencies) at System.Web.Http.ApiController.InternalServerError(Exception exception) at WebApplication1.Controllers.TokenController.d__0.MoveNext() in C:\Users\QiaoH\source\repos\WebApplication1\WebApplication1\Controllers\TokenController.cs:line 55 --- End of stack trace from previous location where exception was thrown at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Threading.Tasks.TaskHelpersExtensions.d__1`1.MoveNext() End of stack trace from previous location where exception was thrown at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Controllers.ApiControllerActionInvoker.d__1.MoveNext() --- End of stack trace from previous location where exception was thrown at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Controllers.ActionFilterResult.d__5.MoveNext() End of stack trace from previous location where exception was thrown at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__15.MoveNext()