From 9d0bee9c59de6978f42e7e98f83ac78c35a6ca45 Mon Sep 17 00:00:00 2001 From: Jon Koops Date: Mon, 13 Feb 2023 14:03:47 +0100 Subject: [PATCH] Handle requests with a `FormData` payload (#17035) --- js/libs/keycloak-admin-client/src/resources/agent.ts | 4 +++- js/libs/keycloak-admin-client/src/resources/clients.ts | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/js/libs/keycloak-admin-client/src/resources/agent.ts b/js/libs/keycloak-admin-client/src/resources/agent.ts index 91da741a54..52f2ace1f2 100644 --- a/js/libs/keycloak-admin-client/src/resources/agent.ts +++ b/js/libs/keycloak-admin-client/src/resources/agent.ts @@ -209,6 +209,8 @@ export class Agent { } else if (requestHeaders.get("content-type") === "text/plain") { // Pass the payload as a plain string if the content type is 'text/plain'. requestOptions.body = payload as unknown as string; + } else if (payload instanceof FormData) { + requestOptions.body = payload; } else { // Otherwise assume it's JSON and stringify it. requestOptions.body = JSON.stringify( @@ -216,7 +218,7 @@ export class Agent { ); } - if (!requestHeaders.has("content-type")) { + if (!requestHeaders.has("content-type") && !(payload instanceof FormData)) { requestHeaders.set("content-type", "application/json"); } diff --git a/js/libs/keycloak-admin-client/src/resources/clients.ts b/js/libs/keycloak-admin-client/src/resources/clients.ts index d3b1dc32ae..0c0f1180ae 100644 --- a/js/libs/keycloak-admin-client/src/resources/clients.ts +++ b/js/libs/keycloak-admin-client/src/resources/clients.ts @@ -979,7 +979,10 @@ export class Clients extends Resource<{ realm?: string }> { }, }); - public uploadKey = this.makeUpdateRequest<{ id: string; attr: string }, any>({ + public uploadKey = this.makeUpdateRequest< + { id: string; attr: string }, + FormData + >({ method: "POST", path: "/{id}/certificates/{attr}/upload", urlParamKeys: ["id", "attr"], @@ -987,7 +990,7 @@ export class Clients extends Resource<{ realm?: string }> { public uploadCertificate = this.makeUpdateRequest< { id: string; attr: string }, - any + FormData >({ method: "POST", path: "/{id}/certificates/{attr}/upload-certificate",