Crates.io | hmac-predicate |
lib.rs | hmac-predicate |
version | 0.6.0 |
source | src |
created_at | 2023-08-18 23:58:50.30724 |
updated_at | 2024-08-18 16:04:24.232531 |
description | Tower predicate HMAC verification of query params |
homepage | https://github.com/tobymurray/hmac-predicate |
repository | https://github.com/tobymurray/hmac-predicate |
max_upload_size | |
id | 948406 |
size | 8,166 |
Use something like:
use axum::error_handling::HandleErrorLayer;
use axum::Router;
use hmac_predicate::HmacQueryParamValidator;
use reqwest::StatusCode;
use tower::{BoxError, ServiceBuilder};
#[tokio::main]
async fn main() {
let predicate: HmacQueryParamValidator = HmacQueryParamValidator {
key: API_SECRET.to_string(),
};
let builder = ServiceBuilder::new()
.layer(HandleErrorLayer::new(handle_error))
.filter(predicate);
let app = Router::new()
.route("/", get(handler))
.layer(builder);
}
async fn handle_error(err: BoxError) -> (StatusCode, String) {
(
StatusCode::INTERNAL_SERVER_ERROR,
format!("Unhandled internal error: {}", err),
)
}