当我发出 npm 命令时遇到此问题,我收到一条消息,指出它无法通过 npm 注册表(托管在 Azure DevOps 中)进行身份验证,我怀疑这可能是因为它没有生成授权标头并发送它连同请求。
例如,当我发出这些命令:npm ping或 时npm install,它会发出此抱怨。
npm ERR! code E401
npm ERR! Unable to authenticate, your authentication token seems to be invalid.
npm ERR! To correct this please trying logging in again with:
npm ERR! npm login
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\blah\AppData\Roaming\npm-cache\_logs\2020-01-15T06_30_45_484Z-debug.log
Run Code Online (Sandbox Code Playgroud)
我有一个不同的 npm 注册表(托管在不同的 Azure DevOps 实例下),当我发出这些命令时,它可以工作,并且在查看 Fiddler 下的请求时,我注意到工作请求的授权标头包含用于访问注册表的用户名和密码,但是,非工作请求(向非工作注册表)没有它。
除了 npmrc 文件中的注册表 url、用户名和密码之外,它们与此处所示的几乎相同:
registry=https://devops.blah/npm/registry/
always-auth=true
strict-ssl=false
; Treat this auth token like a password. Do not share it with anyone, including Microsoft support. This token expires on or before 02/03/2020.
; begin auth token
//devops.blah/npm/registry/:username=blah
//devops.blah/npm/registry/:_password=blahpassword
//devops.blah/npm/registry/:email=npm requires email to be set but doesn't use the value
//devops.blah/npm/:username=blah
//devops.blah/npm/:_password=blahpassword
//devops.blah/npm/:email=npm requires email to be set but doesn't use the value
; end auth token
Run Code Online (Sandbox Code Playgroud)
npm 命令是在同一台计算机上和同一命令提示符会话中发出的(当我这样做时,我会切换到相关的 npmrc 配置文件)。
什么可能导致 npm 命令在向非工作注册表发出的请求中不包含授权标头?
| 归档时间: |
|
| 查看次数: |
1665 次 |
| 最近记录: |