Skip to content

Commit 8eaca48

Browse files
committed
feat: support autologout config
Signed-off-by: Jessica He <[email protected]>
1 parent 8d2022f commit 8eaca48

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

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

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,67 @@ 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+
461+
await deployment.waitForSynced();
462+
463+
const login = await common.keycloakLogin(
464+
"zeus",
465+
process.env.DEFAULT_USER_PASSWORD,
466+
);
467+
expect(login).toBe("Login successful");
468+
469+
// Wait for the inactivity popup to appear
470+
const inactivityPopup = page.locator("text=Logging out due to inactivity");
471+
await expect(inactivityPopup).toBeVisible({ timeout: 35000 });
472+
await page.waitForTimeout(5000);
473+
474+
await page.reload();
475+
476+
const cookies = await context.cookies();
477+
const authCookie = cookies.find(
478+
(cookie) => cookie.name === "oidc-refresh-token",
479+
);
480+
expect(authCookie).toBeUndefined();
481+
});
482+
483+
test(`Enable autologout and user stays logged in after clicking "Don't log me out"`, async () => {
484+
const login = await common.keycloakLogin(
485+
"zeus",
486+
process.env.DEFAULT_USER_PASSWORD,
487+
);
488+
expect(login).toBe("Login successful");
489+
490+
// Wait for the inactivity popup to appear
491+
const inactivityPopup = page.locator("text=Logging out due to inactivity");
492+
await expect(inactivityPopup).toBeVisible({ timeout: 35000 });
493+
494+
const stayLoggedInButton = page.locator(
495+
'button:has-text("Don\'t log me out")',
496+
);
497+
await stayLoggedInButton.click();
498+
499+
// Verify popup is dismissed
500+
await expect(inactivityPopup).toBeHidden();
501+
502+
// Navigate to settings to verify user is still authenticated
503+
await uiHelper.goToPageUrl("/settings", "Settings");
504+
await uiHelper.verifyHeading("Zeus Giove");
505+
await common.signOut();
506+
});
507+
447508
test.afterAll(async () => {
448509
console.log("[TEST] Starting cleanup...");
449510
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)