Skip to main content

authkestra_engine/auth/
error.rs

1use serde::{Deserialize, Serialize};
2
3/// Errors that can occur during the authentication process.
4#[derive(Debug, thiserror::Error)]
5pub enum AuthError {
6    /// An error returned by the authentication provider
7    #[error("Provider error: {0}")]
8    Provider(String),
9    /// The provided credentials (email/password) are invalid
10    #[error("Invalid credentials")]
11    InvalidCredentials,
12    /// The authorization code is invalid or expired
13    #[error("Invalid code")]
14    InvalidCode,
15    /// A network error occurred during communication with the provider
16    #[error("Network error")]
17    Network,
18    /// An error occurred during session management
19    #[error("Session error: {0}")]
20    Session(String),
21    /// An error occurred during token processing
22    #[error("Token error: {0}")]
23    Token(String),
24    /// The CSRF state parameter does not match the expected value
25    #[error("CSRF state mismatch")]
26    CsrfMismatch,
27    /// An error occurred during OIDC discovery
28    #[error("Discovery error: {0}")]
29    Discovery(String),
30    /// A required component (e.g., SessionManager, TokenManager) is missing
31    #[error("Missing component: {0}")]
32    ComponentMissing(String),
33    /// Invalid input provided
34    #[error("Invalid input")]
35    InvalidInput,
36    /// Invalid or failed credentials verification
37    #[error("Credentials error: {0}")]
38    Credentials(String),
39    /// An internal or unexpected storage error occurred
40    #[error("Internal error: {0}")]
41    Internal(String),
42}
43
44/// Represents an error response from an OAuth2 provider.
45#[derive(Debug, Clone, Serialize, Deserialize)]
46pub struct OAuthErrorResponse {
47    /// The error code.
48    pub error: String,
49    /// A human-readable ASCII text description of the error.
50    pub error_description: Option<String>,
51}