public async Task user_endpoint_when_sliding_flag_is_passed_cookie_should_not_slide() { await BffHost.BffLoginAsync("alice"); var sessions = await _sessionStore.GetUserSessionsAsync(new UserSessionsFilter { SubjectId = "alice" }); sessions.Count().Should().Be(1); var session = sessions.Single(); var ticketStore = BffHost.Resolve <IServerTicketStore>(); var firstTicket = await ticketStore.RetrieveAsync(session.Key); firstTicket.Should().NotBeNull(); _clock.UtcNow = _clock.UtcNow.AddMinutes(8); (await BffHost.GetIsUserLoggedInAsync("slide=false")).Should().BeTrue(); var secondTicket = await ticketStore.RetrieveAsync(session.Key); secondTicket.Should().NotBeNull(); (secondTicket.Properties.IssuedUtc == firstTicket.Properties.IssuedUtc).Should().BeTrue(); (secondTicket.Properties.ExpiresUtc == firstTicket.Properties.ExpiresUtc).Should().BeTrue(); }
public async Task when_BackchannelLogoutAllUserSessions_is_true_backchannel_logout_should_logout_all_sessions() { BffHost.BffOptions.BackchannelLogoutAllUserSessions = true; await BffHost.BffLoginAsync("alice", "sid1"); BffHost.BrowserClient.RemoveCookie("bff"); await BffHost.BffLoginAsync("alice", "sid2"); { var store = BffHost.Resolve <IUserSessionStore>(); var sessions = await store.GetUserSessionsAsync(new UserSessionsFilter { SubjectId = "alice" }); sessions.Count().Should().Be(2); } await IdentityServerHost.RevokeSessionCookieAsync(); { var store = BffHost.Resolve <IUserSessionStore>(); var sessions = await store.GetUserSessionsAsync(new UserSessionsFilter { SubjectId = "alice" }); sessions.Should().BeEmpty(); } }
public async Task user_endpoint_when_uservalidate_renews_and_sliding_flag_is_passed_cookie_should_not_slide() { var shouldRenew = false; #if NET6_0_OR_GREATER BffHost.OnConfigureServices += services => { services.Configure <CookieAuthenticationOptions>("cookie", options => { options.Events.OnCheckSlidingExpiration = ctx => { ctx.ShouldRenew = shouldRenew; return(Task.CompletedTask); }; }); }; #else BffHost.OnConfigureServices += services => { services.Configure <CookieAuthenticationOptions>("cookie", options => { options.Events.OnValidatePrincipal = ctx => { ctx.ShouldRenew = shouldRenew; return(Task.CompletedTask); }; }); }; #endif await BffHost.InitializeAsync(); await BffHost.BffLoginAsync("alice"); var sessions = await _sessionStore.GetUserSessionsAsync(new UserSessionsFilter { SubjectId = "alice" }); sessions.Count().Should().Be(1); var session = sessions.Single(); var ticketStore = BffHost.Resolve <IServerTicketStore>(); var firstTicket = await ticketStore.RetrieveAsync(session.Key); firstTicket.Should().NotBeNull(); shouldRenew = true; _clock.UtcNow = _clock.UtcNow.AddSeconds(1); (await BffHost.GetIsUserLoggedInAsync("slide=false")).Should().BeTrue(); var secondTicket = await ticketStore.RetrieveAsync(session.Key); secondTicket.Should().NotBeNull(); (secondTicket.Properties.IssuedUtc == firstTicket.Properties.IssuedUtc).Should().BeTrue(); (secondTicket.Properties.ExpiresUtc == firstTicket.Properties.ExpiresUtc).Should().BeTrue(); }