Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NUGET_AUTH_TOKEN does not work for official NuGet repository #526

Closed
2 of 5 tasks
na1307 opened this issue May 14, 2024 · 8 comments
Closed
2 of 5 tasks

NUGET_AUTH_TOKEN does not work for official NuGet repository #526

na1307 opened this issue May 14, 2024 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@na1307
Copy link

na1307 commented May 14, 2024

Description:
I tried publishing the package using source-url and NUGET_AUTH_TOKEN, but it failed with the error API key not found.

warn : No API Key was provided and no API Key could be found for 'https://www.nuget.org/api/v2/package'. To save an API Key for a source use the 'setApiKey' command.
Pushing Bluehill.Hangul.2.1.0-gh-actions-test.1.nupkg to 'https://www.nuget.org/api/v2/package'...
  PUT https://www.nuget.org/api/v2/package/
  Unauthorized https://www.nuget.org/api/v2/package/ 303ms
error: Response status code does not indicate success: 401 (An API key must be provided in the 'X-NuGet-ApiKey' header to use this service).

Task version:
v4

Platform:

  • Ubuntu
  • macOS
  • Windows

Runner type:

  • Hosted
  • Self-hosted

Repro steps:
https://github.com/na1307/Bluehill.Hangul/blob/9702f8b7432c8cbf088a829cef16c661a40c4efa/.github/workflows/dotnet.yml

Expected behavior:
The package should publish normally.

Actual behavior:
The package won't be published with an error about missing an API key.

@na1307 na1307 added bug Something isn't working needs triage labels May 14, 2024
@aparnajyothi-y
Copy link

Hello @na1307, Thank you for creating this issue and we will look into it :)

@gowridurgad gowridurgad self-assigned this Jul 3, 2024
@gowridurgad
Copy link

gowridurgad commented Jul 10, 2024

Hi @na1307, The issue occurs because an API key was not correctly provided when attempting to push the package to NuGet. We were able to reproduce the issue by providing an incorrect API key. We suspect that the issue is due to one of the following reasons:

  1. Missing API Key: The API key was not provided in the command, leading to an unauthorized request.
  2. Incorrect API Key: An incorrect or expired API key was used, resulting in a 401 Unauthorized error.

To resolve this issue, please follow these steps:

  1. Ensure that the API key is correctly set in your NuGet configuration.
  2. If the API key is missing or incorrect, generate a new API key
  3. Store the API key as a secret in your GitHub repository settings.
  4. Modify your workflow file to include the API key when pushing the package.
env:
        NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}

Following these steps will ensure that the correct API key is used when pushing the package in your GitHub Actions workflow.

@gowridurgad
Copy link

Hi @na1307, Just a gentle reminder regarding this issue, If you have any updates or need further assistance, Please let us know.

1 similar comment
@gowridurgad
Copy link

Hi @na1307, Just a gentle reminder regarding this issue, If you have any updates or need further assistance, Please let us know.

@na1307
Copy link
Author

na1307 commented Aug 6, 2024

But I provided correct api key. Nonetheless, I received a 401 error.

@gowridurgad
Copy link

Hi @na1307, we have successfully pushed the package to NuGet. A screenshot is attached for your reference. Here are the steps that helped us publish the package:

  1. Regenerate the API Key: The API key might expire, so be sure to regenerate it by logging in to nuget.org, navigating to your API keys, and regenerating the key.
  2. Rename the .csproj File: Change the name of the .csproj file and update the corresponding files before attempting to publish the package again.
  3. Check the Permissions:
    • Verify API Key Scope on NuGet.org: Log in to your NuGet.org account, go to your profile, select "API Keys," and ensure the scope of the API key includes the "Push" permission.
    • Inspect Workflow Permissions: Ensure your GitHub Actions workflow has the necessary permissions to use the API key:

    permissions:  
             contents: read
              packages: write

Please follow the above steps to resolve your issue and let us know if you are still facing any problems.

Screenshot 2024-08-12 at 12 59 01 PM Screenshot 2024-08-14 at 11 47 26 AM

@na1307
Copy link
Author

na1307 commented Aug 16, 2024

According to README.md:

- uses: actions/setup-dotnet@v4
  with:
    dotnet-version: 3.1.x
- name: Publish the package to nuget.org
  run: dotnet nuget push */bin/Release/*.nupkg -k $NUGET_AUTH_TOKEN -s https://api.nuget.org/v3/index.json
  env:
    NUGET_AUTH_TOKEN: ${{ secrets.NUGET_TOKEN }}

Note: It's the only way to push a package to nuget.org feed for macOS/Linux machines due to API key config store limitations.

Sorry, I found out that the way to publish packages to GPR and nuget.org is different. I followed the README.md instructions and it was published normally.

@gowridurgad
Copy link

Hi @na1307 , Since it has been successfully published, we are proceeding to close this issue. Please feel free to contact us in case of any further concerns.
Thank You !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants