Azure DevOps NPM Authentication
raw JSON →The `ado-npm-auth` package is a command-line utility designed to streamline authentication for Node.js projects interacting with private npm registries hosted on Azure DevOps (ADO). It automates the process of fetching authentication tokens using the underlying `azureauth-cli` (wrapped via `node-azureauth`) and securely updates the user's `.npmrc` file. A key differentiator from its predecessor, `vsts-npm-auth`, is its cross-platform compatibility, leveraging the cross-platform nature of `azureauth-cli`. Currently at version 0.10.2, the package is under active development. Its primary use case involves integration into project lifecycle scripts, such as `preinstall`, to ensure continuous access to private ADO feeds without manual token management.
Common errors
error npm ERR! 401 Unauthorized ↓
npm exec ado-npm-auth (or your configured preinstall script) to refresh the authentication token. Ensure the command is executed correctly, especially considering the 'chicken and egg' warning for npm exec. error npm ERR! command not found: ado-npm-auth ↓
npm_config_registry=https://registry.npmjs.org npm exec ado-npm-auth. This ensures ado-npm-auth is fetched from the public npm registry before it can authenticate to your private ADO feed. error Error: Command failed: <path-to-node>/node_modules/ado-npm-auth/bin/ado-npm-auth.js ↓
azureauth-cli. Ensure you have appropriate permissions in Azure DevOps, and that your azureauth-cli installation (managed by ado-npm-auth's dependency) is functional. Try running the command with increased verbosity if the tool supports it. Warnings
gotcha When running `ado-npm-auth` via `npm exec` or `npx` within a project that already has its `.npmrc` configured to point to a private Azure DevOps feed, a 'chicken and egg problem' can occur. The package manager might attempt to resolve `ado-npm-auth` itself from the private registry before authentication has happened, leading to failures. ↓
gotcha The `ado-npm-auth` tool relies on the `azureauth-cli` for token acquisition. While `ado-npm-auth` manages its dependency on the `azureauth` npm package, issues with the underlying `azureauth-cli` installation or environment configuration (e.g., path issues) could indirectly affect `ado-npm-auth`'s functionality. ↓
Install
npm install ado-npm-auth yarn add ado-npm-auth pnpm add ado-npm-auth Quickstart
{
"name": "my-ado-project",
"version": "1.0.0",
"description": "Example project using Azure DevOps npm feed.",
"main": "index.js",
"scripts": {
"preinstall": "npm_config_registry=https://registry.npmjs.org npm exec ado-npm-auth -- -c ./.npmrc",
"start": "node index.js"
},
"dependencies": {},
"devDependencies": {},
"repository": {
"type": "git",
"url": "git+https://github.com/microsoft/ado-npm-auth.git"
},
"author": ""
}
// Example .npmrc in project root
// registry=https://pkgs.dev.azure.com/your-org/your-project/_packaging/your-feed/npm/registry/
// always-auth=true