Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/auth_basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,19 @@ use http::{request::Parts, StatusCode};
/// - \`Authorization\` header must be for basic authentication – Someone tried to use bearer auth instead of basic auth
/// - \`Authorization\` header is missing – The header was required but it wasn't found
/// - \`Authorization\` header contains invalid characters – The header couldn't be processed because of invalid characters
#[derive(Debug, PartialEq, Eq, Clone)]
#[derive(PartialEq, Eq, Clone)]
pub struct AuthBasic(pub (String, Option<String>));

/// Manually implement Debug for AuthBasic to prevent password from being accidentally printed
impl std::fmt::Debug for AuthBasic {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("AuthBasic")
.field("id", &self.0 .0)
.field("password", &"********")
.finish()
}
}

#[async_trait]
impl<B> FromRequestParts<B> for AuthBasic
where
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub(crate) trait DecodeRequestParts: Sized {
}

/// Gets the auth header from [Parts] of the request or errors with [ERR_CHARS] or [ERR_MISSING] if wrong
pub(crate) fn get_header(parts: &mut Parts, err_code: StatusCode) -> Result<&str, Rejection> {
pub(crate) fn get_header(parts: &Parts, err_code: StatusCode) -> Result<&str, Rejection> {
parts
.headers
.get(AUTHORIZATION)
Expand Down