Skip to content

Commit

Permalink
Automatically re-authenticate on single-logout (keycloak#28723) (keyc…
Browse files Browse the repository at this point in the history
…loak#31154)

Automatically forces the user to re-authenticate from the Admin and Account consoles when a single-logout occurs.

Closes keycloak#23832
Closes keycloak#23833




(cherry picked from commit 957859d)

Signed-off-by: Erik Jan de Wit <[email protected]>
Signed-off-by: Jon Koops <[email protected]>
Co-authored-by: Jon Koops <[email protected]>
  • Loading branch information
edewit and jonkoops authored Jul 22, 2024
1 parent 6b76886 commit dff6cff
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
25 changes: 13 additions & 12 deletions js/apps/account-ui/src/root/KeycloakContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,30 @@ export const KeycloakProvider = ({
const calledOnce = useRef(false);
const [init, setInit] = useState(false);
const [error, setError] = useState<unknown>();
const keycloak = useMemo(
() =>
new Keycloak({
url: environment.authUrl,
realm: environment.realm,
clientId: environment.clientId,
}),
[environment],
);
const keycloak = useMemo(() => {
const keycloak = new Keycloak({
url: environment.authUrl,
realm: environment.realm,
clientId: environment.clientId,
});

keycloak.onAuthLogout = () => keycloak.login();

return keycloak;
}, [environment]);

useEffect(() => {
// only needed in dev mode
if (calledOnce.current) {
return;
}

const init = () => {
return keycloak.init({
const init = () =>
keycloak.init({
onLoad: "check-sso",
pkceMethod: "S256",
responseMode: "query",
});
};

init()
.then(() => setInit(true))
Expand Down
2 changes: 2 additions & 0 deletions js/apps/admin-ui/src/keycloak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit dff6cff

Please sign in to comment.