get401
Core Rust SDK for get401 authentication. Verifies EdDSA/Ed25519 JWTs, fetches and caches the public key, and parses token claims.
Backend only. Designed for Rust server applications. Used directly by
get401/rust-axum.
Installation
[]
= "0.1"
= { = "1", = ["full"] }
Quick start
use Arc;
use ;
let client = new;
let verifier = new;
let claims = verifier.verify.await?;
println!; // user public ID
println!; // ["USER"]
println!; // "read,write"
Configuration
// Default host (https://app.get401.com)
new
// Custom host (self-hosted / staging)
with_host
The client sends X-App-Id and Origin headers as required by the get401 API.
TokenClaims reference
| Field | Type | Description |
|---|---|---|
sub |
String |
User's public ID |
exp |
u64 |
Expiration Unix timestamp |
iat |
u64 |
Issued-at Unix timestamp |
iss |
String |
Token issuer |
roles |
Vec<String> |
Roles granted — e.g. ["USER"] |
scope |
String |
Comma-separated scope string |
Helper methods
claims.has_role // bool
claims.has_any_role // bool
claims.has_all_roles // bool
claims.has_scope // bool
claims.scopes // Vec<&str>
claims.is_authenticated_user // true when roles contains "USER"
Error handling
use Get401Error;
match verifier.verify.await
Public key caching
The client caches the public key automatically until the backend-provided expires_at timestamp passes. Concurrent requests during a refresh are de-duplicated via a tokio::sync::RwLock.
// Force a refresh
client.refresh_public_key.await?;
Thread safety
Get401Client uses tokio::sync::RwLock internally. Wrap it in an Arc and clone freely across tasks:
let client = new;
let verifier = new;
// Share verifier across handlers
let v1 = clone;
let v2 = clone;