Skip to content

Commit

Permalink
[typescript-fetch] add bearer token support (#3097)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
ken210 authored and macjohnny committed Jun 6, 2019
1 parent 6660b74 commit cd85210
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down

0 comments on commit cd85210

Please sign in to comment.