diff --git a/meilisearch-http/src/extractors/authentication/error.rs b/meilisearch-http/src/extractors/authentication/error.rs index c1af9a3ce..6d362dcbf 100644 --- a/meilisearch-http/src/extractors/authentication/error.rs +++ b/meilisearch-http/src/extractors/authentication/error.rs @@ -5,7 +5,7 @@ pub enum AuthenticationError { #[error("The Authorization header is missing. It must use the bearer authorization method.")] MissingAuthorizationHeader, #[error("The provided API key is invalid.")] - InvalidToken(String), + InvalidToken, // Triggered on configuration error. #[error("An internal error has occurred. `Irretrievable state`.")] IrretrievableState, @@ -15,7 +15,7 @@ impl ErrorCode for AuthenticationError { fn error_code(&self) -> Code { match self { AuthenticationError::MissingAuthorizationHeader => Code::MissingAuthorizationHeader, - AuthenticationError::InvalidToken(_) => Code::InvalidToken, + AuthenticationError::InvalidToken => Code::InvalidToken, AuthenticationError::IrretrievableState => Code::Internal, } } diff --git a/meilisearch-http/src/extractors/authentication/mod.rs b/meilisearch-http/src/extractors/authentication/mod.rs index 873f7cbcd..0a0d9ecfe 100644 --- a/meilisearch-http/src/extractors/authentication/mod.rs +++ b/meilisearch-http/src/extractors/authentication/mod.rs @@ -33,7 +33,7 @@ impl GuardedData { P: Policy + 'static, { match Self::authenticate(auth, token, index).await? { - (_, Some(filters)) => match data { + Some(filters) => match data { Some(data) => Ok(Self { data, filters, @@ -41,7 +41,7 @@ impl GuardedData { }), None => Err(AuthenticationError::IrretrievableState.into()), }, - (token, None) => Err(AuthenticationError::InvalidToken(token).into()), + None => Err(AuthenticationError::InvalidToken.into()), } } @@ -49,7 +49,7 @@ impl GuardedData { where P: Policy + 'static, { - match Self::authenticate(auth, "", None).await?.1 { + match Self::authenticate(auth, String::new(), None).await? { Some(filters) => match data { Some(data) => Ok(Self { data, @@ -62,18 +62,16 @@ impl GuardedData { } } - async fn authenticate( + async fn authenticate( auth: AuthController, - token: S, + token: String, index: Option, - ) -> Result<(S, Option), ResponseError> + ) -> Result, ResponseError> where P: Policy + 'static, - S: AsRef + 'static + Send, { Ok(tokio::task::spawn_blocking(move || { - let res = P::authenticate(auth, token.as_ref(), index.as_deref()); - (token, res) + P::authenticate(auth, token.as_ref(), index.as_deref()) }) .await .map_err(|e| ResponseError::from_msg(e.to_string(), Code::Internal))?) @@ -114,10 +112,7 @@ impl FromRequest for GuardedData index.map(String::from), req.app_data::().cloned(), )), - None => Box::pin(err(AuthenticationError::InvalidToken( - "unknown".to_string(), - ) - .into())), + None => Box::pin(err(AuthenticationError::InvalidToken.into())), } } _otherwise => {