When I try to authenticate I get the following error
2021-10-01T11:19:46.162027114Z: [INFO] : Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]
2021-10-01T11:19:46.162072114Z: [INFO] An unhandled exception has occurred while executing the request.
2021-10-01T11:19:46.162078813Z: [INFO] System.Exception: An error was encountered while handling the remote login.
2021-10-01T11:19:46.163227804Z: [INFO] ---> System.Exception: Unable to unprotect the message.State.
2021-10-01T11:19:46.163254904Z: [INFO] --- End of inner exception stack trace ---
2021-10-01T11:19:46.163261804Z: [INFO] at Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler`1.HandleRequestAsync()
2021-10-01T11:19:46.163830499Z: [INFO] at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
2021-10-01T11:19:46.163847599Z: [INFO] at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
2021-10-01T11:19:46.163869499Z: [INFO] at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
I have created an core mvc site and it is working fine in stage and dev but the prod is failing. We are using linux docker to host on azure app services. We investigated and found that this issue is happening when azure tries to run multiple instances in prod. We found a link below which say about data protection but I need to understand in detail what I need to do. Azure AD Authentication in Kubernetes Unable to unprotect the message.State
In startup.cs the authentication is configured in following way
services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(options =>
{
Configuration.Bind("AzureAD", options);
options.AccessDeniedPath = new PathString("/Download");
options.Events ??= new OpenIdConnectEvents();
options.Events.OnTokenValidated = async (context) =>
{
//code to get some data from local database
};
});