Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export default class ApiClient extends RESTDataSource {
switch (auth.type) {
case 'basic':
if (auth.username || auth.password) {
fetchOptions.headers['Authorization'] = 'Basic ' + base64.encode(auth.username + ":" + auth.password);
fetchOptions.headers['Authorization'] = 'Basic ' + base64.encode((auth.username || "") + ":" + (auth.password || ""));
}

break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export const {{classname}}FetchParamCreator = function (configuration?: Configur
{{#isBasicBasic}}
// http basic authentication required
if (configuration && (configuration.username || configuration.password)) {
localVarHeaderParameter["Authorization"] = "Basic " + btoa(configuration.username + ":" + configuration.password);
localVarHeaderParameter["Authorization"] = "Basic " + btoa((configuration.username || "") + ":" + (configuration.password || ""));
}
{{/isBasicBasic}}
{{#isOAuth}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export default class ApiClient extends RESTDataSource {
switch (auth.type) {
case 'basic':
if (auth.username || auth.password) {
fetchOptions.headers['Authorization'] = 'Basic ' + base64.encode(auth.username + ":" + auth.password);
fetchOptions.headers['Authorization'] = 'Basic ' + base64.encode((auth.username || "") + ":" + (auth.password || ""));
}

break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ constructor({ accessToken, apiKeys, basePath, credentials, encodeParam, encoder,
{{#isBasicBasic}}
this.credentials['{{name}}'] = () => {
return (this.username || this.password)
? btoa(this.username + ':' + this.password)
? btoa((this.username || '') + ':' + (this.password || ''))
: undefined;
};
{{/isBasicBasic}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ export class {{classname}} extends runtime.BaseAPI {
{{#isBasic}}
{{#isBasicBasic}}
if (this.configuration && (this.configuration.username !== undefined || this.configuration.password !== undefined)) {
headerParameters["Authorization"] = "Basic " + btoa(this.configuration.username + ":" + this.configuration.password);
headerParameters["Authorization"] = "Basic " + btoa((this.configuration.username || "") + ":" + (this.configuration.password || ""));
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
}
{{/isBasicBasic}}
{{#isBasicBearer}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class {{classname}} {
{{/isApiKey}}
{{#isBasicBasic}}
if (this.APIConfiguration.username || this.APIConfiguration.password) {
headers['Authorization'] = btoa(this.APIConfiguration.username + ':' + this.APIConfiguration.password);
headers['Authorization'] = 'Basic ' + btoa((this.APIConfiguration.username || '') + ':' + (this.APIConfiguration.password || ''));
}
{{/isBasicBasic}}
{{#isOAuth}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export class {{classname}} {
{{#isBasicBasic}}
// http basic authentication required
if (this.configuration.username || this.configuration.password) {
headerParams['Authorization'] = 'Basic ' + btoa(this.configuration.username + ':' + this.configuration.password);
headerParams['Authorization'] = 'Basic ' + btoa((this.configuration.username || '') + ':' + (this.configuration.password || ''));
}

{{/isBasicBasic}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export class {{classname}} {
{{/isApiKey}}
{{#isBasicBasic}}
if (this.configuration.username || this.configuration.password) {
headers['Authorization'] = 'Basic ' + btoa(this.configuration.username + ':' + this.configuration.password);
headers['Authorization'] = 'Basic ' + btoa((this.configuration.username || '') + ':' + (this.configuration.password || ''));
}

{{/isBasicBasic}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export class {{classname}} extends runtime.BaseAPI {
{{#isBasic}}
{{#isBasicBasic}}
if (this.configuration && (this.configuration.username !== undefined || this.configuration.password !== undefined)) {
headerParameters["Authorization"] = "Basic " + btoa(this.configuration.username + ":" + this.configuration.password);
headerParameters["Authorization"] = "Basic " + btoa((this.configuration.username || "") + ":" + (this.configuration.password || ""));
}
{{/isBasicBasic}}
{{#isBasicBearer}}
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/javascript-apollo/src/ApiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export default class ApiClient extends RESTDataSource {
switch (auth.type) {
case 'basic':
if (auth.username || auth.password) {
fetchOptions.headers['Authorization'] = 'Basic ' + base64.encode(auth.username + ":" + auth.password);
fetchOptions.headers['Authorization'] = 'Basic ' + base64.encode((auth.username || "") + ":" + (auth.password || ""));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: base64 is never imported or declared in this file, so base64.encode(...) throws a ReferenceError whenever basic auth credentials are set. This line predates the PR, but the PR now edits it and keeps the broken call. Use Node's Buffer instead, which needs no import.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At samples/client/petstore/javascript-apollo/src/ApiClient.js, line 151:

<comment>`base64` is never imported or declared in this file, so `base64.encode(...)` throws a ReferenceError whenever basic auth credentials are set. This line predates the PR, but the PR now edits it and keeps the broken call. Use Node's `Buffer` instead, which needs no import.</comment>

<file context>
@@ -148,7 +148,7 @@ export default class ApiClient extends RESTDataSource {
                 case 'basic':
                     if (auth.username || auth.password) {
-                        fetchOptions.headers['Authorization'] = 'Basic ' + base64.encode(auth.username + ":" + auth.password);
+                        fetchOptions.headers['Authorization'] = 'Basic ' + base64.encode((auth.username || "") + ":" + (auth.password || ""));
                     }
 
</file context>
Suggested change
fetchOptions.headers['Authorization'] = 'Basic ' + base64.encode((auth.username || "") + ":" + (auth.password || ""));
fetchOptions.headers['Authorization'] = 'Basic ' + Buffer.from((auth.username || "") + ":" + (auth.password || "")).toString('base64');

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with apollo, so I would change only the default to an empty string.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ export class FakeApi extends runtime.BaseAPI {
const headerParameters: runtime.HTTPHeaders = {};

if (this.configuration && (this.configuration.username !== undefined || this.configuration.password !== undefined)) {
headerParameters["Authorization"] = "Basic " + btoa(this.configuration.username + ":" + this.configuration.password);
headerParameters["Authorization"] = "Basic " + btoa((this.configuration.username || "") + ":" + (this.configuration.password || ""));
}
const consumes: runtime.Consume[] = [
{ contentType: 'application/x-www-form-urlencoded' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ export class FakeApi extends runtime.BaseAPI {
const headerParameters: runtime.HTTPHeaders = {};

if (this.configuration && (this.configuration.username !== undefined || this.configuration.password !== undefined)) {
headerParameters["Authorization"] = "Basic " + btoa(this.configuration.username + ":" + this.configuration.password);
headerParameters["Authorization"] = "Basic " + btoa((this.configuration.username || "") + ":" + (this.configuration.password || ""));
}
const consumes: runtime.Consume[] = [
{ contentType: 'application/x-www-form-urlencoded' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ export class FakeApi extends runtime.BaseAPI {
const headerParameters: runtime.HTTPHeaders = {};

if (this.configuration && (this.configuration.username !== undefined || this.configuration.password !== undefined)) {
headerParameters["Authorization"] = "Basic " + btoa(this.configuration.username + ":" + this.configuration.password);
headerParameters["Authorization"] = "Basic " + btoa((this.configuration.username || "") + ":" + (this.configuration.password || ""));
}
const consumes: runtime.Consume[] = [
{ contentType: 'application/x-www-form-urlencoded' },
Expand Down
Loading