pub enum Authentication {
Bearer(SecureString),
Basic {
username: String,
password: SecureString,
},
ApiKey {
header_name: String,
key: SecureString,
},
}
Expand description
Authentication configuration for API requests.
This enum supports various authentication methods commonly used in APIs. Authentication can be configured at the client level and optionally overridden for individual requests.
§Security Features
- Memory Protection: Sensitive data is automatically cleared from memory when dropped
- Display Masking: Credentials are never displayed in full for logging safety
- Debug Safety: Authentication data is redacted in debug output
§Examples
use clawspec_core::Authentication;
// Bearer token authentication
let auth = Authentication::Bearer("my-api-token".into());
// Basic authentication
let auth = Authentication::Basic {
username: "user".to_string(),
password: "pass".into(),
};
// API key in header
let auth = Authentication::ApiKey {
header_name: "X-API-Key".to_string(),
key: "secret-key".into(),
};
Variants§
Bearer(SecureString)
Bearer token authentication (RFC 6750)
Adds Authorization: Bearer <token>
header
Basic
HTTP Basic authentication (RFC 7617)
Adds Authorization: Basic <base64(username:password)>
header
ApiKey
API key authentication with custom header
Adds <header_name>: <key>
header
Implementations§
Source§impl Authentication
impl Authentication
Sourcepub fn to_header(
&self,
) -> Result<(HeaderName, HeaderValue), AuthenticationError>
pub fn to_header( &self, ) -> Result<(HeaderName, HeaderValue), AuthenticationError>
Converts the authentication into HTTP headers.
Returns a tuple of (HeaderName, HeaderValue) that can be added to the request.
§Errors
Returns AuthenticationError
if the authentication data contains invalid characters
or cannot be properly formatted for HTTP headers.
Trait Implementations§
Source§impl Clone for Authentication
impl Clone for Authentication
Source§fn clone(&self) -> Authentication
fn clone(&self) -> Authentication
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for Authentication
impl Debug for Authentication
Source§impl<'de> Deserialize<'de> for Authentication
impl<'de> Deserialize<'de> for Authentication
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for Authentication
impl Display for Authentication
Source§impl PartialEq for Authentication
impl PartialEq for Authentication
Source§impl Serialize for Authentication
impl Serialize for Authentication
impl Eq for Authentication
impl StructuralPartialEq for Authentication
Auto Trait Implementations§
impl Freeze for Authentication
impl RefUnwindSafe for Authentication
impl Send for Authentication
impl Sync for Authentication
impl Unpin for Authentication
impl UnwindSafe for Authentication
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string
, but without panic on OOM.