Files
tkmind_go/crates/goose-server/src/auth.rs
T
Douwe Osinga 9251da4314 Declarative providers (#5084)
Co-authored-by: Douwe Osinga <douwe@squareup.com>
Co-authored-by: Michael Neale <michael.neale@gmail.com>
2025-10-15 09:48:14 -04:00

26 lines
608 B
Rust

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> {
if request.uri().path() == "/status" {
return Ok(next.run(request).await);
}
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),
}
}