use admin client instead of fetch (#20774)
This commit is contained in:
parent
db315b59f6
commit
911663b65c
3 changed files with 19 additions and 36 deletions
|
@ -5,9 +5,6 @@ import { HelpItem } from "ui-shared";
|
|||
|
||||
import { adminClient } from "../../admin-client";
|
||||
import { JsonFileUpload } from "../../components/json-file-upload/JsonFileUpload";
|
||||
import { useRealm } from "../../context/realm-context/RealmContext";
|
||||
import { addTrailingSlash } from "../../util";
|
||||
import { getAuthorizationHeaders } from "../../utils/getAuthorizationHeaders";
|
||||
import { DiscoveryEndpointField } from "../component/DiscoveryEndpointField";
|
||||
import { DiscoverySettings } from "./DiscoverySettings";
|
||||
|
||||
|
@ -15,7 +12,6 @@ export const OpenIdConnectSettings = () => {
|
|||
const { t } = useTranslation("identity-providers");
|
||||
const id = "oidc";
|
||||
|
||||
const { realm } = useRealm();
|
||||
const {
|
||||
setValue,
|
||||
setError,
|
||||
|
@ -38,25 +34,10 @@ export const OpenIdConnectSettings = () => {
|
|||
formData.append("file", new Blob([JSON.stringify(obj)]));
|
||||
|
||||
try {
|
||||
const response = await fetch(
|
||||
`${addTrailingSlash(
|
||||
adminClient.baseUrl
|
||||
)}admin/realms/${realm}/identity-provider/import-config`,
|
||||
{
|
||||
method: "POST",
|
||||
body: formData,
|
||||
headers: getAuthorizationHeaders(await adminClient.getAccessToken()),
|
||||
}
|
||||
const result = await adminClient.identityProviders.importFromUrl(
|
||||
formData
|
||||
);
|
||||
if (response.ok) {
|
||||
const result = await response.json();
|
||||
setupForm(result);
|
||||
} else {
|
||||
setError("discoveryError", {
|
||||
type: "manual",
|
||||
message: response.statusText,
|
||||
});
|
||||
}
|
||||
setupForm(result);
|
||||
} catch (error) {
|
||||
setError("discoveryError", {
|
||||
type: "manual",
|
||||
|
|
|
@ -82,22 +82,23 @@ export class Agent {
|
|||
const baseParams = this.getBaseParams?.() ?? {};
|
||||
|
||||
// Filter query parameters by queryParamKeys
|
||||
const queryParams = queryParamKeys
|
||||
? pick(payload, queryParamKeys)
|
||||
: undefined;
|
||||
const queryParams =
|
||||
queryParamKeys.length > 0 ? pick(payload, queryParamKeys) : undefined;
|
||||
|
||||
// Add filtered payload parameters to base parameters
|
||||
const allUrlParamKeys = [...Object.keys(baseParams), ...urlParamKeys];
|
||||
const urlParams = { ...baseParams, ...pick(payload, allUrlParamKeys) };
|
||||
|
||||
// Omit url parameters and query parameters from payload
|
||||
const omittedKeys = ignoredKeys
|
||||
? [...allUrlParamKeys, ...queryParamKeys].filter(
|
||||
(key) => !ignoredKeys.includes(key)
|
||||
)
|
||||
: [...allUrlParamKeys, ...queryParamKeys];
|
||||
if (!(payload instanceof FormData)) {
|
||||
// Omit url parameters and query parameters from payload
|
||||
const omittedKeys = ignoredKeys
|
||||
? [...allUrlParamKeys, ...queryParamKeys].filter(
|
||||
(key) => !ignoredKeys.includes(key)
|
||||
)
|
||||
: [...allUrlParamKeys, ...queryParamKeys];
|
||||
|
||||
payload = omit(payload, omittedKeys);
|
||||
payload = omit(payload, omittedKeys);
|
||||
}
|
||||
|
||||
// Transform keys of both payload and queryParams
|
||||
if (keyTransform) {
|
||||
|
|
|
@ -116,10 +116,11 @@ export class IdentityProviders extends Resource<{ realm?: string }> {
|
|||
});
|
||||
|
||||
public importFromUrl = this.makeRequest<
|
||||
{
|
||||
fromUrl: string;
|
||||
providerId: string;
|
||||
},
|
||||
| {
|
||||
fromUrl: string;
|
||||
providerId: string;
|
||||
}
|
||||
| FormData,
|
||||
Record<string, string>
|
||||
>({
|
||||
method: "POST",
|
||||
|
|
Loading…
Reference in a new issue