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:
df8b552f5f (diff-e91249994e03dd6af8c6bee4ff7d8381)
This commit is contained in:
Chris Couzens 2020-01-24 06:16:35 +00:00 committed by Esteban Gehring
parent 09fd494836
commit b77bffeae1

View File

@ -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}}