Use middleware to verify secret key (#4338)

This commit is contained in:
Jack Amadeo
2025-09-09 09:54:33 -04:00
committed by GitHub
parent 0969b80877
commit 9f53d39b88
27 changed files with 166 additions and 460 deletions
+22
View File
@@ -0,0 +1,22 @@
use axum::{
extract::{Request, State},
http::StatusCode,
middleware::Next,
response::Response,
};
pub async fn check_token(
State(state): State<String>,
request: Request,
next: Next,
) -> Result<Response, StatusCode> {
let secret_key = request
.headers()
.get("X-Secret-Key")
.and_then(|value| value.to_str().ok());
match secret_key {
Some(key) if key == state => Ok(next.run(request).await),
_ => Err(StatusCode::UNAUTHORIZED),
}
}