Force user to authenticate before bootstrapping Admin Console (#20251)

This commit is contained in:
Jon Koops 2023-05-10 08:20:49 +02:00 committed by GitHub
parent 67cc6bfa7c
commit 64a65bd0aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View file

@ -9,3 +9,15 @@ export const keycloak = new Keycloak({
? "security-admin-console"
: "security-admin-console-v2",
});
export async function initKeycloak() {
const authenticated = await keycloak.init({
onLoad: "check-sso",
pkceMethod: "S256",
});
// Force the user to login if not authenticated.
if (!authenticated) {
await keycloak.login();
}
}

View file

@ -6,13 +6,13 @@ import { render } from "react-dom";
import { createHashRouter, RouterProvider } from "react-router-dom";
import { initI18n } from "./i18n";
import { keycloak } from "./keycloak";
import { initKeycloak } from "./keycloak";
import { RootRoute } from "./routes";
import "./index.css";
// Initialize required components before rendering app.
await keycloak.init({ onLoad: "check-sso", pkceMethod: "S256" });
await initKeycloak();
await initI18n();
const router = createHashRouter([RootRoute]);