From f2e4eb2747e2d987ad82cb12b0e59cd0cd811331 Mon Sep 17 00:00:00 2001 From: Robert Poienar Date: Fri, 13 Nov 2026 12:00:01 +0200 Subject: [PATCH] ci: publish to NuGet with trusted publishing instead of an API key The release run for 1.0.10 failed with 403 "The specified API key is invalid, has expired, or does not have permission": the workflow still pushed with the NUGET_DEPLOY_KEY secret. A trusted publishing policy on nuget.org is only used when the workflow asks for it, so the job now requests an OIDC token (id-token: write) and exchanges it for a short-lived key with NuGet/login. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release.yml | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 495de05a7..6ba1bf1c8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -8,16 +8,30 @@ on: jobs: publish-nuget-package: runs-on: ubuntu-latest + permissions: + contents: read + id-token: write # lets NuGet/login request a GitHub OIDC token for trusted publishing steps: - uses: actions/checkout@v3 - name: Setup .NET Core SDK uses: actions/setup-dotnet@v2.1.1 - - name: Upload to Nuget - env: - NUGET_DEPLOY_KEY: ${{ secrets.NUGET_DEPLOY_KEY }} + - name: Pack run: | cd websocket-sharp/websocket-sharp-netstandard dotnet pack altwebsocket-sharp.csproj -c release - dotnet nuget push bin/release/AltWebSocketSharp.1.0.10.nupkg --api-key $NUGET_DEPLOY_KEY --source https://api.nuget.org/v3/index.json + + # Exchanges the OIDC token for a short-lived API key, using the trusted + # publishing policy on nuget.org. NUGET_USER is the nuget.org profile + # name (not the email) of the account that created that policy. + - name: NuGet login + uses: NuGet/login@v1 + id: nuget-login + with: + user: ${{ secrets.NUGET_USER }} + + - name: Upload to Nuget + run: | + cd websocket-sharp/websocket-sharp-netstandard + dotnet nuget push bin/release/AltWebSocketSharp.1.0.10.nupkg --api-key ${{ steps.nuget-login.outputs.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json