aboutsummaryrefslogtreecommitdiff
path: root/src/extractors.rs
diff options
context:
space:
mode:
authorFxQnLr <[email protected]>2024-02-25 15:53:04 +0100
committerGitHub <[email protected]>2024-02-25 15:53:04 +0100
commitf0dc13f907a72ffef44f89b5e197567db129b020 (patch)
treed560273df2eece276cbda021cb4e95c044bb19df /src/extractors.rs
parentc663810817183c8f92a4279236ca84d271365088 (diff)
parent91cd665671d564620bce13e693cd7ecaad697db9 (diff)
downloadwebol-f0dc13f907a72ffef44f89b5e197567db129b020.tar
webol-f0dc13f907a72ffef44f89b5e197567db129b020.tar.gz
webol-f0dc13f907a72ffef44f89b5e197567db129b020.zip
Merge pull request #17 from FxQnLr/0.3.2
0.3.2
Diffstat (limited to 'src/extractors.rs')
-rw-r--r--src/extractors.rs24
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 @@
1use axum::{
2 extract::{Request, State},
3 http::{HeaderMap, StatusCode},
4 middleware::Next,
5 response::Response,
6};
7
8use crate::AppState;
9
10pub 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}