| Crates.io | paseto-auth |
| lib.rs | paseto-auth |
| version | 0.1.0 |
| created_at | 2025-12-23 14:47:52.086431+00 |
| updated_at | 2025-12-23 14:47:52.086431+00 |
| description | Paseto v4.public microservice compatible library for token creation and validation |
| homepage | |
| repository | https://github.com/alptekinbodur/paseto-auth |
| max_upload_size | |
| id | 2001643 |
| size | 26,829 |
paseto-auth
A lightweight, secure, and reusable Rust library for creating and verifying PASETO v4.public tokens using Ed25519 signatures. Designed for microservice architectures where a single authentication service issues tokens and multiple services verify them.
๐ No dependencies on external PASETO crates โ built on stable, well-maintained libraries (
ed25519-dalek,serde,base64)
exp) and issuance (iat) checksthiserrorAdd this to your Cargo.toml:
[dependencies]
paseto-auth = "0.1"
Generate an Ed25519 keypair once (e.g., using the provided helper or any secure method).
Store the private key ONLY in your auth service (e.g., via .env, Vault, or *Kubernetes Secret).
Distribute the public key to all verifier services.
๐ Never share the private key outside the token issuer!
use paseto_auth::{Claims, create_paseto_v4_public};
// Load your 32-byte private key (e.g., from hex string)
let private_key: [u8; 32] = hex::decode("...")?.try_into()?;
let claims = Claims::new("user_123".into(), 3600) // 1-hour token
.with_scope("read:profile".into());
let token = create_paseto_v4_public(&claims, &private_key)?;
println!("Token: {}", token);
use paseto_auth::{verify_paseto_v4_public, Claims};
// Load your 32-byte public key
let public_key: [u8; 32] = hex::decode("...")?.try_into()?;
let token = "v4.public...."; // from Authorization header
let claims: Claims = verify_paseto_v4_public(token, &public_key)?;
println!("Valid token for user: {}", claims.sub);
use ed25519_dalek::SigningKey;
use rand::rngs::OsRng;
use rand::RngCore;
let mut sk_bytes = [0u8; 32];
OsRng.fill_bytes(&mut sk_bytes);
let signing_key = SigningKey::from_bytes(&sk_bytes);
let pk_bytes = signing_key.verifying_key().to_bytes();
println!("Private Key (hex): {}", hex::encode(sk_bytes));
println!("Public Key (hex): {}", hex::encode(pk_bytes));
myapp by default) to bind tokens to your application.exp/iat work correctly.Contributions welcome! Please open an issue or PR on GitHub.
Built with โค๏ธ for secure, distributed systems. Inspired by the PASETO specification.