npm publish with a token? Move to trusted publishing before January
npm trusted publishing uses short-lived OIDC credentials instead of stored tokens.
Published here · 3 sources · Resume reading
npm trusted publishing replaces stored tokens with short-lived, workflow-specific OIDC credentials. Tokens that bypass 2FA will lose direct publish access around January 2027 [1]. The two migration paths are trusted publishing (OIDC) and staged publishing (human approval).
Configure trusted publishing on npm
- Go to your package on npmjs.com.
- Under Settings, find Trusted publishers.
- Add a GitHub Actions workflow: specify the repository, workflow file, and optionally an environment.
The npm registry now accepts publishes from that workflow using OIDC.
Update your workflow
Set id-token: write to let the workflow request an OIDC token. The npm CLI exchanges that token for a short-lived registry credential [3]:
name: Publish
on:
release:
types: [published]
permissions:
contents: read
id-token: write
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: npm publishYou do not need --provenance. Publishing through trusted publishing from GitHub Actions generates provenance automatically [1] [2].
Verify it works
Check the package page on npmjs.com. Packages published via trusted publishing show provenance information linking to the source repository and build.
Restrict token access
After trusted publishing works, restrict traditional token access in the package settings. This reduces risk from leaked or stolen tokens [1].
Provenance proves which repository and workflow built the package. It does not prove the code is safe; it proves where it came from [2].
Send this to the friend who still publishes npm packages with a stored token.
Keep this guide
Questions about this guide
What happens to my existing tokens?
Granular tokens that bypass 2FA will lose direct publish access around January 2027. Switch to trusted publishing or staged publishing before then.
Does this work with private repos?
No. Provenance attestations are only generated for public repositories and public packages.
Sources
- npm docs: trusted publishing for npm packagesdocs.npmjs.com
- npm docs: generating provenance statementsdocs.npmjs.com