diff options
author | FxQnLr <[email protected]> | 2024-04-10 20:15:39 +0200 |
---|---|---|
committer | FxQnLr <[email protected]> | 2024-04-10 20:15:39 +0200 |
commit | 69d3e0e6564b416637978a69f0a035066aea4759 (patch) | |
tree | 90c5b80a808f9c71cd3440add52b023973ae5b3b /src/auth.rs | |
parent | 07740f3d985b4cc921b69cd45ec9191a2daecd67 (diff) | |
download | webol-69d3e0e6564b416637978a69f0a035066aea4759.tar webol-69d3e0e6564b416637978a69f0a035066aea4759.tar.gz webol-69d3e0e6564b416637978a69f0a035066aea4759.zip |
Closes #30 and #27. At least a little
Diffstat (limited to 'src/auth.rs')
-rw-r--r-- | src/auth.rs | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/auth.rs b/src/auth.rs index 74008b5..c662e36 100644 --- a/src/auth.rs +++ b/src/auth.rs | |||
@@ -6,6 +6,7 @@ use axum::{ | |||
6 | response::Response, | 6 | response::Response, |
7 | }; | 7 | }; |
8 | use serde::Deserialize; | 8 | use serde::Deserialize; |
9 | use tracing::trace; | ||
9 | 10 | ||
10 | #[derive(Debug, Clone, Deserialize)] | 11 | #[derive(Debug, Clone, Deserialize)] |
11 | pub enum Methods { | 12 | pub enum Methods { |
@@ -20,15 +21,19 @@ pub async fn auth( | |||
20 | next: Next, | 21 | next: Next, |
21 | ) -> Result<Response, StatusCode> { | 22 | ) -> Result<Response, StatusCode> { |
22 | let auth = state.config.auth; | 23 | let auth = state.config.auth; |
24 | trace!(?auth.method, "auth request"); | ||
23 | match auth.method { | 25 | match auth.method { |
24 | Methods::Key => { | 26 | Methods::Key => { |
25 | if let Some(secret) = headers.get("authorization") { | 27 | if let Some(secret) = headers.get("authorization") { |
26 | if auth.secret.as_str() != secret { | 28 | if auth.secret.as_str() != secret { |
29 | trace!("auth failed, unknown secret"); | ||
27 | return Err(StatusCode::UNAUTHORIZED); | 30 | return Err(StatusCode::UNAUTHORIZED); |
28 | }; | 31 | }; |
32 | trace!("auth successfull"); | ||
29 | let response = next.run(request).await; | 33 | let response = next.run(request).await; |
30 | Ok(response) | 34 | Ok(response) |
31 | } else { | 35 | } else { |
36 | trace!("auth failed, no secret"); | ||
32 | Err(StatusCode::UNAUTHORIZED) | 37 | Err(StatusCode::UNAUTHORIZED) |
33 | } | 38 | } |
34 | } | 39 | } |