From 957859d8465e3e72c036dca88f6ef73b5ade650e Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Mon, 22 Apr 2024 13:45:15 +0200 Subject: [PATCH] Automatically re-authenticate on single-logout (#28723) Automatically forces the user to re-authenticate from the Admin and Account consoles when a single-logout occurs. Closes #23832 Closes #23833 Signed-off-by: Erik Jan de Wit Signed-off-by: Jon Koops Co-authored-by: Jon Koops --- .../account-ui/src/root/KeycloakContext.tsx | 23 +++++++++++-------- js/apps/admin-ui/src/keycloak.ts | 2 ++ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/js/apps/account-ui/src/root/KeycloakContext.tsx b/js/apps/account-ui/src/root/KeycloakContext.tsx index f611a3893981..a1f8bc3a42bb 100644 --- a/js/apps/account-ui/src/root/KeycloakContext.tsx +++ b/js/apps/account-ui/src/root/KeycloakContext.tsx @@ -42,12 +42,17 @@ export const KeycloakProvider = ({ const [init, setInit] = useState(false); const [error, setError] = useState(); const keycloak = useMemo( - () => - new Keycloak({ + () => { + const keycloak = new Keycloak({ url: environment.authUrl, realm: environment.realm, clientId: environment.clientId, - }), + }); + + keycloak.onAuthLogout = () => keycloak.login(); + + return keycloak; + }, [environment], ); @@ -57,13 +62,11 @@ export const KeycloakProvider = ({ return; } - const init = () => { - return keycloak.init({ - onLoad: "check-sso", - pkceMethod: "S256", - responseMode: "query", - }); - }; + const init = () => keycloak.init({ + onLoad: "check-sso", + pkceMethod: "S256", + responseMode: "query", + }); init() .then(() => setInit(true)) diff --git a/js/apps/admin-ui/src/keycloak.ts b/js/apps/admin-ui/src/keycloak.ts index d8fe5d3a1797..76925593faaf 100644 --- a/js/apps/admin-ui/src/keycloak.ts +++ b/js/apps/admin-ui/src/keycloak.ts @@ -8,6 +8,8 @@ export const keycloak = new Keycloak({ clientId: environment.clientId, }); +keycloak.onAuthLogout = () => keycloak.login(); + export async function initKeycloak() { const authenticated = await keycloak.init({ onLoad: "check-sso",