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
//! # supabase-jwt
//!
//! A lightweight, framework-agnostic Rust library for validating Supabase Auth JWTs, with JWKS caching support.
//!
//! ## Features
//! - **Framework Agnostic**: Not dependent on any web framework, can be used in any Rust project.
//! - **JWKS-based**: Supports dynamic key fetching and caching from Supabase.
//! - **Stateless Validation**: Each request is validated independently for security.
//! - **High Performance**: Optimized parsing and validation with smart caching.
//!
//! ## Quick Start
//!
//! ```rust,no_run
//! use supabase_jwt::{Claims, JwksCache};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // 1. Initialize the JWKS cache with your Supabase URL
//! let jwks_url = "https://<your-project-ref>.supabase.co/auth/v1/jwks";
//! let jwks_cache = JwksCache::new(jwks_url);
//!
//! // 2. Get the Bearer Token from the request's Authorization header
//! let bearer_token = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...";
//!
//! // 3. Validate the JWT and extract claims
//! match Claims::from_bearer_token(bearer_token, &jwks_cache).await {
//! Ok(claims) => {
//! // 4. Access user information securely
//! println!("Successfully validated token for user: {}", claims.user_id());
//! }
//! Err(e) => {
//! eprintln!("Authentication failed: {}", e);
//! }
//! }
//!
//! Ok(())
//! }
//! ```
// Module declarations for the library's internal components.
/// Handles JWT claims and validation logic.
/// Defines error types for the library.
/// Manages JWKS fetching and caching.
/// Provides JWT parsing functionalities.
// Test module, conditionally compiled only when running tests.
// Re-exporting key types and functions for a clean public API.
pub use Claims;
pub use AuthError;
pub use JwksCache;