Keycloak

Форк
0
/
environment.ts 
70 строк · 2.3 Кб
1
export type Environment = {
2
  /** The realm used to authenticate the user to the Admin Console. */
3
  loginRealm: string;
4
  /** The identifier of the client used to authenticate the user to the Admin Console. */
5
  clientId: string;
6
  /** The URL to the root of the auth server. */
7
  authServerUrl: string;
8
  /** The URL to the path of the auth server where client requests can be sent. */
9
  authUrl: string;
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. */
13
  resourceUrl: string;
14
  /** The name of the master realm. */
15
  masterRealm: string;
16
  /** The version hash of the auth server. */
17
  resourceVersion: string;
18
  /** Indicates the src for the Brand image */
19
  logo: string;
20
  /** Indicates the url to be followed when Brand image is clicked */
21
  logoUrl: string;
22
};
23

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");
26

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/",
34
  resourceUrl: ".",
35
  masterRealm: "master",
36
  resourceVersion: "unknown",
37
  logo: "/logo.svg",
38
  logoUrl: "",
39
};
40

41
// Merge the default and injected environment variables together.
42
const environment: Environment = {
43
  ...defaultEnvironment,
44
  ...getInjectedEnvironment(),
45
};
46

47
export default environment;
48

49
/**
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.
52
 */
53
function getInjectedEnvironment(): Record<string, string | number | boolean> {
54
  const element = document.getElementById("environment");
55

56
  // If the element cannot be found, return an empty record.
57
  if (!element?.textContent) {
58
    return {};
59
  }
60

61
  // Attempt to parse the contents as JSON and return its value.
62
  try {
63
    return JSON.parse(element.textContent);
64
  } catch (error) {
65
    console.error("Unable to parse environment variables.");
66
  }
67

68
  // Otherwise, return an empty record.
69
  return {};
70
}
71

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.