npm login --always-auth doesn't add the appropriate entry to the config
10,053
It seems that "always-auth" is not needed at all when using "npm login" command, but only if you use basic authentication.
My .npmrc looks like: (using npm login command)
registry=http://localhost:8081/artifactory/api/npm/npm-virtual/
//localhost:8081/artifactory/api/npm/npm-virtual/:_authToken=<TOKEN_MASKED>
Also, from Artifactory's "Set Me Up" page, it does not seem necessary, only if you use basic authentication:
Author by
Danny Lo
Updated on June 04, 2022Comments
-
Danny Lo almost 2 years
I use npm version 6.13.7 and Artifactory repository manager. The registry URL is defined in
.npmrc
in my project folder:root@2892c246217b:/build# cat .npmrc registry=https://<masked>/artifactory/api/npm/<masked>
I want to use an authentication token created via
npm login
command:root@2892c246217b:/build# npm login --always-auth Username: <masked> Password: Email: (this IS public) <masked> Logged in as <masked> on https://<masked>/artifactory/api/npm/<masked>.
Now an install should work, however it doesn't:
root@2892c246217b:/build# npm install npm ERR! code E401 npm ERR! Unable to authenticate, need: Basic realm="Artifactory Realm" npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/2020-02-04T17_28_52_957Z-debug.log
I check
/root/.npmrc/
and see thatalways-auth
entry is missing. So I add it vianpm config
:root@2892c246217b:/build# npm config set always-auth true
And fetching works fine:
root@2892c246217b:/build# npm --verbose install npm info it worked if it ends with ok npm verb cli [ '/usr/local/bin/node', npm verb cli '/usr/local/bin/npm', npm verb cli '--verbose', npm verb cli 'install' ] npm info using [email protected] npm info using [email protected] npm verb npm-session fd8f804800679bcc npm info lifecycle <masked>@2.0.0~preinstall: <masked>@2.0.0 npm timing stage:loadCurrentTree Completed in 10ms npm timing stage:loadIdealTree:cloneCurrentTree Completed in 0ms npm timing stage:loadIdealTree:loadShrinkwrap Completed in 4ms npm http fetch GET 200 https://<masked>/artifactory/api/npm/<masked>/<masked> 109ms npm http fetch GET 200 https://<masked>/artifactory/api/npm/<masked>/<masked> 149ms npm http fetch GET 200 https://<masked>/artifactory/api/npm/<masked>/<masked>/-/<masked>.tgz 46ms npm http fetch GET 200 https://<masked>/artifactory/api/npm/<masked>/<masked> 309ms npm http fetch GET 200 https://<masked>/artifactory/api/npm/<masked>/<masked> 738ms ...
Is that a bug in
npm
or am I just doing something wrong?-
JCE over 3 yearsIt's a bug in npm: github.com/npm/cli/issues/704 I also had to add it manually with
npm config
-
Danny Lo over 3 years@JCE thanks, i've subscribed to this issue
-
-
Danny Lo about 4 yearsBut if
always-auth
is not the culprit, why elsenpm install
doesn't work afternpm login
? -
Yonatan Brand about 4 years@DannyLo I tried to reproduce the behavior you encountered, but in my case, it worked without "always-auth". Try to delete your current .npmrc (make sure you back it up first) and try the following steps: 1. npm config set registry <ARTIFACTORY_URL:PORT/artifactory/api/npm/NPM_REPOSITORY_NAME> 2. npm login * Please try to use it without the "always-auth"
-
Danny Lo about 4 yearsMy ~/.npmrc file looks yours now:
registry=...
in the first line and//https://<masked>/artifactory/api/npm/<masked>:_authToken=<MASKED>
in the second. I still get error code 401