![]() |
VOOZH | about |
dotnet add package NATS.Jwt --version 1.0.0
NuGet\Install-Package NATS.Jwt -Version 1.0.0
<PackageReference Include="NATS.Jwt" Version="1.0.0" />
<PackageVersion Include="NATS.Jwt" Version="1.0.0" />Directory.Packages.props
<PackageReference Include="NATS.Jwt" />Project file
paket add NATS.Jwt --version 1.0.0
#r "nuget: NATS.Jwt, 1.0.0"
#:package NATS.Jwt@1.0.0
#addin nuget:?package=NATS.Jwt&version=1.0.0Install as a Cake Addin
#tool nuget:?package=NATS.Jwt&version=1.0.0Install as a Cake Tool
👁 License Apache 2.0
👁 NuGet
👁 Build
👁 codecov
This is a .NET implementation of the JWT library for the NATS ecosystem.
This repository provides an API to build NATS JWTs using .NET. However, at this time it is not a supported API. Use at your own risk.
One important takeaway from this project is that the purpose of the library is for building JWTs, not to validate them exhaustively. This means that tokens generated by this library are expected to be validated by a process that uses the . As that library is the one used by:
Under that context, the ultimate validity of the JWT is delegated to tools or servers that use the . Use of this library implies an agreement with the above disclaimer.
You can install the package via NuGet:
dotnet add package NATS.Jwt
// create an operator key pair (private key)
var okp = KeyPair.CreatePair(PrefixByte.Operator);
var opk = okp.GetPublicKey();
// create an operator claim using the public key for the identifier
var oc = NatsJwt.NewOperatorClaims(opk);
oc.Name = "Example Operator";
// add an operator signing key to sign accounts
var oskp = KeyPair.CreatePair(PrefixByte.Operator);
var ospk = oskp.GetPublicKey();
// add the signing key to the operator - this makes any account
// issued by the signing key to be valid for the operator
oc.Operator.SigningKeys = [ospk];
// self-sign the operator JWT - the operator trusts itself
var operatorJwt = NatsJwt.Encode(oc, okp);
// create an account keypair
var akp = KeyPair.CreatePair(PrefixByte.Account);
var apk = akp.GetPublicKey();
// create the claim for the account using the public key of the account
var ac = NatsJwt.NewAccountClaims(apk);
ac.Name = "Example Account";
var askp = KeyPair.CreatePair(PrefixByte.Account);
var aspk = askp.GetPublicKey();
// add the signing key (public) to the account
ac.Account.SigningKeys = [aspk];
var accountJwt = NatsJwt.Encode(ac, oskp);
// now back to the account, the account can issue users
// need not be known to the operator - the users are trusted
// because they will be signed by the account. The server will
// look up the account get a list of keys the account has and
// verify that the user was issued by one of those keys
var ukp = KeyPair.CreatePair(PrefixByte.User);
var upk = ukp.GetPublicKey();
var uc = NatsJwt.NewUserClaims(upk);
// since the jwt will be issued by a signing key, the issuer account
// must be set to the public ID of the account
uc.User.IssuerAccount = apk;
var userJwt = NatsJwt.Encode(uc, askp);
// the seed is a version of the keypair that is stored as text
var userSeed = ukp.GetSeed();
var conf = $$"""
operator: {{operatorJwt}}
resolver: MEMORY
resolver_preload: {
{{apk}}: {{accountJwt}}
}
""";
// generate a creds formatted file that can be used by a NATS client
const string credsPath = $"example_user.creds";
File.WriteAllText(credsPath, NatsJwt.FormatUserConfig(userJwt, userSeed));
// now we are going to put it together into something that can be run
// we create a file to store the server configuration, the creds
// file and a small program that uses the creds file
const string confPath = $"example_server.conf";
File.WriteAllText(confPath, conf);
// run the server:
// > nats-server -c example_server.conf
// Connect as user
var authOpts = new NatsAuthOpts { CredsFile = credsPath };
var opts = new NatsOpts { Url = server.Url, AuthOpts = authOpts };
await using var nats = new NatsConnection(opts);
await nats.PingAsync();
A JWT implementation that uses nkeys to digitally sign JWT tokens for the NATS ecosystem.
See also https://github.com/nats-io/jwt
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 2 NuGet packages that depend on NATS.Jwt:
| Package | Downloads |
|---|---|
|
cloops.nats
SDK to build NATS consumers with annotations |
|
|
Synadia.AuthCallout
Synadia NATS Auth Callout for .NET |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.1 | 16,578 | 4/23/2026 |
| 1.0.0 | 3,475 | 3/18/2026 |
| 1.0.0-preview.16 | 68,698 | 7/10/2025 |
| 1.0.0-preview.15 | 196 | 6/30/2025 |
| 1.0.0-preview.14 | 200 | 6/20/2025 |
| 1.0.0-preview.12 | 4,562 | 4/2/2025 |
| 1.0.0-preview.11 | 15,869 | 1/22/2025 |
| 1.0.0-preview.10 | 506 | 12/11/2024 |
| 1.0.0-preview.9 | 2,985 | 11/1/2024 |
| 1.0.0-preview.8 | 160 | 10/16/2024 |
| 1.0.0-preview.7 | 187 | 9/13/2024 |
| 1.0.0-preview.6 | 144 | 9/12/2024 |
| 1.0.0-preview.5 | 230 | 8/27/2024 |
| 1.0.0-preview.4 | 178 | 8/22/2024 |
| 1.0.0-preview.3 | 175 | 8/14/2024 |
| 1.0.0-preview.2 | 169 | 8/9/2024 |
| 1.0.0-preview.1 | 166 | 7/19/2024 |