diff options
Diffstat (limited to 'src/auth.rs')
| -rw-r--r-- | src/auth.rs | 22 | 
1 files changed, 11 insertions, 11 deletions
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<T, Src: AuthSource> Authenticated<T, Src> {      async fn parse_auth<'a>(          request: &'a Request<'_>, -    ) -> Outcome<AuthKind<'a>, (Status, anyhow::Error), ()> { +    ) -> Outcome<AuthKind<'a>, (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<T, Src: AuthSource> Authenticated<T, Src> {          } 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<T,          let raw_json = match data.open(limit).into_string().await {              Ok(r) if r.is_complete() => 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<T,              },              Err(e) => {                  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<T,                      Category::Data => Status::UnprocessableEntity,                      _ => Status::BadRequest,                  }; -                Outcome::Failure((status, anyhow!(e))) +                Outcome::Error((status, anyhow!(e)))              },          }      }  | 
