public void Persist(AuthenticationTicket ticket) { var cookie = _cookies.CreateCookie(_systemTime); cookie.Value = EncodeJson(ticket); _cookies.Update(cookie); }
public virtual bool IsExpired(AuthenticationTicket ticket) { return _settings.SlidingExpiration ? _systemTime.UtcNow().Subtract(ticket.LastAccessed).TotalMinutes >= _settings.ExpireInMinutes : _systemTime.UtcNow() >= ticket.Expiration; }
public void Persist(AuthenticationTicket ticket) { var cookie = _cookies.CreateCookie(_systemTime); cookie.Value = _encryptor.Encrypt(JsonUtil.ToJson(ticket)); _cookies.Update(cookie); }
public void MarkAuthenticated(string userName) { var ticket = new AuthenticationTicket{ UserName = userName, LastAccessed = _systemTime.UtcNow() }; if (_settings.SlidingExpiration) { ticket.Expiration = _systemTime.UtcNow().AddMinutes(_settings.ExpireInMinutes); } _source.Persist(ticket); }
public void login_with_default_credentials_and_retrieve_a_resource() { // create the auth ticket var now = DateTime.Now; var ticket = new AuthenticationTicket { Expiration = now.AddDays(1), LastAccessed = now, UserName = "******" }; var writer = new CookieWriter(); Container .With(typeof(IOutputWriter), writer) .GetInstance<CookieTicketSource>() .Persist(ticket); var cookie = writer.Cookie; var response = endpoints.GetByInput(new TargetModel(), acceptType: "text/json", configure: r => { var cookies = new CookieContainer(); cookies.Add(new System.Net.Cookie { Domain = "localhost", Path = cookie.Path, Expires = now.AddDays(1), Name = cookie.States.Single().Name, Value = cookie.Value }); r.CookieContainer = cookies; r.AllowAutoRedirect = false; }); response.StatusCode.ShouldEqual(HttpStatusCode.OK); }
public string EncodeJson(AuthenticationTicket ticket) { var value = _encryptor.Encrypt(JsonUtil.ToJson(ticket)); return HttpUtility.UrlEncode(value); }