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 <erikjan.dewit@gmail.com>
Signed-off-by: Jon Koops <jonkoops@gmail.com>
Co-authored-by: Jon Koops <jonkoops@gmail.com>
This commit is contained in:
Erik Jan de Wit 2024-04-22 13:45:15 +02:00 committed by GitHub
parent 5ae1712f73
commit 957859d846
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 10 deletions

View file

@ -42,12 +42,17 @@ export const KeycloakProvider = ({
const [init, setInit] = useState(false);
const [error, setError] = useState<unknown>();
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({
const init = () => keycloak.init({
onLoad: "check-sso",
pkceMethod: "S256",
responseMode: "query",
});
};
init()
.then(() => setInit(true))

View file

@ -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",