Initial implementation: relay server + common protocol + client stub
This commit is contained in:
commit
7285a33cff
17 changed files with 926 additions and 0 deletions
26
crates/server/src/auth.rs
Normal file
26
crates/server/src/auth.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
use axum::{
|
||||
extract::{Request, State},
|
||||
http::StatusCode,
|
||||
middleware::Next,
|
||||
response::Response,
|
||||
};
|
||||
use crate::AppState;
|
||||
|
||||
/// Axum middleware that checks the `X-Api-Key` header.
|
||||
pub async fn require_api_key(
|
||||
State(state): State<AppState>,
|
||||
req: Request,
|
||||
next: Next,
|
||||
) -> Result<Response, StatusCode> {
|
||||
let key = req
|
||||
.headers()
|
||||
.get("X-Api-Key")
|
||||
.and_then(|v| v.to_str().ok())
|
||||
.unwrap_or("");
|
||||
|
||||
if key != state.api_key {
|
||||
return Err(StatusCode::UNAUTHORIZED);
|
||||
}
|
||||
|
||||
Ok(next.run(req).await)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue