Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

Replace parse-display with manual Display/FromStr impls #2518

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 0 additions & 49 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion crates/graphql/src/model/oauth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,10 @@ impl OAuth2Client {

/// The application type advertised by the client.
pub async fn application_type(&self) -> Option<OAuth2ApplicationType> {
match self.0.application_type? {
match self.0.application_type.as_ref()? {
ApplicationType::Web => Some(OAuth2ApplicationType::Web),
ApplicationType::Native => Some(OAuth2ApplicationType::Native),
ApplicationType::Unknown(_) => None,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/handlers/src/oauth2/registration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ pub(crate) async fn post(
&clock,
metadata.redirect_uris().to_vec(),
encrypted_client_secret,
metadata.application_type,
metadata.application_type.clone(),
//&metadata.response_types(),
metadata.grant_types().to_vec(),
metadata.contacts.clone().unwrap_or_default(),
Expand Down
1 change: 0 additions & 1 deletion crates/oauth2-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ serde.workspace = true
serde_json.workspace = true
language-tags = { version = "0.3.2", features = ["serde"] }
url.workspace = true
parse-display = "0.9.0"
serde_with = { version = "3.7.0", features = ["chrono"] }
chrono.workspace = true
sha2 = "0.10.8"
Expand Down
73 changes: 69 additions & 4 deletions crates/oauth2-types/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

use std::borrow::Cow;

use parse_display::{Display, FromStr};
use serde::{Deserialize, Serialize};
use serde_with::{DeserializeFromStr, SerializeDisplay};

Expand Down Expand Up @@ -60,8 +59,7 @@ impl From<ClientErrorCode> for ClientError {
}

/// Client error codes defined in OAuth2.0, OpenID Connect and their extensions.
#[derive(Debug, Clone, PartialEq, Eq, Display, FromStr, SerializeDisplay, DeserializeFromStr)]
#[display(style = "snake_case")]
#[derive(Debug, Clone, PartialEq, Eq, SerializeDisplay, DeserializeFromStr)]
pub enum ClientErrorCode {
/// `invalid_request`
///
Expand Down Expand Up @@ -276,10 +274,77 @@ pub enum ClientErrorCode {
UnsupportedTokenType,

/// Another error code.
#[display("{0}")]
Unknown(String),
}

impl core::fmt::Display for ClientErrorCode {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
ClientErrorCode::InvalidRequest => f.write_str("invalid_request"),
ClientErrorCode::InvalidClient => f.write_str("invalid_client"),
ClientErrorCode::InvalidGrant => f.write_str("invalid_grant"),
ClientErrorCode::UnauthorizedClient => f.write_str("unauthorized_client"),
ClientErrorCode::UnsupportedGrantType => f.write_str("unsupported_grant_type"),
ClientErrorCode::AccessDenied => f.write_str("access_denied"),
ClientErrorCode::UnsupportedResponseType => f.write_str("unsupported_response_type"),
ClientErrorCode::InvalidScope => f.write_str("invalid_scope"),
ClientErrorCode::ServerError => f.write_str("server_error"),
ClientErrorCode::TemporarilyUnavailable => f.write_str("temporarily_unavailable"),
ClientErrorCode::InteractionRequired => f.write_str("interaction_required"),
ClientErrorCode::LoginRequired => f.write_str("login_required"),
ClientErrorCode::AccountSelectionRequired => f.write_str("account_selection_required"),
ClientErrorCode::ConsentRequired => f.write_str("consent_required"),
ClientErrorCode::InvalidRequestUri => f.write_str("invalid_request_uri"),
ClientErrorCode::InvalidRequestObject => f.write_str("invalid_request_object"),
ClientErrorCode::RequestNotSupported => f.write_str("request_not_supported"),
ClientErrorCode::RequestUriNotSupported => f.write_str("request_uri_not_supported"),
ClientErrorCode::RegistrationNotSupported => f.write_str("registration_not_supported"),
ClientErrorCode::InvalidRedirectUri => f.write_str("invalid_redirect_uri"),
ClientErrorCode::InvalidClientMetadata => f.write_str("invalid_client_metadata"),
ClientErrorCode::AuthorizationPending => f.write_str("authorization_pending"),
ClientErrorCode::SlowDown => f.write_str("slow_down"),
ClientErrorCode::ExpiredToken => f.write_str("expired_token"),
ClientErrorCode::UnsupportedTokenType => f.write_str("unsupported_token_type"),
ClientErrorCode::Unknown(value) => f.write_str(value),
}
}
}

impl core::str::FromStr for ClientErrorCode {
type Err = core::convert::Infallible;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"invalid_request" => Ok(ClientErrorCode::InvalidRequest),
"invalid_client" => Ok(ClientErrorCode::InvalidClient),
"invalid_grant" => Ok(ClientErrorCode::InvalidGrant),
"unauthorized_client" => Ok(ClientErrorCode::UnauthorizedClient),
"unsupported_grant_type" => Ok(ClientErrorCode::UnsupportedGrantType),
"access_denied" => Ok(ClientErrorCode::AccessDenied),
"unsupported_response_type" => Ok(ClientErrorCode::UnsupportedResponseType),
"invalid_scope" => Ok(ClientErrorCode::InvalidScope),
"server_error" => Ok(ClientErrorCode::ServerError),
"temporarily_unavailable" => Ok(ClientErrorCode::TemporarilyUnavailable),
"interaction_required" => Ok(ClientErrorCode::InteractionRequired),
"login_required" => Ok(ClientErrorCode::LoginRequired),
"account_selection_required" => Ok(ClientErrorCode::AccountSelectionRequired),
"consent_required" => Ok(ClientErrorCode::ConsentRequired),
"invalid_request_uri" => Ok(ClientErrorCode::InvalidRequestUri),
"invalid_request_object" => Ok(ClientErrorCode::InvalidRequestObject),
"request_not_supported" => Ok(ClientErrorCode::RequestNotSupported),
"request_uri_not_supported" => Ok(ClientErrorCode::RequestUriNotSupported),
"registration_not_supported" => Ok(ClientErrorCode::RegistrationNotSupported),
"invalid_redirect_uri" => Ok(ClientErrorCode::InvalidRedirectUri),
"invalid_client_metadata" => Ok(ClientErrorCode::InvalidClientMetadata),
"authorization_pending" => Ok(ClientErrorCode::AuthorizationPending),
"slow_down" => Ok(ClientErrorCode::SlowDown),
"expired_token" => Ok(ClientErrorCode::ExpiredToken),
"unsupported_token_type" => Ok(ClientErrorCode::UnsupportedTokenType),
_ => Ok(ClientErrorCode::Unknown(s.to_owned())),
}
}
}

impl ClientErrorCode {
/// Get the default description for this `ClientErrorCode`.
///
Expand Down
Loading
Loading