diff options
author | FxQnLr <[email protected]> | 2024-02-25 15:15:19 +0100 |
---|---|---|
committer | FxQnLr <[email protected]> | 2024-02-25 15:15:19 +0100 |
commit | 9058f191b69ecafc8fdeace227ac113412d03888 (patch) | |
tree | 88ae071fa31c9a5831722ec82878ccf8fd2b224a /src/extractors.rs | |
parent | 2f9f18b80a9e2134f674f345e48a5f21de5efadd (diff) | |
download | webol-9058f191b69ecafc8fdeace227ac113412d03888.tar webol-9058f191b69ecafc8fdeace227ac113412d03888.tar.gz webol-9058f191b69ecafc8fdeace227ac113412d03888.zip |
Closes #16. Impl auth as extractor
Diffstat (limited to 'src/extractors.rs')
-rw-r--r-- | src/extractors.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/extractors.rs b/src/extractors.rs new file mode 100644 index 0000000..4d441e9 --- /dev/null +++ b/src/extractors.rs | |||
@@ -0,0 +1,24 @@ | |||
1 | use axum::{ | ||
2 | extract::{Request, State}, | ||
3 | http::{HeaderMap, StatusCode}, | ||
4 | middleware::Next, | ||
5 | response::Response, | ||
6 | }; | ||
7 | |||
8 | use crate::AppState; | ||
9 | |||
10 | pub async fn auth( | ||
11 | State(state): State<AppState>, | ||
12 | headers: HeaderMap, | ||
13 | request: Request, | ||
14 | next: Next, | ||
15 | ) -> Result<Response, StatusCode> { | ||
16 | let secret = headers.get("authorization"); | ||
17 | match secret { | ||
18 | Some(token) if token == state.config.apikey.as_str() => { | ||
19 | let response = next.run(request).await; | ||
20 | Ok(response) | ||
21 | } | ||
22 | _ => Err(StatusCode::UNAUTHORIZED), | ||
23 | } | ||
24 | } | ||