0

I'm trying to connect to my private npm feed from Mac. I generated credentials from Connect to feed menu and they looked like that:

; begin auth token
//pkgs.dev.azure.com/<yourorganization>/_packaging/<yourfeed>/npm/registry/:username=ANYTHING-BUT-EMPTY
//pkgs.dev.azure.com/<yourorganization>/_packaging/<yourfeed>/npm/registry/:_password=BASE64-ENCODED-PAT-GOES-HERE
//pkgs.dev.azure.com/<yourorganization>/_packaging/<yourfeed>/npm/registry/:email=npm requires email to be set but doesn't use the value
//pkgs.dev.azure.com/<yourorganization>/_packaging/<yourfeed>/npm/:username=ANYTHING-BUT-EMPTY
//pkgs.dev.azure.com/<yourorganization>/_packaging/<yourfeed>/npm/:_password=BASE64-ENCODED-PAT-GOES-HERE
//pkgs.dev.azure.com/<yourorganization>/_packaging/<yourfeed>/npm/:email=npm requires email to be set but doesn't use the value
; end auth token

I placed that in .npmrc file in my project and it didn't work. When im trying to do npm install I get this error:

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

I also placed these credentials in $HOME directory which also didn't solve the issue. What am I doing wrong? In which .npmrc file should they be? Should I run additional commands to use them?

Alexandr Accord
  • 105
  • 1
  • 9

3 Answers3

1

How to connect NPM to azure artifacts feed on Mac?

The .npmrc file which including the credentials should set int the $home directory.

Check the document Use npm to store JavaScript packages in Azure DevOps Services or TFS:

On your development machine, you also have an .npmrc file in $home for Linux or Mac systems, or $env.HOME for Windows systems. This .npmrc file should contain credentials for all of the registries that you need to connect to. The npm client will look at your project's .npmrc file, discover the registry, and fetch matching credentials from $home/.npmrc or $env.HOME/.npmrc. The next section will discuss credential acquisition.

Since it still not work for you, you could check if your npmrc token has expired. In your .npmrc, I found you are using BASE64-ENCODED-PAT-GOES-HERE, it seems you are using the PAT, but in the 90-day token type. The .npmrc file should like:

//pkgs.dev.azure.com/<yourorganization>/_packaging/<yourfeed>/npm/registry/:username=ANYTHING-BUT-EMPTY
//pkgs.dev.azure.com/<yourorganization>/_packaging/<yourfeed>/npm/registry/:_password=BASE64-ENCODED-PAT-GOES-HERE
//pkgs.dev.azure.com/<yourorganization>/_packaging/<yourfeed>/npm/registry/:email=YOUREMAIL@EXAMPLE.COM
//pkgs.dev.azure.com/<yourorganization>/_packaging/<yourfeed>/npm/registry/:always-auth=true

Check Create a token that lasts longer than 90 days.

If you still have 401 error, please check if your PAT has expired and convert to Base64String or do not have enough permission.

Hope this helps.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • The problem was in registry address that in npmrc inside project folder. Somehow address that worked fine at work didn't work at home and when i checked that on portal it was a little bit different. – Alexandr Accord Nov 18 '19 at 17:20
  • 1
    I resolved it. Your answer didn't helped me because problem was with that microsoft changed registry string on "connect to feed" page and i was not very attentive so i didn't noticed that it was different. After updating registry address everything starts work just fine so it's look like problem was with that. from "....visualstudio...." to "pkgs.dev.azure.com......". – Alexandr Accord Nov 20 '19 at 07:13
  • 1
    @AlexandrAccord, Glad to know that you have resolved your question, would you mind share your solution as answer, so that could help other community members who get the same issues? Thanks. – Leo Liu Nov 20 '19 at 07:19
0

In my case for some reason I needed to surround the base 64 encoded token with double quotes and square bracket to make it work.

//pkgs.dev.azure.com/<yourorganization>/_packaging/<yourfeed>/npm/registry/:_password="[BASE64-ENCODED-PAT-GOES-HERE]"

Note the : "[ and at the end ]".

after adding that, all worked just fine.

I'm running MacOS Big Sur 11.6

destined
  • 324
  • 1
  • 3
  • 9
0

To be able to connect to the ADO npm feed without saving the credentials, you can get an access token in ADO, and pass that as a parameter to the following script:

setup-npmrc-feed-auth.bash

#!/bin/bash
DecodedPat=$1
NPMAuthIdent=$(echo -ne "$DecodedPat" | base64);

pnpm config set registry https://pkgs.dev.azure.com/{orgName}/{projectName}/_packaging/{feedName}/npm/registry/ --location=global

pnpm config set //pkgs.dev.azure.com/{orgName}/{projectName}/_packaging/{feedName}/npm/registry/:username {orgName} --location=global
pnpm config set //pkgs.dev.azure.com/{orgName}/{projectName}/_packaging/{feedName}/npm/registry/:_password $NPMAuthIdent --location=global
pnpm config set //pkgs.dev.azure.com/{orgName}/{projectName}/_packaging/{feedName}/npm/registry/:email some@email.com --location=global
pnpm config set //pkgs.dev.azure.com/{orgName}/{projectName}/_packaging/{feedName}/npm/:username {orgName} --location=global
pnpm config set //pkgs.dev.azure.com/{orgName}/{projectName}/_packaging/{feedName}/npm/:_password $NPMAuthIdent --location=global
pnpm config set //pkgs.dev.azure.com/{orgName}/{projectName}/_packaging/{feedName}/npm/:email some@email.com --location=global

in your workspace, have the following:

.npmrc

registry=https://pkgs.dev.azure.com/{orgName}/{projectName}/_packaging/{feedName}/npm/registry/

auto-install-peers=true
strict-peer-dependencies=false
always-auth=true
Mor Shemesh
  • 2,689
  • 1
  • 24
  • 36