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

Commit 7e30daf

Browse files
committed
Replace parse-display with manual Display/FromStr impls
1 parent 4eeedbe commit 7e30daf

File tree

10 files changed

+334
-168
lines changed

10 files changed

+334
-168
lines changed

Cargo.lock

Lines changed: 0 additions & 49 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/graphql/src/model/oauth.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,10 @@ impl OAuth2Client {
197197

198198
/// The application type advertised by the client.
199199
pub async fn application_type(&self) -> Option<OAuth2ApplicationType> {
200-
match self.0.application_type? {
200+
match self.0.application_type.as_ref()? {
201201
ApplicationType::Web => Some(OAuth2ApplicationType::Web),
202202
ApplicationType::Native => Some(OAuth2ApplicationType::Native),
203+
ApplicationType::Unknown(_) => None,
203204
}
204205
}
205206
}

crates/handlers/src/oauth2/registration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ pub(crate) async fn post(
268268
&clock,
269269
metadata.redirect_uris().to_vec(),
270270
encrypted_client_secret,
271-
metadata.application_type,
271+
metadata.application_type.clone(),
272272
//&metadata.response_types(),
273273
metadata.grant_types().to_vec(),
274274
metadata.contacts.clone().unwrap_or_default(),

crates/oauth2-types/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ serde.workspace = true
1717
serde_json.workspace = true
1818
language-tags = { version = "0.3.2", features = ["serde"] }
1919
url.workspace = true
20-
parse-display = "0.9.0"
2120
serde_with = { version = "3.7.0", features = ["chrono"] }
2221
chrono.workspace = true
2322
sha2 = "0.10.8"

crates/oauth2-types/src/errors.rs

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
1717
use std::borrow::Cow;
1818

19-
use parse_display::{Display, FromStr};
2019
use serde::{Deserialize, Serialize};
2120
use serde_with::{DeserializeFromStr, SerializeDisplay};
2221

@@ -60,8 +59,7 @@ impl From<ClientErrorCode> for ClientError {
6059
}
6160

6261
/// 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)]
6563
pub enum ClientErrorCode {
6664
/// `invalid_request`
6765
///
@@ -276,10 +274,77 @@ pub enum ClientErrorCode {
276274
UnsupportedTokenType,
277275

278276
/// Another error code.
279-
#[display("{0}")]
280277
Unknown(String),
281278
}
282279

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+
283348
impl ClientErrorCode {
284349
/// Get the default description for this `ClientErrorCode`.
285350
///

0 commit comments

Comments
 (0)