public void Store(IHttpResponseDescriptor response, Uri requestUri, Token token) { var cookie = new Cookie(); if (Secure) { cookie.Secure = true; } cookie.Path = "/"; cookie.HttpOnly = true; cookie.Domain = GetDomain(requestUri); cookie.Name = CookieName; if (null == token) { cookie.Expires = DateTime.Now.AddYears(-1); cookie.Value = ""; } else { cookie.Expires = token.Expire.AddMinutes(5); cookie.Value = TokenEncryptor.Encrypt(token); } response.Cookies = response.Cookies ?? new CookieCollection(); response.Cookies.Add(cookie); }
public Token Extract(IHttpRequestDescriptor request) { var cookie = ReadCookie(request); if (string.IsNullOrWhiteSpace(cookie)) { return(null); } return(TokenEncryptor.Decrypt(cookie)); }