Owin middleware implementations lookup their own authentication type before adding a challenge, so only the appropriate middleware responds. Multiple challenges can be used at the same time.
protected override Task ApplyResponseChallengeAsync()
{
if (Response.StatusCode == 401)
{
var challenge = Helper.LookupChallenge(Options.AuthenticationType, Options.AuthenticationMode);
if (challenge != null)
{
Response.Headers.AppendValues("WWW-Authenticate", _challenge);
}
}
return Task.FromResult<object>(null);
}
When using the built-in Cookie or Bearer middleware, the "Bearer" type is always present and gets looked up.
Where would I add my own challenge type globally so it gets looked up? This can be done manually within a request context by calling
Request.GetOwinContext().Authentication.Challenge("Basic");
but I would like to add a global configuration for all controllers.