Set task in Owin middleware

The Owin middleware implementation looks for its own type of authentication before adding the call, so only matching middleware responds. Several problems 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 an embedded Cookie or Bearer middleware, the "Bearer" type is always present and gets searched.

Where could I add my own call type globally to get it raised? This can be done manually in the context of the request by calling

Request.GetOwinContext().Authentication.Challenge("Basic");

      

but I would like to add a global config for all controllers.

+3


source to share


1 answer


You can install AuthenticationResponseChallenge

using methods AuthenticationManager.Challenge()

. For example, in your startup.cs, you might have something like context.Authentication.Challenge(new AuthenticationProperties(), Options.AuthenticationType)

so that middleware matching the Options.AuthenticationType parameters returns this issue when searched.



The active middleware will try to process all outgoing calls regardless of its AuthenticationType. Typically only the cookie middleware is set to active and all other middleware is passive. For passive middleware to act on a call, the task must have an appropriate AuthenticationType.

+1


source







All Articles