From 45b878e2e6a4afb0a3d4206b09434ebafa17d855 Mon Sep 17 00:00:00 2001 From: Stan Silvert Date: Mon, 26 Oct 2020 04:00:05 -0400 Subject: [PATCH] Allow login to different realms using query param (#188) --- public/keycloak.json | 8 -------- src/components/realm-selector/RealmSelector.tsx | 2 +- src/context/auth/keycloak.ts | 10 +++++++++- 3 files changed, 10 insertions(+), 10 deletions(-) delete mode 100644 public/keycloak.json diff --git a/public/keycloak.json b/public/keycloak.json deleted file mode 100644 index 977acfded3..0000000000 --- a/public/keycloak.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "realm": "master", - "auth-server-url": "http://localhost:8180/auth/", - "ssl-required": "external", - "resource": "security-admin-console-v2", - "public-client": true, - "confidential-port": 0 -} \ No newline at end of file diff --git a/src/components/realm-selector/RealmSelector.tsx b/src/components/realm-selector/RealmSelector.tsx index 4f57b411ef..48747f16ec 100644 --- a/src/components/realm-selector/RealmSelector.tsx +++ b/src/components/realm-selector/RealmSelector.tsx @@ -69,7 +69,7 @@ export const RealmSelector = ({ realmList }: RealmSelectorProps) => { const dropdownItems = realmList.map((r) => ( { setRealm(r.realm); setOpen(!open); diff --git a/src/context/auth/keycloak.ts b/src/context/auth/keycloak.ts index c4c1096d01..59d5785927 100644 --- a/src/context/auth/keycloak.ts +++ b/src/context/auth/keycloak.ts @@ -1,5 +1,13 @@ import Keycloak, { KeycloakInstance } from "keycloak-js"; -const keycloak: KeycloakInstance = Keycloak("/keycloak.json"); + +const realm = + new URLSearchParams(window.location.search).get("realm") || "master"; + +const keycloak: KeycloakInstance = Keycloak({ + url: "http://localhost:8180/auth/", + realm: realm, + clientId: "security-admin-console-v2", +}); export default async function (): Promise { await keycloak.init({ onLoad: "check-sso", pkceMethod: "S256" }).catch(() => {