Skip to content

Commit

Permalink
add Raw variant for Authorzation (#804)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyke-bot authored May 30, 2024
1 parent 7320d4c commit 2bff1dd
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion crates/transport/src/common.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use base64::{engine::general_purpose, Engine};
use std::{fmt, net::SocketAddr};

/// Basic or bearer authentication in http or websocket transport
/// Basic, bearer or raw authentication in http or websocket transport
///
/// Use to inject username and password or an auth token into requests
#[derive(Clone, Debug, PartialEq, Eq)]
Expand All @@ -10,6 +10,8 @@ pub enum Authorization {
Basic(String),
/// [RFC6750](https://datatracker.ietf.org/doc/html/rfc6750) Bearer Auth
Bearer(String),
/// Raw auth string
Raw(String),
}

impl Authorization {
Expand Down Expand Up @@ -43,13 +45,19 @@ impl Authorization {
pub fn bearer(token: impl Into<String>) -> Self {
Self::Bearer(token.into())
}

/// Instantiate a new raw auth from the given token.
pub fn raw(token: impl Into<String>) -> Self {
Self::Raw(token.into())
}
}

impl fmt::Display for Authorization {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Basic(auth) => write!(f, "Basic {auth}"),
Self::Bearer(auth) => write!(f, "Bearer {auth}"),
Self::Raw(auth) => write!(f, "{auth}"),
}
}
}

0 comments on commit 2bff1dd

Please sign in to comment.