1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//! # modo::auth::jwt
//!
//! JWT authentication — token encoding, decoding, middleware, and revocation.
//!
//! Requires feature `"auth"`.
//!
//! ## Provides
//!
//! | Type | Purpose |
//! |------|---------|
//! | [`Claims`] | JWT claims with registered and custom fields; axum extractor |
//! | [`JwtConfig`] | YAML-deserialized configuration (secret, expiry, leeway, issuer, audience) |
//! | [`JwtEncoder`] | Signs and produces JWT token strings (HS256) |
//! | [`JwtDecoder`] | Verifies signatures and validates claims |
//! | [`JwtLayer`] | Tower middleware that enforces JWT auth on axum routes |
//! | [`Bearer`] | Standalone axum extractor for the raw Bearer token string |
//! | [`JwtError`] | Typed error enum with static `code()` strings |
//! | [`ValidationConfig`] | Runtime validation policy (leeway, issuer, audience) |
//!
//! | Trait | Purpose |
//! |-------|---------|
//! | [`Revocation`] | Pluggable async token revocation backend |
//! | [`TokenSource`] | Pluggable token extraction from HTTP requests |
//! | [`TokenSigner`] | JWT signing (extends [`TokenVerifier`]) |
//! | [`TokenVerifier`] | JWT signature verification |
//!
//! | Token source | Extracts from |
//! |--------------|---------------|
//! | [`BearerSource`] | `Authorization: Bearer <token>` header |
//! | [`CookieSource`] | Named cookie |
//! | [`QuerySource`] | Named query parameter |
//! | [`HeaderSource`] | Custom request header |
//!
//! | Signer | Algorithm |
//! |--------|-----------|
//! | [`HmacSigner`] | HMAC-SHA256 (HS256), implements [`TokenSigner`] and [`TokenVerifier`] |
//!
//! ## Quick start
//!
//! ```rust,ignore
//! use modo::auth::jwt::{JwtConfig, JwtEncoder, JwtDecoder, JwtLayer, Claims};
//! use serde::{Serialize, Deserialize};
//!
//! #[derive(Clone, Serialize, Deserialize)]
//! struct MyClaims { role: String }
//!
//! let config = JwtConfig::new("my-super-secret-key-for-signing-tokens");
//! let encoder = JwtEncoder::from_config(&config);
//! let decoder = JwtDecoder::from_config(&config);
//!
//! // Encode
//! let claims = Claims::new(MyClaims { role: "admin".into() })
//! .with_sub("user_123")
//! .with_iat_now()
//! .with_exp_in(std::time::Duration::from_secs(3600));
//! let token = encoder.encode(&claims).unwrap();
//!
//! // Decode
//! let decoded: Claims<MyClaims> = decoder.decode(&token).unwrap();
//!
//! // Middleware
//! use axum::Router;
//! use axum::routing::get;
//! let app: Router = Router::new()
//! .route("/me", get(|| async { "ok" }))
//! .layer(JwtLayer::<MyClaims>::new(decoder));
//! ```
pub use Claims;
pub use JwtConfig;
pub use JwtDecoder;
pub use JwtEncoder;
pub use JwtError;
pub use Bearer;
pub use JwtLayer;
pub use Revocation;
pub use ;
pub use ;
pub use ValidationConfig;