diff --git a/lib/komainu/benches/pkce.rs b/lib/komainu/benches/pkce.rs index 1fac7c6b8..d62e02755 100644 --- a/lib/komainu/benches/pkce.rs +++ b/lib/komainu/benches/pkce.rs @@ -6,7 +6,7 @@ use std::borrow::Cow; static GLOBAL: divan::AllocProfiler = divan::AllocProfiler::system(); #[divan::bench] -fn s256() -> Result<(), komainu::flow::FlowError> { +fn s256() -> Result<(), komainu::flow::Error> { let verifier_base64 = "dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk"; let challenge_base64 = "E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM"; @@ -19,7 +19,7 @@ fn s256() -> Result<(), komainu::flow::FlowError> { } #[divan::bench] -fn none() -> Result<(), komainu::flow::FlowError> { +fn none() -> Result<(), komainu::flow::Error> { let value = "arbitrary value"; let payload = pkce::Payload { diff --git a/lib/komainu/src/flow/authorization.rs b/lib/komainu/src/flow/authorization.rs index 4e60f73dc..18b738787 100644 --- a/lib/komainu/src/flow/authorization.rs +++ b/lib/komainu/src/flow/authorization.rs @@ -1,6 +1,6 @@ use crate::{ extract::ClientCredentials, - flow::{FlowError, OptionExt, TokenResponse}, + flow::{self, OptionExt, TokenResponse}, params::ParamStorage, Authorization, ClientExtractor, }; @@ -11,12 +11,12 @@ pub trait Issuer { fn load_authorization( &self, auth_code: &str, - ) -> impl Future>, FlowError>> + Send; + ) -> impl Future>, flow::Error>> + Send; fn issue_token( &self, authorization: &Authorization<'_>, - ) -> impl Future, FlowError>> + Send; + ) -> impl Future, flow::Error>> + Send; } #[instrument(skip_all)] @@ -24,7 +24,7 @@ pub async fn perform( req: http::Request, client_extractor: CE, token_issuer: I, -) -> Result, FlowError> +) -> Result, flow::Error> where CE: ClientExtractor, I: Issuer, @@ -44,7 +44,7 @@ where if *grant_type != "authorization_code" { error!(?client_id, "grant_type is not authorization_code"); - return Err(FlowError::UnsupportedGrantType); + return Err(flow::Error::UnsupportedGrantType); } let client = client_extractor @@ -53,16 +53,16 @@ where if client.redirect_uri != *redirect_uri { error!(?client_id, "redirect uri doesn't match"); - return Err(FlowError::InvalidClient); + return Err(flow::Error::InvalidClient); } let Some(authorization) = token_issuer.load_authorization(code).await? else { - return Err(FlowError::InvalidGrant); + return Err(flow::Error::InvalidGrant); }; // This check is constant time :3 if client != authorization.client { - return Err(FlowError::UnauthorizedClient); + return Err(flow::Error::UnauthorizedClient); } if let Some(ref pkce) = authorization.pkce_payload { diff --git a/lib/komainu/src/flow/mod.rs b/lib/komainu/src/flow/mod.rs index a5f10721b..6e817f2a5 100644 --- a/lib/komainu/src/flow/mod.rs +++ b/lib/komainu/src/flow/mod.rs @@ -8,20 +8,20 @@ pub mod pkce; pub mod refresh; trait OptionExt { - fn or_invalid_request(self) -> Result; + fn or_invalid_request(self) -> Result; } impl OptionExt for Option { #[inline] - fn or_invalid_request(self) -> Result { - self.ok_or(FlowError::InvalidRequest) + fn or_invalid_request(self) -> Result { + self.ok_or(Error::InvalidRequest) } } #[derive(Debug, Display, Error, Serialize)] #[serde(rename_all = "snake_case")] #[strum(serialize_all = "snake_case")] -pub enum FlowError { +pub enum Error { InvalidRequest, InvalidClient, InvalidGrant, @@ -49,6 +49,6 @@ pub enum TokenResponse<'a> { expires_in: u64, }, Error { - errorr: FlowError, + errorr: Error, }, } diff --git a/lib/komainu/src/flow/pkce.rs b/lib/komainu/src/flow/pkce.rs index ab18441cc..fc3075b93 100644 --- a/lib/komainu/src/flow/pkce.rs +++ b/lib/komainu/src/flow/pkce.rs @@ -1,4 +1,4 @@ -use crate::{error::Error, flow::FlowError}; +use crate::{error::Error, flow}; use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; use std::borrow::Cow; @@ -22,7 +22,7 @@ pub struct Payload<'a> { impl Payload<'_> { #[inline] - fn verify_s256(&self, code_verifier: &str) -> Result<(), FlowError> { + fn verify_s256(&self, code_verifier: &str) -> Result<(), flow::Error> { let decoded = base64_simd::URL_SAFE_NO_PAD .decode_to_vec(self.challenge.as_bytes()) .inspect_err(|error| debug!(?error, "failed to decode pkce payload")) @@ -32,22 +32,22 @@ impl Payload<'_> { if decoded.ct_eq(hash.as_slice()).into() { Ok(()) } else { - Err(FlowError::InvalidGrant) + Err(flow::Error::InvalidGrant) } } #[inline] - fn verify_none(&self, code_verifier: &str) -> Result<(), FlowError> { + fn verify_none(&self, code_verifier: &str) -> Result<(), flow::Error> { let challenge_bytes = self.challenge.as_bytes(); if challenge_bytes.ct_eq(code_verifier.as_bytes()).into() { Ok(()) } else { - Err(FlowError::InvalidGrant) + Err(flow::Error::InvalidGrant) } } #[inline] - pub fn verify(&self, code_verifier: &str) -> Result<(), FlowError> { + pub fn verify(&self, code_verifier: &str) -> Result<(), flow::Error> { match self.method { Method::None => self.verify_none(code_verifier), Method::S256 => self.verify_s256(code_verifier), diff --git a/lib/komainu/src/flow/refresh.rs b/lib/komainu/src/flow/refresh.rs index 74c580bb8..658b450c1 100644 --- a/lib/komainu/src/flow/refresh.rs +++ b/lib/komainu/src/flow/refresh.rs @@ -1,6 +1,6 @@ use crate::{ extract::ClientCredentials, - flow::{FlowError, OptionExt, TokenResponse}, + flow::{self, OptionExt, TokenResponse}, params::ParamStorage, Client, ClientExtractor, }; @@ -12,7 +12,7 @@ pub trait Issuer { &self, client: &Client<'_>, refresh_token: &str, - ) -> impl Future, FlowError>> + Send; + ) -> impl Future, flow::Error>> + Send; } #[instrument(skip_all)] @@ -20,7 +20,7 @@ pub async fn perform( req: http::Request, client_extractor: CE, token_issuer: I, -) -> Result, FlowError> +) -> Result, flow::Error> where CE: ClientExtractor, I: Issuer, @@ -39,7 +39,7 @@ where if *grant_type != "refresh_token" { debug!(?client_id, "grant_type is not refresh_token"); - return Err(FlowError::UnsupportedGrantType); + return Err(flow::Error::UnsupportedGrantType); } let client = client_extractor