Pass client id for Account and Admin consoles through environment (#20961)

This commit is contained in:
Jon Koops 2023-06-13 18:29:37 +02:00 committed by GitHub
parent e4cc7825f3
commit c998193797
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 15 additions and 17 deletions

View file

@ -88,8 +88,8 @@
<script id="environment" type="application/json"> <script id="environment" type="application/json">
{ {
"authUrl": "${authUrl}", "authUrl": "${authUrl}",
"isRunningAsTheme": true,
"realm": "${realm.name}", "realm": "${realm.name}",
"clientId": "${clientId}",
"resourceUrl": "${resourceUrl}", "resourceUrl": "${resourceUrl}",
"logo": "${properties.logo!""}", "logo": "${properties.logo!""}",
"logoUrl": "${properties.logoUrl!""}", "logoUrl": "${properties.logoUrl!""}",

View file

@ -1,10 +1,10 @@
export type Environment = { export type Environment = {
/** The URL to the root of the auth server. */ /** The URL to the root of the auth server. */
authUrl: string; authUrl: string;
/** Indicates if the application is running as a Keycloak theme. */ /** The realm used to authenticate the user to the Account Console. */
isRunningAsTheme: boolean;
/** The realm used to sign into. */
realm: string; realm: string;
/** The identifier of the client used to authenticate the user to the Account Console. */
clientId: string;
/** The URL to resources such as the files in the `public` directory. */ /** The URL to resources such as the files in the `public` directory. */
resourceUrl: string; resourceUrl: string;
/** Indicates the src for the Brand image */ /** Indicates the src for the Brand image */
@ -30,8 +30,8 @@ export type Environment = {
// The default environment, used during development. // The default environment, used during development.
const defaultEnvironment: Environment = { const defaultEnvironment: Environment = {
authUrl: "http://localhost:8180", authUrl: "http://localhost:8180",
isRunningAsTheme: false,
realm: "master", realm: "master",
clientId: "security-admin-console-v2",
resourceUrl: "http://localhost:8080", resourceUrl: "http://localhost:8080",
logo: "/logo.svg", logo: "/logo.svg",
logoUrl: "/", logoUrl: "/",

View file

@ -4,7 +4,5 @@ import { environment } from "./environment";
export const keycloak = new Keycloak({ export const keycloak = new Keycloak({
url: environment.authUrl, url: environment.authUrl,
realm: environment.realm, realm: environment.realm,
clientId: environment.isRunningAsTheme clientId: environment.clientId,
? "account-console"
: "security-admin-console-v2",
}); });

View file

@ -130,6 +130,7 @@
<script id="environment" type="application/json"> <script id="environment" type="application/json">
{ {
"loginRealm": "${loginRealm!"master"}", "loginRealm": "${loginRealm!"master"}",
"clientId": "${clientId}",
"authServerUrl": "${authServerUrl}", "authServerUrl": "${authServerUrl}",
"authUrl": "${authUrl}", "authUrl": "${authUrl}",
"consoleBaseUrl": "${consoleBaseUrl}", "consoleBaseUrl": "${consoleBaseUrl}",
@ -137,8 +138,7 @@
"masterRealm": "${masterRealm}", "masterRealm": "${masterRealm}",
"resourceVersion": "${resourceVersion}", "resourceVersion": "${resourceVersion}",
"logo": "${properties.logo!""}", "logo": "${properties.logo!""}",
"logoUrl": "${properties.logoUrl!""}", "logoUrl": "${properties.logoUrl!""}"
"isRunningAsTheme": true
} }
</script> </script>
</body> </body>

View file

@ -1,6 +1,8 @@
export type Environment = { export type Environment = {
/** The realm which should be used when signing into the application. */ /** The realm used to authenticate the user to the Admin Console. */
loginRealm: string; loginRealm: string;
/** The identifier of the client used to authenticate the user to the Admin Console. */
clientId: string;
/** The URL to the root of the auth server. */ /** The URL to the root of the auth server. */
authServerUrl: string; authServerUrl: string;
/** The URL to the path of the auth server where client requests can be sent. */ /** The URL to the path of the auth server where client requests can be sent. */
@ -13,8 +15,6 @@ export type Environment = {
masterRealm: string; masterRealm: string;
/** The version hash of the auth server. */ /** The version hash of the auth server. */
resourceVersion: string; resourceVersion: string;
/** Indicates if the application is running as a Keycloak theme. */
isRunningAsTheme: boolean;
/** Indicates the src for the Brand image */ /** Indicates the src for the Brand image */
logo: string; logo: string;
/** Indicates the url to be followed when Brand image is clicked */ /** Indicates the url to be followed when Brand image is clicked */
@ -27,13 +27,13 @@ const realm = new URLSearchParams(window.location.search).get("realm");
// The default environment, used during development. // The default environment, used during development.
const defaultEnvironment: Environment = { const defaultEnvironment: Environment = {
loginRealm: realm ?? "master", loginRealm: realm ?? "master",
clientId: "security-admin-console-v2",
authServerUrl: "http://localhost:8180", authServerUrl: "http://localhost:8180",
authUrl: "http://localhost:8180", authUrl: "http://localhost:8180",
consoleBaseUrl: "/admin/master/console/", consoleBaseUrl: "/admin/master/console/",
resourceUrl: ".", resourceUrl: ".",
masterRealm: "master", masterRealm: "master",
resourceVersion: "unknown", resourceVersion: "unknown",
isRunningAsTheme: false,
logo: "/logo.svg", logo: "/logo.svg",
logoUrl: "", logoUrl: "",
}; };

View file

@ -5,9 +5,7 @@ import environment from "./environment";
export const keycloak = new Keycloak({ export const keycloak = new Keycloak({
url: environment.authServerUrl, url: environment.authServerUrl,
realm: environment.loginRealm, realm: environment.loginRealm,
clientId: environment.isRunningAsTheme clientId: environment.clientId,
? "security-admin-console"
: "security-admin-console-v2",
}); });
export async function initKeycloak() { export async function initKeycloak() {

View file

@ -95,6 +95,7 @@ public class AccountConsole {
map.put("authUrl", authUrl.getPath().endsWith("/") ? authUrl : authUrl + "/"); map.put("authUrl", authUrl.getPath().endsWith("/") ? authUrl : authUrl + "/");
map.put("baseUrl", accountBaseUrl); map.put("baseUrl", accountBaseUrl);
map.put("realm", realm); map.put("realm", realm);
map.put("clientId", Constants.ACCOUNT_CONSOLE_CLIENT_ID);
map.put("resourceUrl", Urls.themeRoot(authUrl).getPath() + "/" + Constants.ACCOUNT_MANAGEMENT_CLIENT_ID + "/" + theme.getName()); map.put("resourceUrl", Urls.themeRoot(authUrl).getPath() + "/" + Constants.ACCOUNT_MANAGEMENT_CLIENT_ID + "/" + theme.getName());
map.put("resourceCommonUrl", Urls.themeRoot(adminBaseUri).getPath() + "/common/keycloak"); map.put("resourceCommonUrl", Urls.themeRoot(adminBaseUri).getPath() + "/common/keycloak");
map.put("resourceVersion", Version.RESOURCES_VERSION); map.put("resourceVersion", Version.RESOURCES_VERSION);

View file

@ -344,6 +344,7 @@ public class AdminConsole {
map.put("masterRealm", Config.getAdminRealm()); map.put("masterRealm", Config.getAdminRealm());
map.put("resourceVersion", Version.RESOURCES_VERSION); map.put("resourceVersion", Version.RESOURCES_VERSION);
map.put("loginRealm", realm.getName()); map.put("loginRealm", realm.getName());
map.put("clientId", Constants.ADMIN_CONSOLE_CLIENT_ID);
map.put("properties", theme.getProperties()); map.put("properties", theme.getProperties());
FreeMarkerProvider freeMarkerUtil = session.getProvider(FreeMarkerProvider.class); FreeMarkerProvider freeMarkerUtil = session.getProvider(FreeMarkerProvider.class);