public async Task UpdateUserSessionAsync_should_succeed() { await _subject.CreateUserSessionAsync(new UserSession { Key = "key123", Scheme = "scheme", SessionId = "sid", SubjectId = "sub", Created = new DateTime(2020, 3, 1, 9, 12, 33, DateTimeKind.Utc), Renewed = new DateTime(2021, 4, 2, 10, 13, 34, DateTimeKind.Utc), Expires = new DateTime(2022, 5, 3, 11, 14, 35, DateTimeKind.Utc), Ticket = "ticket" }); await _subject.UpdateUserSessionAsync("key123", new UserSessionUpdate { Ticket = "ticket2", Renewed = new DateTime(2024, 1, 3, 5, 7, 9, DateTimeKind.Utc), Expires = new DateTime(2025, 2, 4, 6, 8, 10, DateTimeKind.Utc) }); var item = await _subject.GetUserSessionAsync("key123"); item.Should().NotBeNull(); item.Key.Should().Be("key123"); item.Scheme.Should().Be("scheme"); item.SubjectId.Should().Be("sub"); item.SessionId.Should().Be("sid"); item.Ticket.Should().Be("ticket2"); item.Created.Should().Be(new DateTime(2020, 3, 1, 9, 12, 33, DateTimeKind.Utc)); item.Renewed.Should().Be(new DateTime(2024, 1, 3, 5, 7, 9, DateTimeKind.Utc)); item.Expires.Should().Be(new DateTime(2025, 2, 4, 6, 8, 10, DateTimeKind.Utc)); }
/// <inheritdoc /> public async Task RenewAsync(string key, AuthenticationTicket ticket) { var session = await _store.GetUserSessionAsync(key); if (session == null) { throw new InvalidOperationException($"No matching item in store for key `{key}`"); } _logger.LogDebug("Renewing AuthenticationTicket for key {key}, with expiration: {expiration}", key, ticket.GetExpiration()); var sub = ticket.GetSubjectId(); var sid = ticket.GetSessionId(); var isNew = session.SubjectId != sub || session.SessionId != sid; var created = isNew ? ticket.GetIssued() : session.Created; await _store.UpdateUserSessionAsync(key, new UserSessionUpdate { SubjectId = ticket.GetSubjectId(), SessionId = ticket.GetSessionId(), Created = created, Renewed = ticket.GetIssued(), Expires = ticket.GetExpiration(), Ticket = ticket.Serialize(_protector) }); }
/// <inheritdoc /> public Task RenewAsync(string key, AuthenticationTicket ticket) { // todo: discuss updating sub and sid? return(_store.UpdateUserSessionAsync(key, new UserSessionUpdate { Renewed = ticket.GetIssued(), Expires = ticket.GetExpiration(), Ticket = ticket.Serialize(), })); }