Skip to content

Commit 66345d4

Browse files
committed
feat: support autologout config
Signed-off-by: Jessica He <[email protected]>
1 parent 17d3fc1 commit 66345d4

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

e2e-tests/playwright/e2e/auth-providers/oidc.spec.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,71 @@ test.describe("Configure OIDC provider (using RHBK)", async () => {
444444
await context.clearCookies();
445445
});
446446

447+
test(`Enable autologout and user is logged out after inactivity`, async () => {
448+
deployment.setAppConfigProperty("auth.autologout.enabled", "true");
449+
deployment.setAppConfigProperty(
450+
"auth.autologout.idleTimeoutMinutes",
451+
"0.5", // minimum allowed value is 0.5 minutes
452+
);
453+
deployment.setAppConfigProperty(
454+
"auth.autologout.promptBeforeIdleSeconds",
455+
"3",
456+
);
457+
await deployment.updateAllConfigs();
458+
await deployment.restartLocalDeployment();
459+
await deployment.waitForDeploymentReady();
460+
await deployment.waitForSynced();
461+
462+
const login = await common.keycloakLogin(
463+
"zeus",
464+
process.env.DEFAULT_USER_PASSWORD,
465+
);
466+
expect(login).toBe("Login successful");
467+
468+
await uiHelper.verifyTextVisible(
469+
"Logging out due to inactivity",
470+
false,
471+
60000,
472+
);
473+
await page.waitForTimeout(5000);
474+
475+
await page.reload();
476+
477+
const cookies = await context.cookies();
478+
const authCookie = cookies.find(
479+
(cookie) => cookie.name === "oidc-refresh-token",
480+
);
481+
expect(authCookie).toBeUndefined();
482+
});
483+
484+
test(`Enable autologout and user stays logged in after clicking "Don't log me out"`, async () => {
485+
deployment.setAppConfigProperty("auth.autologout.enabled", "true");
486+
deployment.setAppConfigProperty(
487+
"auth.autologout.idleTimeoutMinutes",
488+
"0.5", // minimum allowed value is 0.5 minutes
489+
);
490+
deployment.setAppConfigProperty(
491+
"auth.autologout.promptBeforeIdleSeconds",
492+
"5",
493+
);
494+
await deployment.updateAllConfigs();
495+
await deployment.restartLocalDeployment();
496+
await deployment.waitForDeploymentReady();
497+
await deployment.waitForSynced();
498+
499+
const login = await common.keycloakLogin(
500+
"zeus",
501+
process.env.DEFAULT_USER_PASSWORD,
502+
);
503+
expect(login).toBe("Login successful");
504+
505+
await uiHelper.clickButtonByText("Don't log me out", { timeout: 60000 });
506+
507+
await uiHelper.goToPageUrl("/settings", "Settings");
508+
await uiHelper.verifyHeading("Zeus Giove");
509+
await common.signOut();
510+
});
511+
447512
test.afterAll(async () => {
448513
console.log("[TEST] Starting cleanup...");
449514
await deployment.killRunningProcess();

packages/app/src/components/AppBase/AppBase.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import { useContext } from 'react';
22
import { Route } from 'react-router-dom';
33

44
import { FlatRoutes } from '@backstage/core-app-api';
5-
import { AlertDisplay, OAuthRequestDialog } from '@backstage/core-components';
5+
import {
6+
AlertDisplay,
7+
AutoLogout,
8+
OAuthRequestDialog,
9+
} from '@backstage/core-components';
610
import { ApiExplorerPage } from '@backstage/plugin-api-docs';
711
import {
812
CatalogEntityPage,
@@ -152,6 +156,7 @@ const AppBase = () => {
152156
</Root>
153157
</ApplicationProvider>
154158
</AppRouter>
159+
<AutoLogout enabled={false} idleTimeoutMinutes={60} />
155160
</AppProvider>
156161
);
157162
};

0 commit comments

Comments
 (0)