简体   繁体   English

如何使用多个 npm 身份验证令牌

[英]How to use multiple npm auth tokens

I need to set up multiple npm tokens that are under two different scopes我需要设置两个不同范围内的多个 npm 令牌

@scope1:registry=https://registry.npmjs.org/
@scope2:registry=https://registry.npmjs.org/
//registry.npmjs.org/:_authToken=${NPM_TOKEN}

I have tried to add the an auth Token to each scope我试图将身份验证令牌添加到每个范围

@scope1:registry=https://registry.npmjs.org/:_authToken=${TOKEN_1}
@scope2:registry=https://registry.npmjs.org/:_authToken=${TOKEN_2}

But I am getting a 405 when I am trying to install a package.但是当我尝试安装软件包时,我得到了405

I tried looking up the docs: https://docs.npmjs.com/using-npm/config but I cannot find a way to specify different tokens for different scopes我尝试查找文档: https ://docs.npmjs.com/using-npm/config 但我找不到为不同范围指定不同令牌的方法

I contacted the npm support and got the following response:我联系了 npm 支持并得到以下回复:

Users cannot mix-and-match auth for a single registry.用户不能混合和匹配单个注册表的身份验证。 We recommend having a single npm user that's granted access to all of the packages and to use the token for that user.我们建议让一个 npm 用户被授予访问所有包的权限并为该用户使用令牌。

This is a bit of a hacky answer - but it works.这是一个有点老套的答案 - 但它有效。 At least on github packages where I am using it.至少在我使用它的 github 包上。 I assume it works on npmjs.org but I don't have any private packages there to test.我认为它可以在 npmjs.org 上运行,但我没有任何私有包可以测试。

@scope1:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=TOKEN1

@scope2:registry=https://npm.pkg.github.com:443
//npm.pkg.github.com:443/:_authToken=TOKEN2

@scope3:registry=https://npm.pkg.github.com:0443
//npm.pkg.github.com:0443/:_authToken=TOKEN3

Basically, just make them different registries by specifying a port even though it is the same port.基本上,只需通过指定端口来使它们成为不同的注册表,即使它是同一个端口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM