3 releases (breaking)

0.3.0 Jun 11, 2024
0.2.0 Jul 8, 2022
0.1.0 Jul 25, 2021

#234 in Authentication

Download history 63/week @ 2024-06-26 39/week @ 2024-07-03 69/week @ 2024-07-10 43/week @ 2024-07-17 93/week @ 2024-07-24 54/week @ 2024-07-31 60/week @ 2024-08-07 54/week @ 2024-08-14 26/week @ 2024-08-21 50/week @ 2024-08-28 53/week @ 2024-09-04 49/week @ 2024-09-11 75/week @ 2024-09-18 50/week @ 2024-09-25 36/week @ 2024-10-02 51/week @ 2024-10-09

222 downloads per month

MIT/Apache

21KB
304 lines

NATS JWT (Rust)

Crates.io Crates.io Docs.rs

Generate JWTs signed using NKEYs for use with NATS

Supports generating account and user JWTs, operator JWTs are not typically generated on the fly and so aren't supported, although a PR adding support would be accepted.

Example

use nats_jwt::{KeyPair, Token};

// 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_token = Token::new_account(account_keypair.public_key())
    .name("My Account")
    .add_signing_key(account_signing_key.public_key())
    .max_connections(100)
    .sign(&operator_signing_key);
println!("account_token: {}", account_token);

let user_keypair = KeyPair::new_user();
let user_key_pub = user_keypair.public_key();
let user_token = Token::new_user(account_keypair.public_key(), user_key_pub)
    .bearer_token(true)
    .name("My User")
    .max_subscriptions(10)
    .max_payload(1024 * 1024) // 1MiB
    .allow_publish("service.hello.world")
    .allow_subscribe("_INBOX.>")
    .sign(&account_signing_key);
println!("user_token: {}", user_token);

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~4–5.5MB
~114K SLoC