Best VSTS NPM Auth
raw JSON → 1.0.5 verified Sat Apr 25 auth: no javascript
A CLI tool that refreshes Azure DevOps Artifacts and GitHub Packages npm authentication on your machine. It reads your project .npmrc, obtains an access token via Azure CLI (no app registration required), and writes short-lived tokens (valid ~1 hour) to your user ~/.npmrc and optionally project .yarnrc.yml. Current stable version is 1.0.5. Key differentiators: simple setup with no app registration, supports Yarn Berry, and works with scoped registries. Works on Node.js with Azure CLI.
Common errors
error Error: Azure CLI not found. Please install Azure CLI and login with 'az login'. ↓
cause Azure CLI is not installed or not in PATH.
fix
Install Azure CLI from https://docs.microsoft.com/en-us/cli/azure/install-azure-cli and run 'az login'.
error Error: No registries found in .npmrc. ↓
cause The provided .npmrc does not contain any registry entries.
fix
Ensure your .npmrc includes registry settings for Azure DevOps or GitHub Packages.
error Error: Failed to refresh token. Check your Azure login status. ↓
cause Azure CLI session expired or not logged in.
fix
Run 'az login' and then retry the tool.
Warnings
gotcha Access tokens are valid for approximately 1 hour. Re-run the tool if you see 401 errors. ↓
fix Run 'best-vsts-npm-auth' again to refresh tokens.
gotcha Tokens are written only to the user ~/.npmrc, not the project .npmrc, unless configured otherwise. ↓
fix Expect tokens in ~/.npmrc. Check project .npmrc for any overriding settings.
Install
npm install best-vsts-npm-auth yarn add best-vsts-npm-auth pnpm add best-vsts-npm-auth Imports
- AuthClient wrong
const AuthClient = require('best-vsts-npm-auth')correctimport { AuthClient } from 'best-vsts-npm-auth' - refreshToken wrong
const refreshToken = require('best-vsts-npm-auth').refreshTokencorrectimport { refreshToken } from 'best-vsts-npm-auth' - parseNpmrc wrong
const { parseNpmrc } = require('best-vsts-npm-auth')correctimport { parseNpmrc } from 'best-vsts-npm-auth'
Quickstart
// Install globally
npm i -g best-vsts-npm-auth
# Run in project directory
best-vsts-npm-auth .
# Or specify .npmrc path
best-vsts-npm-auth -n /path/to/.npmrc
# Also update Yarn Berry config
best-vsts-npm-auth -y ./.yarnrc.yml .