basic-jwt

Crates.iobasic-jwt
lib.rsbasic-jwt
version0.2.0
sourcesrc
created_at2024-04-20 11:23:51.043884
updated_at2024-04-20 11:48:46.466762
descriptionBasic JWT signing and verification library
homepage
repositoryhttps://gitea.communiquons.org/pierre/basic-jwt
max_upload_size
id1214528
size8,345
Pierre Hubert (pierre42100)

documentation

README

Basic JWT

This crate provide basic functions to:

  • Sign JWT

  • Parse and validate JWT

Basic usage:

let claims = ...; // note : claims must be serializable

// 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();

// Create a JWT for the given claims (note: standard claims: sub, iss, ...) are not
// automatically added if they are missing
let jwt = priv_key.sign_jwt(&claims).expect("Failed to sign JWT!");

// Validate signed JWT
let claims_out = pub_key
            .validate_jwt::<Claims>(&jwt)
            .expect("Failed to validate JWT!");
Commit count: 0

cargo fmt