Fix Unable to unprotect the message.State. exception on Identity Server redirect

After fixing the 502 Bad Gateway issue I hit another one.

Here is the exception I have from the logs

HTTP POST /signin-oidc responded 500 in 77.6515 ms

System.Exception: An error was encountered while handling the remote login. —> System.Exception: Unable to unprotect the message.State. — End of inner exception stack trace — at Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler`1.HandleRequestAsync() at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Serilog.AspNetCore.RequestLoggingMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)

As mentioned in the previous post – when I run from Visual Studio 2022 and debug – all is fine. It doesn’t work from the Kubernetes cluster. I have tried one more cluster and the result is the same.

The mistake I did when deploying the second cluster is that I have used the same configuration. This particular service that was using the Identity Server has two instances. Reducing the number of instances to one fixed the problem. I know this is not a final fix and will come back to it when the time is right. For now I can continue the development of the services.