GeezerVison is showing github.com — [BUG] npm config removes _auth from .npmrc · Issue #2300 · npm/cli
[BUG] npm config removes _auth from .npmrc #2300Labels Bugthing that needs fixingRelease 7.xwork is associated with a specific npm 7 release DescriptionCurrent Behavior:
npm config set <anykey> <anyvalue> will result in _auth=... being removed from .npmrc
Expected Behavior:
npm config set foo bar should not result in _auth=... being removed from .npmrc
Steps To Reproduce:
echo '_auth="xxx"' >> ~/.npmrc
cat ~/.npmrc to see _auth="xxx" is there
npm config set foo bar
cat ~/.npmrc to see _auth="xxx" is gone
Environment:
Docker image node:15.3.0
Node: 15.3.0
npm: 7.0.14 Reacted by Joe Tom, Abhilash Ghosh, Elouan Keryell-Even and Drazen Bjelovuk Activityljharb commented on Dec 8, 2020 Does it still happen with v7.0.15? bradbeck commented on Dec 8, 2020 Not sure, I haven't found a way to update npm in the node docker image. ljharb commented on Dec 8, 2020 bradbeck commented on Dec 8, 2020 The node docker image fails to update npm that way. Some permissions issue.
I have confirmed that it still happens for [email protected] on MacOS. Reacted by Jordan Harband isaacs commented on Dec 10, 2020 This is happening because xxx is not a valid _auth field.
In order for credentials to be saved, a username, email address, and password must all be set, and it is re-saved to the config file scoped only to the proper registry.
This works as expected, for example:
$ echo $'_auth=dXNlcjpwYXNz\[email protected]' > foo.npmrc; node . config set foo=bar --userconfig=foo.npmrc ; cat foo.npmrc
foo=bar
//registry.npmjs.org/:username=user
//registry.npmjs.org/:_password="cGFzcw=="
//registry.npmjs.org/:[email protected]
//registry.npmjs.org/:always-auth=false
isaacs commented on Dec 11, 2020 Note that _auth must be a base64-encoded username:password pair. It's then saved with the username and password as shown. bradbeck commented on Dec 11, 2020 @isaacs This appears to be a change in behavior relative to versions prior to npm v7. Is the methodology you describe backward compatible? If so, how far back? bradbeck commented on Dec 11, 2020 @isaacs The methodology you describe does not seem to work for ~/.npmrc and npm config set foo=bar. _auth still gets removed but it not replaced with username and password as you describe. Reacted by Elouan Keryell-Even and Drazen Bjelovuk bradbeck commented on Dec 11, 2020 In versions prior to npm v7 we used to be able to use the following to configure authentication:
$ npm config set registry http://npm.example.com/
$ npm config set always-auth true
$ npm config set email [email protected]
$ npm config set _auth YWRtaW46YWRtaW4=
With npm v7+ it does not appear to be possible to use npm config set ... to set email or _auth. A sequence like the following is required to get authentication working:
$ npm config set registry http://npm.example.com/
$ echo '[email protected]\n_auth="YWRtaW46YWRtaW4="' >> ~/.npmrc
$ npm config set always-auth true
or
$ npm config set registry http://npm.example.com/
$ npm config set //npm.example.com/:always-auth true
$ npm config set //npm.example.com/:email [email protected]
$ npm config set //npm.example.com/:username admin
$ npm config set //npm.example.com/:_password YWRtaW4=
Reacted by Drazen Bjelovuk isaacs commented on Dec 15, 2020 Aha, seems like the issue here is that npm config set email [email protected] is failing, that's the bug here. Email should be able to be set separate from credentials. This works in the meantime:
npm config set registry http://npm.example.com/
npm config set always-auth true
echo "[email protected]" >> ~/.npmrc
npm config set _auth YWRtaW46YWRtaW4= isaacs commented on Dec 15, 2020 isaacs commented on Dec 16, 2020 So, just to clarify:
npm config set _auth=xxx will fail if email is not set.
npm config set [email protected] will work, even if _auth is not set.
npm config set [email protected] _auth=xxx will always work (ie, adding two configs in one command).
- in all cases, the authentication settings will still be scoped to a given registry, so it's important to either set that registry config first, or include it in the command cli config, like
npm config --registry=https://npm.internal/ set [email protected] _auth=xxx
Reacted by Brad Beck and Drazen Bjelovuk belun commented on Oct 18, 2022
MetadataMetadataBugthing that needs fixingRelease 7.xwork is associated with a specific npm 7 release DevelopmentNo branches or pull requestsIssue actions
|