Beispiel #1
0
        public static HttpCookie CreateCookie(string identifier, out Guid authenticationToken, bool persistent = false)
        {
            using (var protector = new CookieProtector(Configuration))
            {
                authenticationToken = Guid.NewGuid();

                var authenticationCookie = new AuthenticationCookie(0, authenticationToken, persistent, identifier);
                return(authenticationCookie.CreateHttpCookie(protector, Configuration));
            }
        }
Beispiel #2
0
        private static void RenewCookieIfExpiring(HttpContextBase context, CookieProtector protector, AuthenticationCookie authenticationCookie)
        {
            if (!Configuration.SlidingExpiration || !authenticationCookie.IsExpired(TimeSpan.FromTicks(Configuration.Timeout.Ticks / 2)))
            {
                return;
            }

            authenticationCookie.Renew();
            context.Response.Cookies.Remove(Configuration.CookieName);

            var newCookie = authenticationCookie.CreateHttpCookie(protector, Configuration);

            context.Response.Cookies.Add(newCookie);
        }
        private static void RenewCookieIfExpiring(IOwinResponse response, CookieProtector protector, AuthenticationCookie authenticationCookie)
        {
            if (!Configuration.SlidingExpiration || !authenticationCookie.IsExpired(TimeSpan.FromTicks(Configuration.Timeout.Ticks / 2)))
            {
                return;
            }

            authenticationCookie.Renew();
            response.Cookies.Delete(Configuration.CookieName);

            var newCookie = authenticationCookie.CreateHttpCookie(protector, Configuration);

            response.Cookies.Append(Configuration.CookieName, newCookie.Value, new CookieOptions
            {
                Domain   = newCookie.Domain,
                Expires  = newCookie.Expires,
                HttpOnly = newCookie.HttpOnly,
                Path     = newCookie.Path,
                Secure   = newCookie.Secure
            });
        }