A godawful jwt implementation
toml
[dependencies.jwt]
package="tenet"
version = "*"
features = ["HS256"]
This library is slow, baldly implemented and took a total of 20 minutes to write and bug check.
You are much better off using another tried and tested JWT implementation:
- frank_jwt
- jsonwebtoken
- biscuit
- jsonwebtokens
Why does it exist? I got fed up with shitty API design around signing and verifying tokens.
This library has two token types:
- A unsigned token with a given type (Token<T>
)
- A signed token (SignedToken
)
Token algorithms are decided by a enum: TokenAlgorithm
HS256
HS512
```rust use serde::{Serialize, Deserialize}; use jwt::{Token, TokenAlgorithm, SignedToken};
// Create a new token type. // This uses serde's Serialize and Deserialize procedural macros.
struct MyToken { foo: u8, bar: bool, baz: String, }
// create a key to sign and verify tokens. let tokenkey = b"VERYSECUREKEY".tovec();
// create a new token, sign it, and get the string representation let token = Token::create( TokenAlgorithm::HS256, MyToken { foo: 10, bar: true, baz: "Hello World".tostring() } ) .sign(&tokenkey).unwrap().string();
println!("{}", token);
// verify a token input
let payload = Token::
println!("{:?}", payload); ```