Nhan Nguyen
Nhan Nguyen

Reputation: 106

ASP.NET Core authentication with Azure Active Directory throws Bad Request

Initially, I setup my ASP.NET Core project with authentication from Azure Active Directory through Visual Studio. It executed without error. After cloning to another PC the authentication keeps throwing Bad Request error. Tracing down the stack I got the following exception:

System.Net.Http.HttpRequestException: Response status code does not indicate success: 400 (Bad Request).
   at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectHandler.<RedeemAuthorizationCodeAsync>d__21.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 Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectHandler.<HandleRemoteAuthenticateAsync>d__19.MoveNext()

For sure all the setup of AAD in the portal are kept default and no configuration value changed after committing/cloning. Could someone please offer some solution for this?

Upvotes: 0

Views: 758

Answers (1)

Fei Xue
Fei Xue

Reputation: 14649

Based on the error message, the error was occurred at the RedeemAuthorizationCodeAsync, however it doesn’t show the real reason for the 400 error.

To narrow down this issue, I suggest that you use the Fiddler to capture the http request and response, then you can find the root cause for this issue by review the exact error message.

Upvotes: 2

Related Questions