wae_authentication/oauth2/
errors.rs1use std::fmt;
4
5#[derive(Debug)]
7pub enum OAuth2Error {
8 InvalidAuthorizationCode,
10
11 InvalidRedirectUri,
13
14 InvalidClientId,
16
17 InvalidClientSecret,
19
20 InvalidScope(String),
22
23 InvalidAccessToken,
25
26 InvalidRefreshToken,
28
29 TokenExpired,
31
32 AccessDenied(String),
34
35 UnsupportedGrantType(String),
37
38 UnsupportedResponseType(String),
40
41 StateMismatch,
43
44 ConfigurationError(String),
46
47 RequestError(String),
49
50 ParseError(String),
52
53 ProviderError(String),
55
56 Other(String),
58}
59
60impl fmt::Display for OAuth2Error {
61 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
62 match self {
63 OAuth2Error::InvalidAuthorizationCode => write!(f, "Invalid authorization code"),
64 OAuth2Error::InvalidRedirectUri => write!(f, "Invalid redirect URI"),
65 OAuth2Error::InvalidClientId => write!(f, "Invalid client ID"),
66 OAuth2Error::InvalidClientSecret => write!(f, "Invalid client secret"),
67 OAuth2Error::InvalidScope(scope) => write!(f, "Invalid scope: {}", scope),
68 OAuth2Error::InvalidAccessToken => write!(f, "Invalid access token"),
69 OAuth2Error::InvalidRefreshToken => write!(f, "Invalid refresh token"),
70 OAuth2Error::TokenExpired => write!(f, "Token has expired"),
71 OAuth2Error::AccessDenied(msg) => write!(f, "Authorization denied: {}", msg),
72 OAuth2Error::UnsupportedGrantType(grant_type) => {
73 write!(f, "Unsupported grant type: {}", grant_type)
74 }
75 OAuth2Error::UnsupportedResponseType(response_type) => {
76 write!(f, "Unsupported response type: {}", response_type)
77 }
78 OAuth2Error::StateMismatch => write!(f, "State mismatch"),
79 OAuth2Error::ConfigurationError(msg) => write!(f, "Configuration error: {}", msg),
80 OAuth2Error::RequestError(msg) => write!(f, "Request error: {}", msg),
81 OAuth2Error::ParseError(msg) => write!(f, "Parse error: {}", msg),
82 OAuth2Error::ProviderError(msg) => write!(f, "Provider error: {}", msg),
83 OAuth2Error::Other(msg) => write!(f, "OAuth2 error: {}", msg),
84 }
85 }
86}
87
88impl std::error::Error for OAuth2Error {}
89
90impl From<url::ParseError> for OAuth2Error {
91 fn from(err: url::ParseError) -> Self {
92 OAuth2Error::ParseError(err.to_string())
93 }
94}
95
96impl From<serde_json::Error> for OAuth2Error {
97 fn from(err: serde_json::Error) -> Self {
98 OAuth2Error::ParseError(err.to_string())
99 }
100}
101
102pub type OAuth2Result<T> = Result<T, OAuth2Error>;