Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Unable to Authenticate' when trying to connect to Azure DevOps Artifacts feed through npm; I get an E401 error

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

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.

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 

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] 

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

like image 417
CourtneyH Avatar asked May 02 '19 18:05

CourtneyH


People also ask

How do I run npm on Azure pipeline?

Example: to run npm run myTask -- --users='{"foo":"bar"}' , provide this input: run myTask -- --users="{"foo":"bar"}" . You can either commit a . npmrc file to your source code repository and set its path or select a registry from Azure Artifacts. Select this option to use feeds specified in a .

Had an expired Npmrc token?

Solution #1: manually refresh the token Maybe your token is simply expired. You can simply navigate to Azure DevOps and generate new credentials to be stored in the . npmrc file at user level.


2 Answers

I had an issue where I couldn't connect, even though I had the same .npmrc as other repos on the same machine. Running vsts-npm-auth -config .npmrc just exited, presumably happy with the cached credentials.

However, the credentials it had seemed to be bad. The solution was to force refreshing the token: vsts-npm-auth -config .npmrc -force

like image 128
Simon Clough Avatar answered Oct 06 '22 23:10

Simon Clough


This usually happens when you've recently changed your password. To fix this problem, I ran this command within VS Code's Powershell terminal (any terminal will work)

vsts-npm-auth -config .npmrc 

With doing so, a GUI popped-up where I was able to select the account I wanted to use to authenticate.

I hope this helps!

like image 43
Null Avatar answered Oct 06 '22 22:10

Null