From 22711c21d0213ae78132c28b56be98f9d53af456 Mon Sep 17 00:00:00 2001 From: pennae Date: Sat, 17 Aug 2024 01:23:36 +0200 Subject: update for deps --- src/auth.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/auth.rs') diff --git a/src/auth.rs b/src/auth.rs index 304ab0f..57d481d 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -76,21 +76,21 @@ impl Authenticated { async fn parse_auth<'a>( request: &'a Request<'_>, - ) -> Outcome, (Status, anyhow::Error), ()> { + ) -> Outcome, (Status, anyhow::Error), Status> { let auth = match request.headers().get("authorization").take(2).enumerate().last() { Some((0, h)) => h, Some((_, _)) => { - return Outcome::Failure(( + return Outcome::Error(( Status::BadRequest, anyhow!("multiple authorization headers present"), )) }, - None => return Outcome::Forward(()), + None => return Outcome::Forward(Status::Unauthorized), }; if let Some(hawk) = drop_auth_prefix(auth, "hawk ") { match Header::from_str(hawk) { Ok(header) => Outcome::Success(AuthKind::Hawk { header }), - Err(e) => Outcome::Failure(( + Err(e) => Outcome::Error(( Status::Unauthorized, anyhow!(e).context("malformed hawk header"), )), @@ -98,14 +98,14 @@ impl Authenticated { } else if let Some(token) = drop_auth_prefix(auth, "bearer ") { Outcome::Success(AuthKind::Token { token }) } else { - Outcome::Forward(()) + Outcome::Forward(Status::Unauthorized) } } pub async fn get_conn<'r>(req: &'r Request<'_>) -> Result<&'r DbConn> { match <&'r DbConn as FromRequest<'r>>::from_request(req).await { Outcome::Success(db) => Ok(db), - Outcome::Failure((_, e)) => Err(e.context("get db connection")), + Outcome::Error((_, e)) => Err(e.context("get db connection")), _ => Err(anyhow!("could not get db connection")), } } @@ -168,7 +168,7 @@ impl<'r, Src: AuthSource> FromRequest<'r> for Authenticated<(), Src> { }, Err(e) => { request.local_cache(|| Some(InvalidTokenUsed)); - Outcome::Failure((Status::Unauthorized, anyhow!(e))) + Outcome::Error((Status::Unauthorized, anyhow!(e))) }, } } @@ -185,12 +185,12 @@ impl<'r, T: Deserialize<'r>, Src: AuthSource> FromData<'r> for Authenticated local_cache!(request, r.into_inner()), Ok(_) => { - return data::Outcome::Failure(( + return data::Outcome::Error(( Status::PayloadTooLarge, anyhow!("request too large"), )) }, - Err(e) => return data::Outcome::Failure((Status::InternalServerError, e.into())), + Err(e) => return data::Outcome::Error((Status::InternalServerError, e.into())), }; let verify_result = match auth { AuthKind::Hawk { header } => Self::verify_hawk(request, header, Some(raw_json)).await, @@ -202,7 +202,7 @@ impl<'r, T: Deserialize<'r>, Src: AuthSource> FromData<'r> for Authenticated { request.local_cache(|| Some(InvalidTokenUsed)); - return Outcome::Failure((Status::Unauthorized, anyhow!(e))); + return Outcome::Error((Status::Unauthorized, anyhow!(e))); }, }; match result { @@ -213,7 +213,7 @@ impl<'r, T: Deserialize<'r>, Src: AuthSource> FromData<'r> for Authenticated Status::UnprocessableEntity, _ => Status::BadRequest, }; - Outcome::Failure((status, anyhow!(e))) + Outcome::Error((status, anyhow!(e))) }, } } -- cgit v1.2.3