changed to use adminUrl instead (#30441)
* changed to use adminUrl instead fixes: #19070 Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com> * changed to make use of "frondend url" and "adminUrl" Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com> --------- Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
This commit is contained in:
parent
3a156b1a8b
commit
e3649eb86a
3 changed files with 42 additions and 32 deletions
|
@ -1,6 +1,6 @@
|
||||||
import type ClientRepresentation from "@keycloak/keycloak-admin-client/lib/defs/clientRepresentation";
|
import type ClientRepresentation from "@keycloak/keycloak-admin-client/lib/defs/clientRepresentation";
|
||||||
import type { ClientQuery } from "@keycloak/keycloak-admin-client/lib/resources/clients";
|
import type { ClientQuery } from "@keycloak/keycloak-admin-client/lib/resources/clients";
|
||||||
import { label } from "@keycloak/keycloak-ui-shared";
|
import { label, useEnvironment } from "@keycloak/keycloak-ui-shared";
|
||||||
import {
|
import {
|
||||||
AlertVariant,
|
AlertVariant,
|
||||||
Badge,
|
Badge,
|
||||||
|
@ -37,6 +37,7 @@ import {
|
||||||
import { ViewHeader } from "../components/view-header/ViewHeader";
|
import { ViewHeader } from "../components/view-header/ViewHeader";
|
||||||
import { useAccess } from "../context/access/Access";
|
import { useAccess } from "../context/access/Access";
|
||||||
import { useRealm } from "../context/realm-context/RealmContext";
|
import { useRealm } from "../context/realm-context/RealmContext";
|
||||||
|
import { Environment } from "../environment";
|
||||||
import helpUrls from "../help-urls";
|
import helpUrls from "../help-urls";
|
||||||
import { emptyFormatter, exportClient } from "../util";
|
import { emptyFormatter, exportClient } from "../util";
|
||||||
import { convertClientToUrl } from "../utils/client-url";
|
import { convertClientToUrl } from "../utils/client-url";
|
||||||
|
@ -90,8 +91,8 @@ const ClientDescription = (client: ClientRepresentation) => (
|
||||||
);
|
);
|
||||||
|
|
||||||
const ClientHomeLink = (client: ClientRepresentation) => {
|
const ClientHomeLink = (client: ClientRepresentation) => {
|
||||||
const { adminClient } = useAdminClient();
|
const { environment } = useEnvironment<Environment>();
|
||||||
const href = convertClientToUrl(client, adminClient.baseUrl);
|
const href = convertClientToUrl(client, environment);
|
||||||
|
|
||||||
if (!href) {
|
if (!href) {
|
||||||
return "—";
|
return "—";
|
||||||
|
|
|
@ -7,7 +7,8 @@ describe("convertClientToUrl", () => {
|
||||||
const baseUrl = "http://something";
|
const baseUrl = "http://something";
|
||||||
|
|
||||||
//when
|
//when
|
||||||
const result = convertClientToUrl({ baseUrl }, "");
|
//@ts-ignore
|
||||||
|
const result = convertClientToUrl({ baseUrl }, { serverBaseUrl: "" });
|
||||||
|
|
||||||
//then
|
//then
|
||||||
expect(result).toBe(baseUrl);
|
expect(result).toBe(baseUrl);
|
||||||
|
@ -16,13 +17,17 @@ describe("convertClientToUrl", () => {
|
||||||
it("when root url constrains ${authAdminUrl}", () => {
|
it("when root url constrains ${authAdminUrl}", () => {
|
||||||
//given
|
//given
|
||||||
const rootUrl = "${authAdminUrl}";
|
const rootUrl = "${authAdminUrl}";
|
||||||
const baseUrl = "/else";
|
const adminUrl = "/else";
|
||||||
|
|
||||||
//when
|
//when
|
||||||
const result = convertClientToUrl({ rootUrl, baseUrl }, "/admin");
|
const result = convertClientToUrl(
|
||||||
|
{ rootUrl, adminUrl },
|
||||||
|
//@ts-ignore
|
||||||
|
{ adminBaseUrl: "/admin" },
|
||||||
|
);
|
||||||
|
|
||||||
//then
|
//then
|
||||||
expect(result).toBe("/admin/else");
|
expect(result).toBe("/admin");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("when root url constrains ${authBaseUrl}", () => {
|
it("when root url constrains ${authBaseUrl}", () => {
|
||||||
|
@ -31,10 +36,14 @@ describe("convertClientToUrl", () => {
|
||||||
const baseUrl = "/something";
|
const baseUrl = "/something";
|
||||||
|
|
||||||
//when
|
//when
|
||||||
const result = convertClientToUrl({ rootUrl, baseUrl }, "/admin");
|
const result = convertClientToUrl(
|
||||||
|
{ rootUrl, baseUrl },
|
||||||
|
//@ts-ignore
|
||||||
|
{ serverBaseUrl: "/admin" },
|
||||||
|
);
|
||||||
|
|
||||||
//then
|
//then
|
||||||
expect(result).toBe("/admin/something");
|
expect(result).toBe("/admin");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("when baseUrl when rootUrl is not set", () => {
|
it("when baseUrl when rootUrl is not set", () => {
|
||||||
|
@ -42,7 +51,11 @@ describe("convertClientToUrl", () => {
|
||||||
const baseUrl = "/another";
|
const baseUrl = "/another";
|
||||||
|
|
||||||
//when
|
//when
|
||||||
const result = convertClientToUrl({ rootUrl: undefined, baseUrl }, "");
|
const result = convertClientToUrl(
|
||||||
|
{ rootUrl: undefined, baseUrl },
|
||||||
|
//@ts-ignore
|
||||||
|
{ serverBaseUrl: "" },
|
||||||
|
);
|
||||||
|
|
||||||
//then
|
//then
|
||||||
expect(result).toBe("/another");
|
expect(result).toBe("/another");
|
||||||
|
@ -54,7 +67,11 @@ describe("convertClientToUrl", () => {
|
||||||
const rootUrl = "http://test.nl";
|
const rootUrl = "http://test.nl";
|
||||||
|
|
||||||
//when
|
//when
|
||||||
const result = convertClientToUrl({ rootUrl, baseUrl }, "");
|
const result = convertClientToUrl(
|
||||||
|
{ rootUrl, baseUrl },
|
||||||
|
//@ts-ignore
|
||||||
|
{ serverBaseUrl: "" },
|
||||||
|
);
|
||||||
|
|
||||||
//then
|
//then
|
||||||
expect(result).toBe("http://test.nl/another");
|
expect(result).toBe("http://test.nl/another");
|
||||||
|
@ -65,20 +82,13 @@ describe("convertClientToUrl", () => {
|
||||||
const rootUrl = "http://test.nl";
|
const rootUrl = "http://test.nl";
|
||||||
|
|
||||||
//when
|
//when
|
||||||
const result = convertClientToUrl({ rootUrl, baseUrl: undefined }, "");
|
const result = convertClientToUrl(
|
||||||
|
{ rootUrl, baseUrl: undefined },
|
||||||
|
//@ts-ignore
|
||||||
|
{ serverBaseUrl: "" },
|
||||||
|
);
|
||||||
|
|
||||||
//then
|
//then
|
||||||
expect(result).toBe("http://test.nl");
|
expect(result).toBe("http://test.nl");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should it return ${authBaseUrl} when baseUrl is not set?", () => {
|
|
||||||
//given
|
|
||||||
const rootUrl = "${authBaseUrl}";
|
|
||||||
|
|
||||||
//when
|
|
||||||
const result = convertClientToUrl({ rootUrl, baseUrl: undefined }, "");
|
|
||||||
|
|
||||||
//then
|
|
||||||
expect(result).toBeUndefined();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,23 +1,22 @@
|
||||||
import ClientRepresentation from "@keycloak/keycloak-admin-client/lib/defs/clientRepresentation";
|
import ClientRepresentation from "@keycloak/keycloak-admin-client/lib/defs/clientRepresentation";
|
||||||
|
import type { Environment } from "../environment";
|
||||||
import { joinPath } from "./joinPath";
|
import { joinPath } from "./joinPath";
|
||||||
|
|
||||||
export const convertClientToUrl = (
|
export const convertClientToUrl = (
|
||||||
{ rootUrl, baseUrl }: ClientRepresentation,
|
{ rootUrl, baseUrl }: ClientRepresentation,
|
||||||
adminClientBaseUrl: string,
|
environment: Environment,
|
||||||
) => {
|
) => {
|
||||||
// absolute base url configured, use base url is
|
// absolute base url configured, use base url is
|
||||||
if (baseUrl?.startsWith("http")) {
|
if (baseUrl?.startsWith("http")) {
|
||||||
return baseUrl;
|
return baseUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (rootUrl === "${authAdminUrl}") {
|
||||||
(rootUrl === "${authBaseUrl}" || rootUrl === "${authAdminUrl}") &&
|
return rootUrl.replace(/\$\{(authAdminUrl)\}/, environment.adminBaseUrl);
|
||||||
baseUrl
|
}
|
||||||
) {
|
|
||||||
return rootUrl.replace(
|
if (rootUrl === "${authBaseUrl}") {
|
||||||
/\$\{(authAdminUrl|authBaseUrl)\}/,
|
return rootUrl.replace(/\$\{(authBaseUrl)\}/, environment.serverBaseUrl);
|
||||||
joinPath(adminClientBaseUrl, baseUrl),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rootUrl?.startsWith("http")) {
|
if (rootUrl?.startsWith("http")) {
|
||||||
|
|
Loading…
Reference in a new issue