From b77bffeae14f4d33761ae15bc4cca8030da945d7 Mon Sep 17 00:00:00 2001 From: Chris Couzens Date: Fri, 24 Jan 2020 06:16:35 +0000 Subject: [PATCH] Typescript axios: remove use of `btoa` (#5098) btoa (binary to ascii), is a javascript function to base64 encode a string. Axios is usable both from node and from the browser. But the btoa function is available only in the browser. This meant that any client that used basic auth was broken in node. Axios has its own method of encoding basic auth credentials. This method works in both the browser and node. https://github.com/axios/axios/blame/v0.19.2/README.md#L318 By using this method, the generated client works in node and in the browser. This solves this comment on this issue. https://github.com/OpenAPITools/openapi-generator/issues/3049#issuecomment-498278966 I have validated this change within a personal project: https://github.com/ccouzens/create-vdc-with-edge-portal-api-demo/commit/df8b552f5f8b7528bd0b003b1c5b5558dd05eabf#diff-e91249994e03dd6af8c6bee4ff7d8381 --- .../src/main/resources/typescript-axios/apiInner.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/resources/typescript-axios/apiInner.mustache b/modules/openapi-generator/src/main/resources/typescript-axios/apiInner.mustache index dc839d57cf7..deaeb9319ec 100644 --- a/modules/openapi-generator/src/main/resources/typescript-axios/apiInner.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-axios/apiInner.mustache @@ -78,7 +78,7 @@ export const {{classname}}AxiosParamCreator = function (configuration?: Configur {{#isBasicBasic}} // http basic authentication required if (configuration && (configuration.username || configuration.password)) { - localVarHeaderParameter["Authorization"] = "Basic " + btoa(configuration.username + ":" + configuration.password); + localVarRequestOptions["auth"] = { username: configuration.username, password: configuration.password }; } {{/isBasicBasic}} {{#isBasicBearer}}