I am using the OWIN cookie authentication middleware and have setup a custom OnValidateIdentity
-method that should be invoked on all requests that needs to be authenticated.
My setup looks like this:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = "my-cookie",
Provider = new CookieAuthenticationProvider()
{
OnValidateIdentity = async ctx =>
{
// my own validation code
}
}
}
The issue I have is that for some requests, OnValidateIdentity
is not called. If I hit the same protected Web API controller multiple times, some of the requests would not invoke the OnValidateIdentity
-method.
This leads to issues later in the processing when I need to use GetOwinContext().Authentication.User
and the ClaimsPrincipal
is not populated.
What could be the reason for this?