发布到 Nexus 上的私有 NPM 存储库时出现身份验证错误

问题描述 投票:0回答:12

我在发布到托管在我的私人 Nexus 上的私人 npm 注册表时遇到身份验证问题。

我的 Nexus 设置是我有 npm-proxynpm-registry(使用

allowRepublish=false
托管 npm)、npm-snapshots(使用
allowRepublish=true
托管 npm)和 npm-public(包含所有内容的组)其他三个存储库)。

由于我正在开发一个库,所以我正在使用我的快照存储库,因此我可以不断地重新部署相同的版本(类似于 Maven 世界中的快照)。

在我的图书馆项目中,我在 package.json

中设置了此选项
"publishConfig": {
    "registry": "https://my.nexus.com/repository/npm-snapshots/"
}

接下来,我创建了 .npmrc 文件,其中包含以下内容:

registry=https://my.nexus.com/repository/npm-public/
_auth=RVhBTVBMRQ==

通过此设置,我可以毫无问题地发布项目。然而,令我困扰的是,我的密码(只是 base64 编码)存储在文件中,应该提交,但由于其中的凭据,我无法提交它。

我尝试登录到 npm 注册表并从 .npmrc 中删除了 auth 行

npm adduser --registry=https://my.nexus.com/repository/npm-snapshots --always-auth

我收到回复了

Logged in as myusername on https://my.nexus.com/repository/npm-snapshots.

但是,当我尝试运行

npm publish
时,我得到:

npm ERR! code E401
npm ERR! Unable to authenticate, need: BASIC realm="Sonatype Nexus Repository Manager"
npm verb exit [ 1, true ]
npm timing npm Completed in 6867ms

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\XXXX\AppData\Roaming\npm-cache\_logs\2019-07-30T19_31_01_598Z-debug.log

现在在我的另一个项目(正在使用这个库)中,我只是创建了内容为

registry=https://nexus.mjamsek.com/repository/npm-public/
的 .npmrc 文件并运行命令
npm adduser --registry=https://my.nexus.com/repository/npm-public --always-auth
,我就能够下载已发布的包。

但是,发布还是不行,不知道为什么。

编辑 2019 年 7 月 31 日:在我的活动领域列表中,我还有 npm 不记名令牌领域

node.js npm nexus
12个回答
55
投票

当您执行

npm login
npm adduser
时,NPM 客户端会创建一个身份验证令牌,该令牌将在将来向注册表发出的请求中使用。默认 NXRM 配置仅允许“本地身份验证领域”,它无法识别 NPM 的令牌。请确保您有 npm Bearer Token Realm 处于活动状态。


37
投票
npm adduser

的注册表 URL 末尾添加一个斜杠,否则

npm
会截断 URL 的最后一段,并且它将无法工作。
    


8
投票
_auth=

替换为

btoa('username:userpassword')
的输出,它对我有用。
我确实使用了 chrome 中的 btoa,如下所示。

enter image description here


7
投票

registry=https://my.nexus.com/repository/npm-snapshots/

最好删除任何多余的内容,事先备份,在我的情况下,我的文件仅包含:

strict-ssl=false

然后你就可以
再次

npm login --registry=https://my.nexus.com/repository/npm-public/

如果这不起作用,您还可以使用curl绕过npm登录,请查看

这个救命帖子


4
投票
“npm 错误!代码 E401 npm 错误!无法验证,需要:BASICrealm=“Sonatype Nexus Repository Manager”

一旦我修复了它,问题就解决了。 对于那些正在寻找生成 _auth 的命令的人。这是:

btoa('用户名:用户密码')


2
投票


1
投票


1
投票

托管(您的私人包的存储库)
  • 代理(公共包的代理,例如
  • https://registry.npmjs.org
  • Group(其他 2 个存储库的组。Nexus 会自动将公共包的请求转发到代理,并将私有包转发到托管)
  • 像这样:

Nexus Setup 在我的用例中,我需要为

hosted 和 group

包含两次身份验证配置才能使其正常工作。 registry=https://my-private-nexus/repository/npm-group/ [email protected] always-auth=true //my-private-nexus/repository/npm-group/:_auth=<auth-token> //my-private-nexus/repository/npm-hosted/:_auth=<auth-token>

已成功测试节点 v18.16.0、npm 9.5.1、Nexus OSS 3.53.1-02


0
投票


0
投票
https://my.nexus.com/repository/npm-snapshots/

”之类的注册表但在

package-lock.json
中具有不同的关系引用是一个问题:“
https://some.previous.nexus.com/repository/npm-snapshots/
”。
我在仔细检查调试日志后发现了它。删除 

package-lock.json

对我的情况有帮助。

    


-1
投票

npm ERR! code ENEEDAUTH npm ERR! need auth This command requires you to be logged in. npm ERR! need auth You need to authorize this machine using `npm adduser`

如果我使用nvm降级到node12/npm6,它可以工作。我更喜欢一个无需降级的工作解决方案,但现在它可以让我继续前进。

更新:

我们终于弄清楚了(不久前,但我忘记了这个答案)。在用户目录中的 .npmrc 文件中,我们需要添加/更改授权配置条目。

之前:

_auth={base64 encoded username:password}

之后:

//{path to private repository}:_auth={base64 encoded username:password}

    


-3
投票
匿名

访问,它将从您的私人注册表中提取。

© www.soinside.com 2019 - 2024. All rights reserved.