Skip to content

feat(config/getNetworkConfigs): load auth info#10491

Merged
zkochan merged 4 commits into
mainfrom
feat-load-auth-info
Jan 22, 2026
Merged

feat(config/getNetworkConfigs): load auth info#10491
zkochan merged 4 commits into
mainfrom
feat-load-auth-info

Conversation

@KSXGitHub

Copy link
Copy Markdown
Contributor

In order to resolve merge conflicts ahead of time for #10385

In order to resolve merge conflicts ahead of time
for #10385
@KSXGitHub KSXGitHub requested a review from zkochan as a code owner January 21, 2026 11:22
Copilot AI review requested due to automatic review settings January 21, 2026 11:22

Copilot AI 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.

Pull request overview

This PR adds authentication information loading capabilities to the pnpm config system. It introduces a new parseAuthInfo module that handles parsing various authentication formats (_authToken, _auth base64, username/password pairs, and tokenHelper commands) from configuration files, and integrates this functionality into the existing getNetworkConfigs function.

Changes:

  • Adds parsing and validation for registry authentication information from config files
  • Extends Config interface to include default registry authentication at the root level
  • Adds comprehensive test coverage for the new authentication parsing functionality

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
config/config/src/parseAuthInfo.ts New module for parsing authentication information from various formats, including validation for tokenHelper commands
config/config/test/parseAuthInfo.test.ts Comprehensive test suite for parseAuthInfo functionality
config/config/src/getNetworkConfigs.ts Updated to parse and return authentication information alongside SSL configs and registries, plus new getDefaultAuthInfo function
config/config/test/getNetworkConfigs.test.ts Added test cases for authentication info extraction from network configs
config/config/src/Config.ts Extended Config interface to include AuthInfo properties at root level
config/config/src/index.ts Integrated getDefaultAuthInfo to populate default registry auth in pnpmConfig

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread config/config/src/index.ts
Comment thread config/config/src/getNetworkConfigs.ts
Comment thread config/config/test/parseAuthInfo.test.ts
Comment thread config/config/src/getNetworkConfigs.ts
Comment thread config/config/src/Config.ts
Comment thread config/config/src/parseAuthInfo.ts
Comment thread config/config/test/parseAuthInfo.test.ts
Comment thread config/config/src/parseAuthInfo.ts
Comment thread config/config/test/getNetworkConfigs.test.ts
Comment thread config/config/src/parseAuthInfo.ts
}

