/// <inheritdoc /> public async Task <string> StoreAsync(AuthenticationTicket ticket) { // it's possible that the user re-triggered OIDC (somehow) prior to // the session DB records being cleaned up, so we should preemptively remove // conflicting session records for this sub/sid combination await _store.DeleteUserSessionsAsync(new UserSessionsFilter { SubjectId = ticket.GetSubjectId(), SessionId = ticket.GetSessionId() }); var key = CryptoRandom.CreateUniqueId(format: CryptoRandom.OutputFormat.Hex); _logger.LogDebug("Creating entry in store for AuthenticationTicket, key {key}, with expiration: {expiration}", key, ticket.GetExpiration()); var session = new UserSession { Key = key, Created = ticket.GetIssued(), Renewed = ticket.GetIssued(), Expires = ticket.GetExpiration(), SubjectId = ticket.GetSubjectId(), SessionId = ticket.GetSessionId(), Ticket = ticket.Serialize(_protector) }; await _store.CreateUserSessionAsync(session); return(key); }
/// <inheritdoc /> public async Task <string> StoreAsync(AuthenticationTicket ticket) { var key = CryptoRandom.CreateUniqueId(format: CryptoRandom.OutputFormat.Hex); var session = new UserSession { Key = key, Created = ticket.GetIssued(), Renewed = ticket.GetIssued(), Expires = ticket.GetExpiration(), SubjectId = ticket.GetSubjectId(), SessionId = ticket.GetSessionId(), Scheme = ticket.AuthenticationScheme, Ticket = ticket.Serialize(), }; await _store.CreateUserSessionAsync(session); return(key); }
public async Task CreateUserSessionAsync_should_succeed() { _database.UserSessions.Count().Should().Be(0); 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" }); _database.UserSessions.Count().Should().Be(1); }