mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-05-29 08:58:02 +02:00
ffefd0caf2
implements: https://github.com/meilisearch/specifications/blob/develop/text/0085-api-keys.md - Add tests on API keys management route (meilisearch-http/tests/auth/api_keys.rs) - Add tests checking authorizations on each meilisearch routes (meilisearch-http/tests/auth/authorization.rs) - Implement API keys management routes (meilisearch-http/src/routes/api_key.rs) - Create module to manage API keys and authorizations (meilisearch-auth) - Reimplement GuardedData to extend authorizations (meilisearch-http/src/extractors/authentication/mod.rs) - Change X-MEILI-API-KEY by Authorization Bearer (meilisearch-http/src/extractors/authentication/mod.rs) - Change meilisearch routes to fit to the new authorization feature (meilisearch-http/src/routes/) - close #1867
23 lines
808 B
Rust
23 lines
808 B
Rust
use meilisearch_error::{Code, ErrorCode};
|
|
|
|
#[derive(Debug, thiserror::Error)]
|
|
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),
|
|
// Triggered on configuration error.
|
|
#[error("An internal error has occurred. `Irretrievable state`.")]
|
|
IrretrievableState,
|
|
}
|
|
|
|
impl ErrorCode for AuthenticationError {
|
|
fn error_code(&self) -> Code {
|
|
match self {
|
|
AuthenticationError::MissingAuthorizationHeader => Code::MissingAuthorizationHeader,
|
|
AuthenticationError::InvalidToken(_) => Code::InvalidToken,
|
|
AuthenticationError::IrretrievableState => Code::Internal,
|
|
}
|
|
}
|
|
}
|