> ## Documentation Index
> Fetch the complete documentation index at: https://buildcharts.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# NpmAuthenticate@v1

> Authenticate private npm feeds in Docker builds.

This plugin obtains credentials from the environment or Azure Artifacts Credential
Provider. It writes an authenticated `.npmrc` as a BuildKit secret and leaves your
source file unchanged.
It follows the same model as [npmAuthenticate@0](https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/npm-authenticate-v0?view=azure-pipelines) in Azure DevOps.

## Usage

```yaml theme={"theme":{"light":"plastic","dark":"plastic"}}
plugins:
  - NpmAuthenticate@v1
```

Run `buildcharts generate` before `docker buildx bake`. Mount the secret when
installing packages:

```dockerfile theme={"theme":{"light":"plastic","dark":"plastic"}}
WORKDIR /app
COPY package.json package-lock.json ./
RUN --mount=type=secret,id=npmrc,target=/app/.npmrc,required=true \
    npm ci
```

The npm charts already mount this secret for pnpm.

## What it does

* Reads default and scoped Azure Artifacts registries from `.npmrc`.
* Uses endpoint credentials from the environment, otherwise an environment token, otherwise the Azure Artifacts Credential Provider.
* Validates credentials returned by the provider. If rejected, forces one refresh before failing.
* Writes npm credentials to `.buildcharts/secrets/npmrc` and adds the generated Bake secret.
* Preserves existing credentials when no environment credentials replace them.

## Environment variables

* `NPM_AUTHENTICATE_WORKING_FILE`
* `NPM_AUTHENTICATE_HELPER_VERSION`
* `ARTIFACTS_CREDENTIALPROVIDER_EXTERNAL_FEED_ENDPOINTS`
* `ARTIFACTS_CREDENTIALPROVIDER_ACCESSTOKEN`
* `AZURE_ARTIFACTS_ENV_ACCESS_TOKEN`
* `SYSTEM_ACCESSTOKEN`
* `VSS_NUGET_ACCESSTOKEN` (legacy)
* `VSS_NUGET_EXTERNAL_FEED_ENDPOINTS` (legacy)

> [!NOTE]
>
> `ARTIFACTS_CREDENTIALPROVIDER_*` is the preferred prefix. The older `VSS_NUGET_*` variables are legacy names kept for compatibility. See the [Artifacts Credential Provider environment variables](https://github.com/microsoft/artifacts-credprovider#environment-variables).

## Notes

* The plugin only authenticates Azure DevOps-hosted npm feeds.
* If no matching npm sources are found, the plugin skips authentication.

## Read more

* [Azure DevOps npmAuthenticate@0](https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/npm-authenticate-v0?view=azure-pipelines)
* [Configure npm authentication for Azure Artifacts](https://learn.microsoft.com/en-us/azure/devops/artifacts/npm/npmrc)
* [Microsoft Artifacts Credential Provider](https://github.com/microsoft/artifacts-credprovider)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.