Site Tools


blog:2021:02:05:setup-npmrc-for-azure-artifacts-in-wsl2

This is an old revision of the document!


Setup npmrc for azure artifacts in WSL2

I recently got a windows machine from work, since more comfortable with mac or linux, so I installed WSL 2 (ubuntu) to setup nodejs development environment in it, I followed the guide, and created the auth token from azure personal access token:

echo -n [personal-access-token] | base64

then added following to .npmrc:

; begin auth token
//pkgs.dev.azure.com/<yourOrganization>/_packaging/<yourFeed>/npm/registry/:username=[ANY_VALUE_BUT_NOT_AN_EMPTY_STRING]
//pkgs.dev.azure.com/<yourOrganization>/_packaging/<yourFeed>/npm/registry/:_password=[BASE64_ENCODED_PERSONAL_ACCESS_TOKEN]
//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=[ANY_VALUE_BUT_NOT_AN_EMPTY_STRING]
//pkgs.dev.azure.com/<yourOrganization>/_packaging/<yourFeed>/npm/:_password=[BASE64_ENCODED_PERSONAL_ACCESS_TOKEN]
//pkgs.dev.azure.com/<yourOrganization>/_packaging/<yourFeed>/npm/:email=npm requires email to be set but doesn't use the value
; end auth token

but this only leads to an error:

npm ERR! code E401
npm ERR! Unable to authenticate, need: Bearer authorization_uri=https://login.windows.net/a1b03033-8a3d-4443-a90b-0f3298ffbf90, Basic realm="https://pkgsprodeau1.pkgs.visualstudio.com/", TFS-Federated

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/dcai/.npm/_logs/2021-02-04T22_20_51_870Z-debug.log

Same npmrc file works on macbook just not wsl2, coworker who directly work on windows told me they use Azure DevOps (formerly VSTS) Auth helper for authentication on windows 10, so I installed the auth helper on windows directly, ran it by providing azure artifacts registry url, it then generated a .npmrc file under c:\Users\[username]\.npmrc, I copied this file to wsl2, and it worked! The generated npmrc file looks like this:

//pkgs.dev.azure.com/[org]/_packaging/[feed]/npm/registry/:username=VssSessionToken
; This is an unencrypted authentication token. Treat it like a password. DO NOT share this value with anyone, including Microsoft support.
//pkgs.dev.azure.com/[org]/_packaging/[feed]/npm/registry/:_password=[generated-token]
; The npm client won't use username and _password without an email set, but the service doesn't use the email value. The following is an arbitrarily made-up address.
//pkgs.dev.azure.com/[org]/_packaging/[feed]/npm/registry/:[email protected]
//[org].pkgs.visualstudio.com/_packaging/[feed]/npm/registry/:username=VssSessionToken
; This is an unencrypted authentication token. Treat it like a password. DO NOT share this value with anyone, including Microsoft support.
//[org].pkgs.visualstudio.com/_packaging/[feed]/npm/registry/:_password=[generated-token]
; The npm client won't use username and _password without an email set, but the service doesn't use the email value. The following is an arbitrarily made-up address.
//[org].pkgs.visualstudio.com/_packaging/[feed]/npm/registry/:[email protected]

So happy I don't have to use powershell and bulky IDE.

Discussion

Enter your comment:
 
blog/2021/02/05/setup-npmrc-for-azure-artifacts-in-wsl2.1612509438.txt.gz · Last modified: 2021-02-05 by dcai