Crates.io | nats-io-jwt |
lib.rs | nats-io-jwt |
version | |
source | src |
created_at | 2025-01-02 23:51:27.397694 |
updated_at | 2025-01-08 21:13:38.607655 |
description | Generate JWTs signed using NKEYs for use with https://nats.io |
homepage | |
repository | |
max_upload_size | |
id | 1501993 |
Cargo.toml error: | TOML parse error at line 22, column 1 | 22 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
NOTE - This is still a work in progress while at the 0.0.x version
This crate is based off of a JSON schema that was initially generated from
v2.7.3 of the golang nats-io jwt library at
nats-io/jwt. At the point when this
crate was built, this was the most up-to-date supported library in use for
nats.io. The idea was to generate a language agnostic representation of the JWT
API for nats.io and then generate Rust code from this schema using typify
.
Finally a thin wrapper found in src/lib.rs
was built to provide an interface
to the generated code.
Generate JWTs signed using NKEYs for use with NATS
Supports generating JWTs for Account, User and Activation claims.
use nats_jwt::{KeyPair, Token, Account, User, Permission, SigningKeys};
// You would probably load the operator's seed via a config and use KeyPair::from_seed
let operator_signing_key = KeyPair::new_operator();
let account_keypair = KeyPair::new_account();
let account_signing_key = KeyPair::new_account();
let account: Account = Account::builder()
.signing_keys(SigningKeys::from(&account_signing_key))
.try_into()
.expect("Account to be valid");
let account_token = Token::new(account_keypair.public_key())
.name("My Account")
.claims(account)
.sign(&operator_signing_key);
println!("account_token: {}", account_token);
let user_keypair = KeyPair::new_user();
let user: User = User::builder()
.pub_(Permission::from("service.hello.world"))
.sub(Permission::from("_INBOX."))
.subs(10)
.payload(1024 * 1024) // 1MiB
.bearer_token(true)
.try_into()
.expect("Account to be valid");
let user_token = Token::new(user_keypair.public_key())
.name("My User")
.claims(user)
.sign(&account_signing_key);
println!("user_token: {}", user_token);
Some parts taken from https://github.com/AircastDev/nats-jwt
Licensed under
MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)