supabase_jwt/
error.rs

1//! Defines the error types that can occur during JWT authentication.
2//!
3//! This module provides a comprehensive set of errors that may arise
4//! during the parsing and validation of JWTs, and is independent of any
5//! specific web framework.
6
7use thiserror::Error;
8
9/// Represents errors that can occur during JWT authentication.
10#[derive(Debug, Error, Clone, PartialEq)]
11pub enum AuthError {
12    /// The authentication token is missing or invalid.
13    #[error("missing or invalid authentication token")]
14    InvalidToken,
15
16    /// Failed to decode the token's header.
17    #[error("failed to decode token header")]
18    DecodeHeader,
19
20    /// No matching key was found in the JSON Web Key Set (JWKS).
21    #[error("failed to find matching key in JWKS")]
22    NoMatchingKey,
23
24    /// The key type is not supported by Supabase.
25    #[error("unsupported key type for Supabase: {0}")]
26    UnsupportedKeyType(String),
27
28    /// The cryptographic curve is not supported by Supabase.
29    #[error("unsupported curve for Supabase: {0}")]
30    UnsupportedCurve(String),
31
32    /// A component of the cryptographic key is invalid.
33    #[error("invalid key component: {0}")]
34    InvalidKeyComponent(String),
35
36    /// Failed to decode from Base64.
37    #[error("base64 decode error: {0}")]
38    Base64Decode(String),
39
40    /// The signing algorithm is invalid or not supported.
41    #[error("invalid algorithm")]
42    InvalidAlgorithm,
43
44    /// The token's signature verification failed.
45    #[error("token verification failed")]
46    Verification,
47
48    /// The claims within the token are invalid (e.g., `exp` or `iss`).
49    #[error("invalid claims")]
50    InvalidClaims,
51
52    /// An internal error occurred within the JWKS handling.
53    #[error("internal JWKS error: {0}")]
54    JwksError(String),
55
56    /// The token format is malformed.
57    #[error("malformed token format")]
58    MalformedToken,
59
60    /// A network error occurred during a request.
61    #[error("network error: {0}")]
62    NetworkError(String),
63}