From 64a65bd0aa175740732957310369d1b73cbd0dcb Mon Sep 17 00:00:00 2001 From: Jon Koops Date: Wed, 10 May 2023 08:20:49 +0200 Subject: [PATCH] Force user to authenticate before bootstrapping Admin Console (#20251) --- js/apps/admin-ui/src/keycloak.ts | 12 ++++++++++++ js/apps/admin-ui/src/main.tsx | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/js/apps/admin-ui/src/keycloak.ts b/js/apps/admin-ui/src/keycloak.ts index 7fe93eecd1..e6c627c0e0 100644 --- a/js/apps/admin-ui/src/keycloak.ts +++ b/js/apps/admin-ui/src/keycloak.ts @@ -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(); + } +} diff --git a/js/apps/admin-ui/src/main.tsx b/js/apps/admin-ui/src/main.tsx index e69cc9bb77..8a933539a9 100644 --- a/js/apps/admin-ui/src/main.tsx +++ b/js/apps/admin-ui/src/main.tsx @@ -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]);