armature-jwt

Crates.ioarmature-jwt
lib.rsarmature-jwt
version0.1.1
created_at2025-12-26 23:12:04.204254+00
updated_at2025-12-29 01:11:59.070021+00
descriptionJWT token handling for Armature authentication
homepagehttps://pegasusheavy.github.io/armature
repositoryhttps://github.com/pegasusheavy/armature
max_upload_size
id2006392
size107,353
Joseph R. Quinn (quinnjr)

documentation

README

armature-jwt

JWT authentication and authorization for the Armature framework.

Features

  • Token Generation - Create signed JWTs with custom claims
  • Token Verification - Validate signatures and expiration
  • Multiple Algorithms - HS256, HS384, HS512, RS256, RS384, RS512, ES256, ES384
  • Refresh Tokens - Built-in token refresh flow
  • Custom Claims - Extend with your own claim types

Installation

[dependencies]
armature-jwt = "0.1"

Quick Start

use armature_jwt::{JwtManager, JwtConfig, Claims};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create JWT manager
    let config = JwtConfig::new("your-secret-key")
        .expiration(Duration::from_secs(3600));
    let jwt = JwtManager::new(config);

    // Create a token
    let claims = Claims::new()
        .subject("user123")
        .claim("role", "admin");
    let token = jwt.sign(&claims)?;

    // Verify a token
    let verified = jwt.verify(&token)?;
    println!("User: {}", verified.sub.unwrap());

    Ok(())
}

Token Refresh

// Generate token pair (access + refresh)
let (access, refresh) = jwt.generate_pair(&claims)?;

// Refresh the access token
let new_access = jwt.refresh(&refresh)?;

License

MIT OR Apache-2.0

Commit count: 0

cargo fmt