public static void DetachAuthenticationHandler(this HttpContext context, IForwardingAuthenticationHandler handler) { var auth = context.Features.Get <IHttpAuthenticationFeature>(); if (auth != null) { auth.Handler = handler.PriorHandler; } }
public static void AttachAuthenticationHandler(this HttpContext context, IForwardingAuthenticationHandler handler, ClaimsPrincipal user = null) { var auth = context.Features.Get <IHttpAuthenticationFeature>(); if (auth == null) { auth = new HttpAuthenticationFeature(); context.Features.Set(auth); } auth.User = user; context.User = user; handler.PriorHandler = auth.Handler; auth.Handler = handler; }