1
export type Environment = {
2
/** The realm used to authenticate the user to the Admin Console. */
4
/** The identifier of the client used to authenticate the user to the Admin Console. */
6
/** The URL to the root of the auth server. */
8
/** The URL to the path of the auth server where client requests can be sent. */
10
/** The URL to the base of the Admin UI. */
11
consoleBaseUrl: string;
12
/** The URL to resources such as the files in the `public` directory. */
14
/** The name of the master realm. */
16
/** The version hash of the auth server. */
17
resourceVersion: string;
18
/** Indicates the src for the Brand image */
20
/** Indicates the url to be followed when Brand image is clicked */
24
// During development the realm can be passed as a query parameter when redirecting back from Keycloak.
25
const realm = new URLSearchParams(window.location.search).get("realm");
27
// The default environment, used during development.
28
const defaultEnvironment: Environment = {
29
loginRealm: realm ?? "master",
30
clientId: "security-admin-console-v2",
31
authServerUrl: "http://localhost:8180",
32
authUrl: "http://localhost:8180",
33
consoleBaseUrl: "/admin/master/console/",
35
masterRealm: "master",
36
resourceVersion: "unknown",
41
// Merge the default and injected environment variables together.
42
const environment: Environment = {
43
...defaultEnvironment,
44
...getInjectedEnvironment(),
47
export default environment;
50
* Extracts the environment variables that are passed if the application is running as a Keycloak theme.
51
* These variables are injected by Keycloak into the `index.ftl` as a script tag, the contents of which can be parsed as JSON.
53
function getInjectedEnvironment(): Record<string, string | number | boolean> {
54
const element = document.getElementById("environment");
56
// If the element cannot be found, return an empty record.
57
if (!element?.textContent) {
61
// Attempt to parse the contents as JSON and return its value.
63
return JSON.parse(element.textContent);
65
console.error("Unable to parse environment variables.");
68
// Otherwise, return an empty record.