尝试通过npm连接到Azure DevOps Artifacts时“无法进行身份验证";我收到E401错误 [英] 'Unable to Authenticate' when trying to connect to Azure DevOps Artifacts feed through npm; I get an E401 error

查看:582
本文介绍了尝试通过npm连接到Azure DevOps Artifacts时“无法进行身份验证";我收到E401错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试连接到Azure DevOps Artifacts提要,但是我一直收到E401错误.

I'm trying to connect to a Azure DevOps Artifacts feed, but I keep getting an E401 error.

我在另一台计算机上尝试过,并且连接正常.我已经卸载,然后重新安装了Node.js,但仍然出现错误.

I've tried on a different computer and it connected just fine. I've uninstalled, and reinstalled my Node.js, and I still got the error.

以下是我在运行"npm install"时遇到的错误

Below is the error I get when I run 'npm install'

npm ERR! code E401
npm ERR! Unable to authenticate, need: Bearer authorization_uri=https://login.windows.net/*********, Basic realm="https://pkgsprodcus1.pkgs.visualstudio.com/", TFS-Federated

以下是添加到.npmrc文件中的内容

Below is what was added to the .npmrc file

registry=https://[org].pkgs.visualstudio.com/_packaging/[feed].Npm/npm/registry
//pkgs.dev.azure.com/[org]/_packaging/[feed].Npm/npm/registry/:_authToken=[token]
//pkgs.dev.azure.com/[org]/_packaging/[feed].Npm/npm/:_authToken=[token]

将我的信息添加到.npmrc文件并运行'npm install'后,我希望能够连接到供稿.

I expected to be connected to the feed after adding my info to the .npmrc file, and running 'npm install'

推荐答案

Microsoft更新将VSTS的名称更改为Azure DevOps时,他们还更改了许多URL.大多数旧版本仍会重定向,但似乎您上面的.npmrc文件中存在不匹配项.更改 first 行中的URI以匹配其他行,因此如下所示:

When Microsoft updated changed the name of VSTS to Azure DevOps, they also changed many of the URLs. Most of the old ones still redirect, but it looks like you have a mismatch in your .npmrc file above. Change the URI in the first line to match the other lines, so it looks like this:

registry=https://pkgs.dev.azure.com/[org]/_packaging/[feed].Npm/npm/registry

那应该解除对你的封锁.

That should unblock you.

请注意,如果您在同一文件中同时拥有注册表,并且该文件已提交到源代码管理中,则还将凭据保存到源代码管理中.此处的最佳实践是将.npmrc保留在项目根中,只有 具有第一行,该行告诉npm连接到哪个注册表.然后,在~/.npmrc处创建一个新文件(如果您使用的是Windows,则可以使用git bash帮助将其放置在正确的位置),然后仅添加另外两行,即带有您的凭据的行.这样可以使您的凭据在计算机上保持本地状态,并且可以安全地提交带有注册表注释的文件.

As a note, if you have both the registry and your credentials in the same file, and that file is being committed to source control, you are also saving your credentials to source control. Best practice here is to keep .npmrc in your project root that only has that first line, the one that tells npm which registry to connect to. Then, create a new file at ~/.npmrc (if you are using Windows you can use git bash to help put it in the right place) and just add the other two lines, the ones with your credentials. This will keep your creds local to your machine and the file with the registry note can safely be committed.

此外,请记住,您从Azure软件包注册表生成的凭据最多可以使用90天,因此在某些时候,您将再次收到未授权的错误消息,并且需要在本地文件.

Also, remember that the credentials you generate from the Azure package registry are good for 90 days at the most, so at some point you will get the unauthorized error message again and you will need to update the credentials in your local ~/.npmrc file.

这篇关于尝试通过npm连接到Azure DevOps Artifacts时“无法进行身份验证";我收到E401错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