basic-jwt/README.md

26 lines
695 B
Markdown
Raw Permalink Normal View History

2024-04-20 11:17:44 +00:00
# Basic JWT
This crate provide basic functions to:
* Sign JWT
* Parse and validate JWT
Basic usage:
```rust
let claims = ...; // note : claims must be serializable
2024-04-20 11:48:00 +00:00
// Generate a key pair. Private and public key are both serializable
let priv_key = JWTPrivateKey::generate_ec384_signing_key().unwrap();
let pub_key = priv_key.to_public_key().unwrap();
2024-04-20 11:17:44 +00:00
// Create a JWT for the given claims (note: standard claims: sub, iss, ...) are not
// automatically added if they are missing
2024-04-20 11:48:00 +00:00
let jwt = priv_key.sign_jwt(&claims).expect("Failed to sign JWT!");
2024-04-20 11:17:44 +00:00
// Validate signed JWT
2024-04-20 11:48:00 +00:00
let claims_out = pub_key
.validate_jwt::<Claims>(&jwt)
.expect("Failed to validate JWT!");
2024-04-20 11:17:44 +00:00
```