Azure DevOps Authentication CLI Wrapper

0.14.0 · active · verified Wed Apr 22

The `azureauth` package serves as a Node.js wrapper for the `microsoft-authentication-cli`, designed to streamline Azure Active Directory (AAD) authentication processes within Node.js applications and npm scripts. Its primary utility lies in automating the download and management of the underlying `azureauth` CLI executable, ensuring it's scoped locally to `./node_modules/.bin`. This unique approach allows for multiple versions of the AzureAuth CLI to coexist on a single machine, mitigating versioning conflicts. As of version 0.14.0, the package is in active pre-1.0 development, indicating an iterative release cadence with potential API changes. It is particularly useful for scenarios requiring Personal Access Token (PAT) generation for Azure DevOps (ADO) feeds, offering a cross-platform alternative to Windows-only tools like `vsts-npm-auth`. While `@azure/identity` provides a comprehensive SDK for general Azure authentication, `azureauth` specifically targets CLI-driven AAD authentication tasks.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to programmatically obtain an Azure DevOps Personal Access Token using `adoPat`.

import { adoPat } from 'azureauth';

async function getAzureDevOpsPat() {
  try {
    const pat = await adoPat({
      displayName: 'my-cli-auth-pat',
      organization: process.env.AZDO_ORG_URL ?? 'https://dev.azure.com/myorganization',
      promptHint: 'Please authenticate in your browser',
      scope: ['vso.packaging_write'], // Example scope
    });
    console.log('Successfully generated ADO PAT.');
    // In a real application, securely store or use the PAT
    // console.log('PAT:', pat); // Do not log PAT to console in production!
    return pat;
  } catch (error) {
    console.error('Failed to get ADO PAT:', error);
    throw error;
  }
}

getAzureDevOpsPat()
  .then(() => console.log('ADO PAT process completed.'))
  .catch(() => console.error('Exiting due to PAT generation failure.'));

view raw JSON →