diff options
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 | } |