public async Task GetUserSessionAsync_for_valid_key_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" }); 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("ticket"); item.Created.Should().Be(new DateTime(2020, 3, 1, 9, 12, 33, DateTimeKind.Utc)); item.Renewed.Should().Be(new DateTime(2021, 4, 2, 10, 13, 34, DateTimeKind.Utc)); item.Expires.Should().Be(new DateTime(2022, 5, 3, 11, 14, 35, DateTimeKind.Utc)); }
/// <inheritdoc /> public async Task <AuthenticationTicket> RetrieveAsync(string key) { _logger.LogDebug("Retrieve AuthenticationTicket for key {key}", key); var session = await _store.GetUserSessionAsync(key); if (session == null) { _logger.LogDebug("No ticket found in store for {key}", key); return(null); } var ticket = session.Deserialize(_protector, _logger); if (ticket != null) { _logger.LogDebug("Ticket loaded for key: {key}, with expiration: {expiration}", key, ticket.GetExpiration()); return(ticket); } // if we failed to get a ticket, then remove DB record _logger.LogWarning("Failed to deserialize authentication ticket from store, deleting record for key {key}", key); await RemoveAsync(key); return(ticket); }
/// <inheritdoc /> public async Task <AuthenticationTicket> RetrieveAsync(string key) { var session = await _store.GetUserSessionAsync(key); if (session != null) { var ticket = session.Deserialize(); if (ticket == null) { // if we failed to get a ticket, then remove DB record _logger.LogWarning("Failed to deserialize authentication ticket from store, deleting record for key {key}", key); await RemoveAsync(key); } return(ticket); } return(null); }