for (const key in authInfoInputs) {
const authInfo = parseAuthInfo(authInfoInputs[key])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why this can't happen inside tryParseAuthSetting?

@KSXGitHub KSXGitHub Jan 22, 2026

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.

why this can't happen inside tryParseAuthSetting?

tryParseAuthSetting mirrors the existing tryParseSslSetting. Both functions only return the setting names to target rather than the setting values. And both functions only take the keys of rawConfig, not the values.

However, there is a difference between "auth" and "ssl":

  • "Ssl" is all strings, so their raw values can be assigned directly to sslConfigs as-is.
  • But "auth" is structured, so their raw values must be assign to the indirect object named authInfoInputs first.

Why not just assign to authInfos directly, as soon as the field is determined?

Because there are multiple fields that determine username and password (_auth, username, _password). The code must know all the fields in order to decide which fields override which fields. Furthermore, username without a _password or _password without a username result in authUserPass: undefined.

See also:

function getAuthUserPass ({
authPairBase64,
authUsername,
authPassword,
}: Pick<AuthInfoInput, 'authPairBase64' | 'authUsername' | 'authPassword'>): AuthUserPass | undefined {
if (authPairBase64) {
const pair = atob(authPairBase64)
const colonIndex = pair.indexOf(':')
if (colonIndex < 0) {
throw new AuthMissingSeparatorError()
}
const username = pair.slice(0, colonIndex)
const password = pair.slice(colonIndex + 1)
return { username, password }
}
if (authUsername && authPassword) {
return { username: authUsername, password: authPassword }
}
return undefined
}

@zkochan

zkochan commented Jan 22, 2026

Copy link
Copy Markdown
Member

There are some misspelling issues. See the error

@KSXGitHub

Copy link
Copy Markdown
Contributor Author

There are some misspelling issues. See the error

Should be fixed now.

Copilot AI 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.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread config/config/src/parseAuthInfo.ts
Comment thread config/config/test/parseAuthInfo.test.ts
Comment thread config/config/src/parseAuthInfo.ts
@zkochan zkochan merged commit d019a7c into main Jan 22, 2026
12 of 15 checks passed
@zkochan zkochan deleted the feat-load-auth-info branch January 22, 2026 13:40
zkochan pushed a commit that referenced this pull request Feb 12, 2026
* chore(deps): add `libnpmpublish` to catalog

* chore(deps): install `libnpmpublish`

* feat: publishableManifest (wip)

* feat: publishableManifest (wip)

* chore(cspell): libnpmpublish

* test: fix

* feat: validate field and version

* chore: @npm/types

* chore: todo

* refactor: reorganize

* feat: transformRequiredFields

* chore(deps): patch `libnpmpublish`

* fix: `BaseManifest.config`

* fix: eslint

* chore(git): revert a patch that doesn't work

This reverts commit 45f2c6a.

We will use type casting

* feat: `engines.runtime`

* feat: normalize bin

* fix: `bin === ''`

* test: fix

* refactor: inference friendly

* feat: `peerDependenciesMeta`

* refactor: group into a directory

* refactor: use `ramda.pipe`

* refactor: less intrusive type assertion

* feat!: returning `ExportedManifest`

* refactor: remove unnecessary file

* docs: add a todo

* refactor: getNetworkConfigs (#10458)

Some tests are added as a bonus

* feat: `publishPackedPkg` (wip)

* feat: replace `\t` with 4 spaces

* fix: newline

* fix: newline

* refactor: extract `FailedToPublishError`

* test: FailedToPublishError

* feat: registryConfigKeys

* feat: `publishPackedPkg` (wip)

* feat(config/getNetworkConfigs): load auth info

* feat(config/getNetworkConfigs): load auth info (#10491)

* feat: `publishPackedPkg` (wip)

* refactor: extract a `static` function

* fix: inheritance, override, and merge

* feat: `executeTokenHelper`

* fix: use the visible `globalWarn`

* feat: add options

* feat: add more options

* docs: more links

* fix: private packages

* fix: --dry-run

* feat: log more things

* fix: name

* fix: tag

* refactor: remove extraneous `assertPublicPackage`

* feat: use `publishPackedPkg` for directories

* refactor: require only necessary fields

* refactor: extractManifestFromPacked

* fix: extractManifestFromPacked

* test: extractManifestFromPacked

* feat: isTarballPath

* feat: use `publishPackedPkg` for tarballs

* style: add an empty line for clarity

* refactor: remove unnecessary works

* feat: --otp

* feat: PNPM_CONFIG_OTP

* feat: oidc

* test: fix name collision

* fix: eslint

* test: disable a false test

* feat: set `provenance`

* docs(todo): auto provenance

* refactor: run oidc in `createPublishOptions`

* fix: correct auth keys for `libnpmpublish`

* docs: changeset

* fix: incorrect `password` field

* fix: typo, grammar

* chore(git): resolve merge conflict ahead of time

In preparation for #10385

* fix: field name

* fix(config): decoding `_password`

* fix: edge case of partial `cert`/`key`

* fix: ensure `registry` always match its config key

* fix: `_password`

* test: correct a name

* test: more specific assertions

* fix: grammar

* docs(changeset): fix grammar

* docs: fix grammar

* fix: clean up after failure

* test: fix windows

* feat(provenance): auto detect

* refactor: consistent name

* fix: correct error names

* refactor: extract the `provenance` code

* feat: show code and body of an error

* refactor: use `encodeURIComponent`

* refactor: rename a type

* refactor: use the try-catch model

* refactor: move `normalizeBinObject`

* refactor: split `oidc` into `idToken` and `authToken`

* refactor: run `next` on `stream`'s `'end'`

* fix: use the correct encoding

* feat: guard against weird names

* test: `transform/engines`

Closes #10599

* test: `transformPeerDependenciesMeta`

Closes #10600

* refactor: dependency inject the `Date` too

* refactor: export an interface

* test: oidc

Closes #10598

* refactor: re-arrange imports

* refactor: remove unnecessary type casts

* refactor: improve test
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.

3 participants