use admin client instead of fetch (#20774)

This commit is contained in:
Erik Jan de Wit 2023-06-12 12:50:53 +02:00 committed by GitHub
parent db315b59f6
commit 911663b65c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 36 deletions

View file

@ -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,
});
}
} catch (error) {
setError("discoveryError", {
type: "manual",

View file

@ -82,14 +82,14 @@ 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) };
if (!(payload instanceof FormData)) {
// Omit url parameters and query parameters from payload
const omittedKeys = ignoredKeys
? [...allUrlParamKeys, ...queryParamKeys].filter(
@ -98,6 +98,7 @@ export class Agent {
: [...allUrlParamKeys, ...queryParamKeys];
payload = omit(payload, omittedKeys);
}
// Transform keys of both payload and queryParams
if (keyTransform) {

View file

@ -116,10 +116,11 @@ export class IdentityProviders extends Resource<{ realm?: string }> {
});
public importFromUrl = this.makeRequest<
{
| {
fromUrl: string;
providerId: string;
},
}
| FormData,
Record<string, string>
>({
method: "POST",