|
16 | 16 |
|
17 | 17 | use std::borrow::Cow;
|
18 | 18 |
|
19 |
| -use parse_display::{Display, FromStr}; |
20 | 19 | use serde::{Deserialize, Serialize};
|
21 | 20 | use serde_with::{DeserializeFromStr, SerializeDisplay};
|
22 | 21 |
|
@@ -60,8 +59,7 @@ impl From<ClientErrorCode> for ClientError {
|
60 | 59 | }
|
61 | 60 |
|
62 | 61 | /// Client error codes defined in OAuth2.0, OpenID Connect and their extensions.
|
63 |
| -#[derive(Debug, Clone, PartialEq, Eq, Display, FromStr, SerializeDisplay, DeserializeFromStr)] |
64 |
| -#[display(style = "snake_case")] |
| 62 | +#[derive(Debug, Clone, PartialEq, Eq, SerializeDisplay, DeserializeFromStr)] |
65 | 63 | pub enum ClientErrorCode {
|
66 | 64 | /// `invalid_request`
|
67 | 65 | ///
|
@@ -276,10 +274,77 @@ pub enum ClientErrorCode {
|
276 | 274 | UnsupportedTokenType,
|
277 | 275 |
|
278 | 276 | /// Another error code.
|
279 |
| - #[display("{0}")] |
280 | 277 | Unknown(String),
|
281 | 278 | }
|
282 | 279 |
|
| 280 | +impl core::fmt::Display for ClientErrorCode { |
| 281 | + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
| 282 | + match self { |
| 283 | + ClientErrorCode::InvalidRequest => f.write_str("invalid_request"), |
| 284 | + ClientErrorCode::InvalidClient => f.write_str("invalid_client"), |
| 285 | + ClientErrorCode::InvalidGrant => f.write_str("invalid_grant"), |
| 286 | + ClientErrorCode::UnauthorizedClient => f.write_str("unauthorized_client"), |
| 287 | + ClientErrorCode::UnsupportedGrantType => f.write_str("unsupported_grant_type"), |
| 288 | + ClientErrorCode::AccessDenied => f.write_str("access_denied"), |
| 289 | + ClientErrorCode::UnsupportedResponseType => f.write_str("unsupported_response_type"), |
| 290 | + ClientErrorCode::InvalidScope => f.write_str("invalid_scope"), |
| 291 | + ClientErrorCode::ServerError => f.write_str("server_error"), |
| 292 | + ClientErrorCode::TemporarilyUnavailable => f.write_str("temporarily_unavailable"), |
| 293 | + ClientErrorCode::InteractionRequired => f.write_str("interaction_required"), |
| 294 | + ClientErrorCode::LoginRequired => f.write_str("login_required"), |
| 295 | + ClientErrorCode::AccountSelectionRequired => f.write_str("account_selection_required"), |
| 296 | + ClientErrorCode::ConsentRequired => f.write_str("consent_required"), |
| 297 | + ClientErrorCode::InvalidRequestUri => f.write_str("invalid_request_uri"), |
| 298 | + ClientErrorCode::InvalidRequestObject => f.write_str("invalid_request_object"), |
| 299 | + ClientErrorCode::RequestNotSupported => f.write_str("request_not_supported"), |
| 300 | + ClientErrorCode::RequestUriNotSupported => f.write_str("request_uri_not_supported"), |
| 301 | + ClientErrorCode::RegistrationNotSupported => f.write_str("registration_not_supported"), |
| 302 | + ClientErrorCode::InvalidRedirectUri => f.write_str("invalid_redirect_uri"), |
| 303 | + ClientErrorCode::InvalidClientMetadata => f.write_str("invalid_client_metadata"), |
| 304 | + ClientErrorCode::AuthorizationPending => f.write_str("authorization_pending"), |
| 305 | + ClientErrorCode::SlowDown => f.write_str("slow_down"), |
| 306 | + ClientErrorCode::ExpiredToken => f.write_str("expired_token"), |
| 307 | + ClientErrorCode::UnsupportedTokenType => f.write_str("unsupported_token_type"), |
| 308 | + ClientErrorCode::Unknown(value) => f.write_str(value), |
| 309 | + } |
| 310 | + } |
| 311 | +} |
| 312 | + |
| 313 | +impl core::str::FromStr for ClientErrorCode { |
| 314 | + type Err = core::convert::Infallible; |
| 315 | + |
| 316 | + fn from_str(s: &str) -> Result<Self, Self::Err> { |
| 317 | + match s { |
| 318 | + "invalid_request" => Ok(ClientErrorCode::InvalidRequest), |
| 319 | + "invalid_client" => Ok(ClientErrorCode::InvalidClient), |
| 320 | + "invalid_grant" => Ok(ClientErrorCode::InvalidGrant), |
| 321 | + "unauthorized_client" => Ok(ClientErrorCode::UnauthorizedClient), |
| 322 | + "unsupported_grant_type" => Ok(ClientErrorCode::UnsupportedGrantType), |
| 323 | + "access_denied" => Ok(ClientErrorCode::AccessDenied), |
| 324 | + "unsupported_response_type" => Ok(ClientErrorCode::UnsupportedResponseType), |
| 325 | + "invalid_scope" => Ok(ClientErrorCode::InvalidScope), |
| 326 | + "server_error" => Ok(ClientErrorCode::ServerError), |
| 327 | + "temporarily_unavailable" => Ok(ClientErrorCode::TemporarilyUnavailable), |
| 328 | + "interaction_required" => Ok(ClientErrorCode::InteractionRequired), |
| 329 | + "login_required" => Ok(ClientErrorCode::LoginRequired), |
| 330 | + "account_selection_required" => Ok(ClientErrorCode::AccountSelectionRequired), |
| 331 | + "consent_required" => Ok(ClientErrorCode::ConsentRequired), |
| 332 | + "invalid_request_uri" => Ok(ClientErrorCode::InvalidRequestUri), |
| 333 | + "invalid_request_object" => Ok(ClientErrorCode::InvalidRequestObject), |
| 334 | + "request_not_supported" => Ok(ClientErrorCode::RequestNotSupported), |
| 335 | + "request_uri_not_supported" => Ok(ClientErrorCode::RequestUriNotSupported), |
| 336 | + "registration_not_supported" => Ok(ClientErrorCode::RegistrationNotSupported), |
| 337 | + "invalid_redirect_uri" => Ok(ClientErrorCode::InvalidRedirectUri), |
| 338 | + "invalid_client_metadata" => Ok(ClientErrorCode::InvalidClientMetadata), |
| 339 | + "authorization_pending" => Ok(ClientErrorCode::AuthorizationPending), |
| 340 | + "slow_down" => Ok(ClientErrorCode::SlowDown), |
| 341 | + "expired_token" => Ok(ClientErrorCode::ExpiredToken), |
| 342 | + "unsupported_token_type" => Ok(ClientErrorCode::UnsupportedTokenType), |
| 343 | + _ => Ok(ClientErrorCode::Unknown(s.to_owned())), |
| 344 | + } |
| 345 | + } |
| 346 | +} |
| 347 | + |
283 | 348 | impl ClientErrorCode {
|
284 | 349 | /// Get the default description for this `ClientErrorCode`.
|
285 | 350 | ///
|
|
0 commit comments