corevpn_auth/
error.rs

1//! Authentication error types
2
3use thiserror::Error;
4
5/// Result type for authentication operations
6pub type Result<T> = std::result::Result<T, AuthError>;
7
8/// Authentication errors
9#[derive(Debug, Error)]
10pub enum AuthError {
11    /// OAuth2 error
12    #[error("OAuth2 error: {0}")]
13    OAuth2Error(String),
14
15    /// Token validation failed
16    #[error("token validation failed: {0}")]
17    TokenValidationFailed(String),
18
19    /// Token expired
20    #[error("token expired")]
21    TokenExpired,
22
23    /// Token refresh failed
24    #[error("token refresh failed: {0}")]
25    TokenRefreshFailed(String),
26
27    /// Invalid state parameter
28    #[error("invalid state parameter")]
29    InvalidState,
30
31    /// Invalid nonce
32    #[error("invalid nonce")]
33    InvalidNonce,
34
35    /// Provider not configured
36    #[error("provider not configured: {0}")]
37    ProviderNotConfigured(String),
38
39    /// Provider discovery failed
40    #[error("OIDC discovery failed: {0}")]
41    DiscoveryFailed(String),
42
43    /// Unauthorized domain
44    #[error("domain not allowed: {0}")]
45    UnauthorizedDomain(String),
46
47    /// User not in allowed group
48    #[error("user not in required group")]
49    NotInRequiredGroup,
50
51    /// User disabled
52    #[error("user account is disabled")]
53    UserDisabled,
54
55    /// Session not found
56    #[error("auth session not found")]
57    SessionNotFound,
58
59    /// Session expired
60    #[error("auth session expired")]
61    SessionExpired,
62
63    /// Device authorization pending
64    #[error("authorization pending")]
65    AuthorizationPending,
66
67    /// Device authorization expired
68    #[error("device authorization expired")]
69    DeviceAuthExpired,
70
71    /// HTTP error
72    #[error("HTTP error: {0}")]
73    HttpError(String),
74
75    /// Serialization error
76    #[error("serialization error: {0}")]
77    SerializationError(String),
78
79    /// Configuration error
80    #[error("configuration error: {0}")]
81    ConfigError(String),
82}
83
84impl From<reqwest::Error> for AuthError {
85    fn from(err: reqwest::Error) -> Self {
86        AuthError::HttpError(err.to_string())
87    }
88}
89
90impl From<serde_json::Error> for AuthError {
91    fn from(err: serde_json::Error) -> Self {
92        AuthError::SerializationError(err.to_string())
93    }
94}