Summary
Exchanges a GitHub Actions OIDC identity token for a short-lived NuGet.org API key (trusted publishing).
Default token service URL is https://www.nuget.org/api/v2/token and default OIDC audience is https://www.nuget.org.
Requires permissions: id-token: write in the GitHub Actions workflow.
OIDC tokens and the returned API key are automatically masked in the build log.
Syntax
public Task<string> NuGetLogin(string userName, CancellationToken cancellationToken = default(CancellationToken))
Examples
var nuGetUserName = EnvironmentVariable("NUGET_USERNAME");
var apiKey = await GitHubActions.Commands.NuGetLogin(nuGetUserName);
var settings = new DotNetNuGetPushSettings
{
ApiKey = apiKey,
Source = "https://api.nuget.org/v3/index.json"
};
foreach (var packageFilePath in GetFiles("./*.nupkg"))
{
DotNetNuGetPush(packageFilePath, settings);
}
Parameters
| Name |
Type |
Description |
| userName |
string |
The NuGet.org account user name. |
| cancellationToken |
CancellationToken |
The cancellation token. |
Return Value
| Type |
Description |
| Task<string> |
The NuGet API key. |