aboutsummaryrefslogtreecommitdiff
path: root/aero-proto/src/dav/middleware.rs
diff options
context:
space:
mode:
Diffstat (limited to 'aero-proto/src/dav/middleware.rs')
-rw-r--r--aero-proto/src/dav/middleware.rs28
1 files changed, 14 insertions, 14 deletions
diff --git a/aero-proto/src/dav/middleware.rs b/aero-proto/src/dav/middleware.rs
index e19ce14..8964699 100644
--- a/aero-proto/src/dav/middleware.rs
+++ b/aero-proto/src/dav/middleware.rs
@@ -1,10 +1,10 @@
use anyhow::{anyhow, Result};
use base64::Engine;
-use hyper::{Request, Response};
use hyper::body::Incoming;
+use hyper::{Request, Response};
-use aero_user::login::ArcLoginProvider;
use aero_collections::user::User;
+use aero_user::login::ArcLoginProvider;
use super::codec::text_body;
use super::controller::HttpResponse;
@@ -13,7 +13,7 @@ type ArcUser = std::sync::Arc<User>;
pub(super) async fn auth<'a>(
login: ArcLoginProvider,
- req: Request<Incoming>,
+ req: Request<Incoming>,
next: impl Fn(ArcUser, Request<Incoming>) -> futures::future::BoxFuture<'a, Result<HttpResponse>>,
) -> Result<HttpResponse> {
let auth_val = match req.headers().get(hyper::header::AUTHORIZATION) {
@@ -23,8 +23,8 @@ pub(super) async fn auth<'a>(
return Ok(Response::builder()
.status(401)
.header("WWW-Authenticate", "Basic realm=\"Aerogramme\"")
- .body(text_body("Missing Authorization field"))?)
- },
+ .body(text_body("Missing Authorization field"))?);
+ }
};
let b64_creds_maybe_padded = match auth_val.split_once(" ") {
@@ -33,8 +33,8 @@ pub(super) async fn auth<'a>(
tracing::info!("Unsupported authorization field");
return Ok(Response::builder()
.status(400)
- .body(text_body("Unsupported Authorization field"))?)
- },
+ .body(text_body("Unsupported Authorization field"))?);
+ }
};
// base64urlencoded may have trailing equals, base64urlsafe has not
@@ -44,22 +44,22 @@ pub(super) async fn auth<'a>(
// Decode base64
let creds = base64::engine::general_purpose::STANDARD_NO_PAD.decode(b64_creds_clean)?;
let str_creds = std::str::from_utf8(&creds)?;
-
+
// Split username and password
- let (username, password) = str_creds
- .split_once(':')
- .ok_or(anyhow!("Missing colon in Authorization, can't split decoded value into a username/password pair"))?;
+ let (username, password) = str_creds.split_once(':').ok_or(anyhow!(
+ "Missing colon in Authorization, can't split decoded value into a username/password pair"
+ ))?;
// Call login provider
let creds = match login.login(username, password).await {
Ok(c) => c,
Err(_) => {
- tracing::info!(user=username, "Wrong credentials");
+ tracing::info!(user = username, "Wrong credentials");
return Ok(Response::builder()
.status(401)
.header("WWW-Authenticate", "Basic realm=\"Aerogramme\"")
- .body(text_body("Wrong credentials"))?)
- },
+ .body(text_body("Wrong credentials"))?);
+ }
};
// Build a user