[typescript-fetch] add bearer token support (#3097)

* [typescript-fetch] added Bearer token support

* [typescript-fetch] executed ./bin/openapi3/typescript-fetch-petstore-all.sh

* [typescript-fetch] executed ./bin/typescript-fetch-petstore-all.sh
This commit is contained in:
Ken Rosaka 2019-06-06 16:58:31 +02:00 committed by Esteban Marin
parent 6660b74247
commit cd85210835

View File

@ -107,10 +107,21 @@ export class {{classname}} extends runtime.BaseAPI {
{{/headerParams}}
{{#authMethods}}
{{#isBasic}}
{{#isBasicBasic}}
if (this.configuration && (this.configuration.username !== undefined || this.configuration.password !== undefined)) {
headerParameters["Authorization"] = "Basic " + btoa(this.configuration.username + ":" + this.configuration.password);
}
{{/isBasicBasic}}
{{#isBasicBearer}}
if (this.configuration && (this.configuration.accessToken || this.configuration.apiKey)) {
const token = this.configuration.accessToken || this.configuration.apiKey;
const tokenString = typeof token === 'function' ? token("{{name}}", [{{#scopes}}"{{{scope}}}"{{^-last}}, {{/-last}}{{/scopes}}]) : token;
if (tokenString) {
headerParameters["Authorization"] = `Bearer ${tokenString}`;
}
}
{{/isBasicBearer}}
{{/isBasic}}
{{#isApiKey}}
{{#isKeyInHeader}}