Azure DevOps NPM Authentication

0.10.2 · active · verified Wed Apr 22

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

Warnings

Install

Quickstart

Demonstrates how to integrate `ado-npm-auth` into a project's `package.json` `preinstall` script. This ensures that an authentication token is automatically fetched and updated in the `.npmrc` file before package installation, resolving the 'chicken and egg problem' by temporarily setting the registry to public npm for `ado-npm-auth` itself, and explicitly passing the project's `.npmrc`.

{
  "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

view raw JSON →