Skip to content

Commit cd9476e

Browse files
feat: enable trusted publishing for npm packages (#999)
## Summary Switch npm publishing from token-based authentication to OIDC-based trusted publishing. ### Changes - Remove `npm-token` secret requirement from workflows and publish action - Add `id-token: write` permission for OIDC authentication - Update npm to v11 in the publish action (required for OIDC publishing) - Remove `--provenance` flag and `NODE_AUTH_TOKEN` environment variable ## Post-merge: Configure on npmjs.com Package Settings → Trusted Publisher → GitHub Actions: - **Organization**: `auth0` - **Repository**: `auth0-react` - **Workflow**: `release.yml` - **Environment**: `release` ### Benefits - Eliminates need to manage long-lived npm tokens as secrets - Leverages GitHub's OIDC provider for secure, short-lived credentials - Simplifies secret management across repositories using the shared workflow
1 parent a5dd7b4 commit cd9476e

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

.github/actions/npm-publish/action.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ name: Publish release to npm
33
inputs:
44
node-version:
55
required: true
6-
npm-token:
7-
required: true
86
version:
97
required: true
108
require-build:
@@ -26,6 +24,10 @@ runs:
2624
cache: 'npm'
2725
registry-url: 'https://registry.npmjs.org'
2826

27+
- name: Update npm
28+
shell: bash
29+
run: npm install -g npm@11
30+
2931
- name: Install dependencies
3032
shell: bash
3133
run: npm ci --include=dev
@@ -46,7 +48,6 @@ runs:
4648
else
4749
TAG="latest"
4850
fi
49-
npm publish --provenance --tag $TAG
51+
npm publish --tag $TAG
5052
env:
51-
NODE_AUTH_TOKEN: ${{ inputs.npm-token }}
5253
VERSION: ${{ inputs.version }}

.github/workflows/npm-release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ on:
1515
secrets:
1616
github-token:
1717
required: true
18-
npm-token:
19-
required: true
2018

2119
jobs:
2220
release:
2321
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.pull_request.merged && startsWith(github.event.pull_request.head.ref, 'release/'))
2422
runs-on: ubuntu-latest
2523
environment: release
24+
permissions:
25+
contents: write
26+
id-token: write
2627

2728
steps:
2829
# Checkout the code
@@ -66,7 +67,6 @@ jobs:
6667
node-version: ${{ inputs.node-version }}
6768
require-build: ${{ inputs.require-build }}
6869
version: ${{ steps.get_version.outputs.version }}
69-
npm-token: ${{ secrets.npm-token }}
7070
release-directory: ${{ inputs.release-directory }}
7171

7272
# Create a release for the tag

.github/workflows/release.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,4 @@ jobs:
3333
node-version: 18
3434
require-build: true
3535
secrets:
36-
npm-token: ${{ secrets.NPM_TOKEN }}
3736
github-token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)