You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
@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?
@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
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 my@example.com
$ 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=my@example.com\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 my@example.com
$ npm config set //npm.example.com/:username admin
$ npm config set //npm.example.com/:_password YWRtaW4=
Aha, seems like the issue here is that npm config set email my@example.com 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 trueecho"email=my@example.com">>~/.npmrc
npm config set _auth YWRtaW46YWRtaW4=
npm config set _auth=xxx will fail if email is not set.
npm config set email=x@y.com will work, even if _auth is not set.
npm config set email=x@y.com _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=x@y.com _auth=xxx
Activity
ljharb commentedon Dec 8, 2020
Does it still happen with v7.0.15?
bradbeck commentedon Dec 8, 2020
Not sure, I haven't found a way to update npm in the node docker image.
ljharb commentedon Dec 8, 2020
npm install -g npm@7?bradbeck commentedon Dec 8, 2020
The node docker image fails to update npm that way. Some permissions issue.
I have confirmed that it still happens for npm@7.0.15 on MacOS.
isaacs commentedon Dec 10, 2020
This is happening because
xxxis not a valid_authfield.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:
isaacs commentedon Dec 11, 2020
Note that
_authmust be a base64-encodedusername:passwordpair. It's then saved with the username and password as shown.bradbeck commentedon 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 commentedon Dec 11, 2020
@isaacs The methodology you describe does not seem to work for
~/.npmrcandnpm config set foo=bar._authstill gets removed but it not replaced with username and password as you describe.bradbeck commentedon Dec 11, 2020
In versions prior to npm v7 we used to be able to use the following to configure authentication:
With npm v7+ it does not appear to be possible to use
npm config set ...to setemailor_auth. A sequence like the following is required to get authentication working:or
isaacs commentedon Dec 15, 2020
Aha, seems like the issue here is that
npm config set email my@example.comis failing, that's the bug here. Email should be able to be set separate from credentials. This works in the meantime:isaacs commentedon Dec 15, 2020
Will be fixed on next npm release, with @npmcli/config@1.2.8
Support multiple set/get/deletes in npm config
Support multiple set/get/deletes in npm config
Support multiple set/get/deletes in npm config
isaacs commentedon Dec 16, 2020
So, just to clarify:
npm config set _auth=xxxwill fail ifemailis not set.npm config set email=x@y.comwill work, even if_authis not set.npm config set email=x@y.com _auth=xxxwill always work (ie, adding two configs in one command).npm config --registry=https://npm.internal/ set email=x@y.com _auth=xxxSupport multiple set/get/deletes in npm config
@npmcli/config@1.2.8
belun commentedon Oct 18, 2022
still happening in npm8