Skip to content

fix(typescript-...): Fix basic auth without username or password - #25462

Open
coffeemakr wants to merge 3 commits into
OpenAPITools:masterfrom
coffeemakr:fix-basic-auth-undefined
Open

coffeemakr wants to merge 3 commits into
OpenAPITools:masterfrom
coffeemakr:fix-basic-auth-undefined

Conversation

@coffeemakr

@coffeemakr coffeemakr commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Missing password or username in multiple typescript generators concat the undefined to the string resulting in a invalid auth header.

typescript-inversify also misses a 'Basic ' prefix

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Summary by cubic

Fixes basic auth in TypeScript and JavaScript generators so a missing username or password no longer produces an invalid Authorization header, and restores the missing Basic prefix in the typescript-inversify generator.

  • Defaults missing username or password values to empty strings instead of concatenating undefined.
  • Updates Javascript-Apollo, Javascript-Flowtyped, the Javascript apollo library, typescript-angular, typescript-fetch, typescript-inversify, typescript-jquery, typescript-nestjs, and typescript-playwright templates, and regenerates affected samples.

Written for commit bd78791. Summary will update on new commits.

View guided diff

@coffeemakr coffeemakr changed the title [typescript]: Fix basic auth without username or password fix(typescript-...): Fix basic auth without username or password Oct 29, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment •

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.

All reported issues were addressed across 9 files

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

coffeemakr and others added 2 commits October 29, 2026 12:22
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment

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.

1 issue found across 4 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. 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. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="samples/client/petstore/javascript-apollo/src/ApiClient.js">

<violation number="1" location="samples/client/petstore/javascript-apollo/src/ApiClient.js:151">
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.</violation>
</file>

Tip: Review your code locally with the cubic CLI to iterate faster.

View guided diff | Re-trigger cubic

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.

@coffeemakr

Copy link
Copy Markdown
Contributor Author

CC @TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @topce (2018/10) @akehir (2019/07) @petejohansonxo (2019/11) @amakhrov (2020/02) @davidgamero (2022/03) @mkusaka (2022/04) @joscha (2024/10) @KannaKim (2026/07)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant