
rust-axum.apis-mod.mustache Maven / Gradle / Ivy
The newest version!
{{#apiInfo}}
{{#apis}}
pub mod {{classFilename}};
{{/apis}}
{{/apiInfo}}
{{#authMethods}}
{{#isApiKey}}
{{#isKeyInCookie}}
/// Cookie Authentication.
#[async_trait::async_trait]
pub trait CookieAuthentication {
type Claims;
/// Extracting Claims from Cookie. Return None if the Claims are invalid.
async fn extract_claims_from_cookie(&self, cookies: &axum_extra::extract::CookieJar, key: &str) -> Option;
}
{{/isKeyInCookie}}
{{#isKeyInHeader}}
/// API Key Authentication - Header.
#[async_trait::async_trait]
pub trait ApiKeyAuthHeader {
type Claims;
/// Extracting Claims from Header. Return None if the Claims are invalid.
async fn extract_claims_from_header(&self, headers: &axum::http::header::HeaderMap, key: &str) -> Option;
}
{{/isKeyInHeader}}
{{/isApiKey}}
{{/authMethods}}
{{#havingBasicAuthMethods}}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum BasicAuthKind {
Basic,
Bearer,
}
/// API Key Authentication - Authentication Header.
/// For `Basic token` and `Bearer token`
#[async_trait::async_trait]
pub trait ApiAuthBasic {
type Claims;
/// Extracting Claims from Header. Return None if the Claims are invalid.
async fn extract_claims_from_auth_header(&self, kind: BasicAuthKind, headers: &axum::http::header::HeaderMap, key: &str) -> Option;
}
{{/havingBasicAuthMethods}}
// Error handler for unhandled errors.
#[async_trait::async_trait]
pub trait ErrorHandler {
#[allow(unused_variables)]
#[tracing::instrument(skip_all)]
async fn handle_error(
&self,
method: &::http::Method,
host: &axum_extra::extract::Host,
cookies: &axum_extra::extract::CookieJar,
error: E
) -> Result {
tracing::error!("Unhandled error: {:?}", error);
axum::response::Response::builder()
.status(http::StatusCode::INTERNAL_SERVER_ERROR)
.body(axum::body::Body::empty())
.map_err(|_| http::StatusCode::INTERNAL_SERVER_ERROR)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy