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.
```rust use nats_jwt::{KeyPair, Token};
// You would probably load the operator's seed via a config and use KeyPair::fromseed let operatorsigningkey = KeyPair::newoperator();
let accountkeypair = KeyPair::newaccount(); let accountsigningkey = KeyPair::newaccount(); let accounttoken = Token::newaccount(accountkeypair.publickey()) .name("My Account") .addsigningkey(accountsigningkey.publickey()) .maxconnections(100) .sign(&operatorsigningkey); println!("accounttoken: {}", account_token);
let userkeypair = KeyPair::newuser(); let userkeypub = userkeypair.publickey(); let usertoken = Token::newuser(accountkeypair.publickey(), userkeypub) .bearertoken(true) .name("My User") .maxsubscriptions(10) .maxpayload(1024 * 1024) // 1MiB .allowpublish("service.hello.world") .allowsubscribe("INBOX.>") .sign(&accountsigningkey); println!("usertoken: {}", usertoken); ```
Licensed under either of
at your option.
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.