/// <summary>
        /// This will ensure any impersonation cookie is deleted when a user signs out
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public Task SigningOutAsync(CookieSigningOutContext context)
        {
            var cookie = new ImpersonationCookie(context.HttpContext, null);

            cookie.Delete();

            return(Task.CompletedTask);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates ImpersonationHandler. NOTE: if protectionProvider is null then impersonation is turned off
        /// </summary>
        /// <param name="httpContext"></param>
        /// <param name="protectionProvider"></param>
        /// <param name="originalClaims"></param>
        public ImpersonationHandler(HttpContext httpContext, IDataProtectionProvider protectionProvider, List <Claim> originalClaims)
        {
            _httpContext        = httpContext ?? throw new ArgumentNullException(nameof(httpContext));
            _protectionProvider = protectionProvider;
            _cookie             = new ImpersonationCookie(httpContext, protectionProvider);
            _originalClaims     = originalClaims;

            _impersonationState = GetImpersonationState();
            //I use a lazy access to the cookie value as this takes a (bit) more time
            _startData = new Lazy <ImpersonationData>(() => new ImpersonationData(_cookie.GetCookieInValue()));
        }