ts-token 0.8.0

JSON web token library for my projects
Documentation
//! Issuing and verifying JSON web tokens

use core::time::Duration;

use ts_crypto::SigningKey;
use ts_token::{JsonWebKey, TokenIssuer, TokenVerifier};

#[test]
fn verify_sign_es512() {
    let pem = include_str!("keys/private.secp521r1.pem");
    let key = SigningKey::from_pem(pem.as_bytes()).expect("the test key should be valid");
    let jwk = JsonWebKey::from(&key.verifying_key());
    let issuer = TokenIssuer::new(
        key,
        jwk.clone(),
        "test-issuer".to_string(),
        "http://localhost:8080/.well-known/jwks.json".to_string(),
    );

    let jws = issuer.issue(
        "test-audience".to_string(),
        "test-subject".to_string(),
        "read-value write-value".to_string(),
        Duration::from_secs(60 * 60),
    );

    let verifier = TokenVerifier::new(jwk.clone()).expect("verifier to be valid");
    let token = verifier
        .verify(&jws)
        .expect("JSON web token should be valid");
    assert_eq!(jwk.kid, token.header.kid);
}