4 releases (2 stable)
new 1.1.0 | Dec 12, 2024 |
---|---|
1.0.0 | Dec 11, 2024 |
0.2.0 | Dec 11, 2024 |
0.1.0 | Dec 11, 2024 |
#555 in Encoding
531 downloads per month
17KB
317 lines
small_jwt
Simple and small JWT library for rust.
Warning
This library is not ready for any usage.
I write it for myself and if you find out that X
from RFC not implemented it's okay.
Example
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub struct Claims {
pub user: String,
pub age: u16,
pub is_admin: bool,
}
const SECRET_KEY: &[u8] = b"my_super_secret_key";
fn main() {
let header = small_jwt::Header::default();
let claims = Claims {
user: String::from("username"),
age: 128,
is_admin: true,
};
let token = small_jwt::encode(&header, &claims, SECRET_KEY);
println!("enoded key: {:?}", token);
let decoded = small_jwt::decode::<Claims>(&token.unwrap(), SECRET_KEY);
println!("decoded payload: {:?}", decoded);
}
LICENSE
Feel free to open issues, send PR, etc.
Dependencies
~1.3–2.3MB
~49K SLoC