You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法使用GitHub应用生成的访问令牌上传NuGet包至GitHub Packages

无法使用GitHub App令牌或GitHub Actions令牌上传NuGet包至GitHub Packages
  • 核心问题:使用程序化生成的访问令牌(GitHub App生成的令牌、GitHub Actions的GITHUB_TOKEN)上传NuGet包到组织的GitHub Packages仓库时,始终返回403 Forbidden错误;但使用具备最低权限的个人访问令牌(PAT)可成功上传。

相关环境信息

  • 组织账号为免费版;
  • GitHub App已开启所有可用权限,且安装至所有仓库。

测试用PowerShell脚本

$pkg = "PACKAGE_NAME_TEST.3.0.0-beta-2.nupkg"

$apiKey = "GENERATED_APP_TOKEN" ##此处使用PAT可正常工作

nuget sources add -name "testing_local" `
                  -Source "https://nuget.pkg.github.com/ORGANIZATION_NAME_HERE/index.json" `
                  -Username ORGANIZATION_NAME_HERE `
                  -Password $apiKey

nuget setApiKey $apiKey -source "testing_local"
nuget push $pkg -NonInteractive -Source "testing_local"
nuget sources remove -name "testing_local" 

脚本执行后的错误输出

PS C:\Users\xxxx\desktop> C:\Users\xxxx\Desktop\test package upload.ps1
Package source with Name: testing_local added successfully.
The API Key 'API_KEY' was saved for 'https://nuget.pkg.github.com/xxxx/index.json'.
Pushing xxxx.3.0.0-beta-2.nupkg to 'https://nuget.pkg.github.com/xxxx'...
  PUT https://nuget.pkg.github.com/xxxx/
WARNING: Your request could not be authenticated by the GitHub Packages service. Please ensure your access token is valid and has the appropriate scopes configured.
  Forbidden https://nuget.pkg.github.com/xxxx/ 792ms
nuget : Response status code does not indicate success: 403 (Forbidden).
At C:\Users\xxxx\Desktop\test package upload.ps1:15 char:1
+ nuget push $pkg -NonInteractive -Source "testing_local"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Response status...03 (Forbidden).:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
Package source with Name: testing_local removed successfully.

GitHub Actions配置及错误

工作流配置

name: Release Build Pipeline
on: 
  push:
    branches:
      - dev
  workflow_dispatch:
permissions:
  contents  : read
  packages  : write

执行后的错误输出

Pushing Nuget files to Nuget Package Repo
Package source with Name: For_E:\gh\01\_work\amp-rewards\amp-rewards\_work\build\Deploy\EnticentAdminDashboard.3.0.0-beta-17f0dfc1641a4a608f2ead7a6e7d342f84bb8116.nupkg added successfully.
Pushing xxxx.3.0.0-beta-17f0df.nupkg to 'https://nuget.pkg.github.com/xxxx'...
  PUT https://nuget.pkg.github.com/xxx/
WARNING: Your request could not be authenticated by the GitHub Packages service. Please ensure your access token is valid and has the appropriate scopes configured.
  Forbidden https://nuget.pkg.github.com/xxxx/ 30335ms
Response status code does not indicate success: 403 (Forbidden).
Push Exit Code: 1
Package source with Name: For_E:\gh\01\_work\xxxxx\xxxx\_work\build\Deploy\xxxx.3.0.0-beta-17f0df.nupkg removed successfully.
Exiting with Code: 1
Error: Process completed with exit code 1.

目前仅能使用PAT完成上传,但这并非长期可行方案,恳请提供解决办法。

内容的提问来源于stack exchange,提问作者Kenneth Garza

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 22:09:24