Skip to content

Commit 28cd968

Browse files
authored
Use correct host URL for Admin Console requests (#30535) (#30579)
Closes #30432 Signed-off-by: Jon Koops <[email protected]> (cherry picked from commit 77fb3c4)
1 parent 96e7809 commit 28cd968

File tree

18 files changed

+110
-137
lines changed

18 files changed

+110
-137
lines changed

docs/documentation/upgrading/topics/changes/changes-25_0_0.adoc

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -445,22 +445,15 @@ If you wish to use Oracle DB, you must manually install a version of the Oracle
445445

446446
= Deprecated theme variables
447447

448-
The following variables were deprecated in the Account theme:
448+
The following variables were deprecated in the Admin theme and will be removed in a future version:
449449

450-
* `authUrl`. Use `authServerUrl` instead.
450+
* `authServerUrl`. Use `serverBaseUrl` instead.
451+
* `authUrl`. Use `adminBaseUrl` instead.
451452

452-
The following variables from the environment script injected into the page of the Account theme are deprecated:
453+
The following variables were deprecated in the Account theme and will be removed in a future version:
453454

454-
* `authUrl`. Use `authServerUrl` instead.
455-
* `features.isInternationalizationEnabled`. Do not use this variable.
456-
457-
The following variables were deprecated in the Admin theme:
458-
459-
* `authUrl`. Do not use this variable.
460-
461-
The following variables from the environment script injected into the page of the Admin theme are deprecated:
462-
463-
* `authUrl`. Do not use this variable.
455+
* `authServerUrl`. Use `serverBaseUrl` instead, note `serverBaseUrl` does not include trailing slash.
456+
* `authUrl`. Use `serverBaseUrl` instead, note `serverBaseUrl` does not include trailing slash.
464457

465458
= Methods to get and set current refresh token in client session are now deprecated
466459

js/apps/account-ui/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { KeycloakProvider } from "@keycloak/keycloak-account-ui";
2222
//...
2323

2424
<KeycloakProvider environment={{
25-
authServerUrl: "http://localhost:8080",
25+
serverBaseUrl: "http://localhost:8080",
2626
realm: "master",
2727
clientId: "security-admin-console"
2828
}}>

js/apps/account-ui/maven-resources/theme/keycloak.v3/account/index.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
<noscript>JavaScript is required to use the Account Console.</noscript>
111111
<script id="environment" type="application/json">
112112
{
113+
"serverBaseUrl": "${serverBaseUrl}",
113114
"authUrl": "${authUrl}",
114115
"authServerUrl": "${authServerUrl}",
115116
"realm": "${realm.name}",

js/apps/account-ui/src/api.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,19 @@ function checkResponse<T>(response: T) {
8181

8282
export async function getIssuer(context: KeycloakContext<BaseEnvironment>) {
8383
const response = await request(
84-
"/realms/" +
85-
context.environment.realm +
84+
joinPath(
85+
"/realms/",
86+
context.environment.realm,
8687
"/.well-known/openid-credential-issuer",
88+
),
8789
context,
8890
{},
8991
new URL(
9092
joinPath(
91-
context.environment.authServerUrl +
92-
"/realms/" +
93-
context.environment.realm +
94-
"/.well-known/openid-credential-issuer",
93+
context.environment.serverBaseUrl,
94+
"/realms/",
95+
context.environment.realm,
96+
"/.well-known/openid-credential-issuer",
9597
),
9698
),
9799
);

js/apps/account-ui/src/api/methods.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export async function linkAccount(
134134
) {
135135
const redirectUri = encodeURIComponent(
136136
joinPath(
137-
context.environment.authServerUrl,
137+
context.environment.serverBaseUrl,
138138
"realms",
139139
context.environment.realm,
140140
"account",

js/apps/account-ui/src/api/request.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export async function request(
5454
export const url = (environment: BaseEnvironment, path: string) =>
5555
new URL(
5656
joinPath(
57-
environment.authServerUrl,
57+
environment.serverBaseUrl,
5858
"realms",
5959
environment.realm,
6060
"account",

js/apps/account-ui/src/environment.ts

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,4 @@ export type Feature = {
2828
isOid4VciEnabled: boolean;
2929
};
3030

31-
// During development the realm can be passed as a query parameter when redirecting back from Keycloak.
32-
const realm =
33-
new URLSearchParams(window.location.search).get("realm") ||
34-
location.pathname.match("/realms/(.*?)/account")?.[1] ||
35-
"master";
36-
37-
const defaultEnvironment: Environment = {
38-
// Base environment variables
39-
authServerUrl: "http://localhost:8180",
40-
realm: realm,
41-
clientId: "security-admin-console-v2",
42-
resourceUrl: "http://localhost:8080",
43-
logo: "/logo.svg",
44-
logoUrl: "/",
45-
// Account Console specific environment variables
46-
baseUrl: `http://localhost:8180/realms/${realm}/account/`,
47-
locale: "en",
48-
features: {
49-
isRegistrationEmailAsUsername: false,
50-
isEditUserNameAllowed: true,
51-
isLinkedAccountsEnabled: true,
52-
isMyResourcesEnabled: true,
53-
deleteAccountAllowed: true,
54-
updateEmailFeatureEnabled: true,
55-
updateEmailActionEnabled: true,
56-
isViewGroupsEnabled: true,
57-
isOid4VciEnabled: true,
58-
},
59-
};
60-
61-
export const environment = getInjectedEnvironment(defaultEnvironment);
31+
export const environment = getInjectedEnvironment<Environment>();

js/apps/account-ui/src/i18n.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const i18n = createInstance({
2929
},
3030
backend: {
3131
loadPath: joinPath(
32-
environment.authServerUrl,
32+
environment.serverBaseUrl,
3333
`resources/${environment.realm}/account/{{lng}}`,
3434
),
3535
parse: (data: string) => {

js/apps/admin-ui/maven-resources/theme/keycloak.v2/admin/index.ftl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@
110110
<noscript>JavaScript is required to use the Administration Console.</noscript>
111111
<script id="environment" type="application/json">
112112
{
113+
"serverBaseUrl": "${serverBaseUrl}",
114+
"adminBaseUrl": "${adminBaseUrl}",
113115
"authUrl": "${authUrl}",
114116
"authServerUrl": "${authServerUrl}",
115117
"realm": "${loginRealm!"master"}",

js/apps/admin-ui/src/admin-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export async function initAdminClient(
2525
const adminClient = new KeycloakAdminClient();
2626

2727
adminClient.setConfig({ realmName: environment.realm });
28-
adminClient.baseUrl = environment.authServerUrl;
28+
adminClient.baseUrl = environment.adminBaseUrl;
2929
adminClient.registerTokenProvider({
3030
async getAccessToken() {
3131
try {

0 commit comments

Comments
 (0)