pub enum Authentication {
Bearer(SecureString),
Basic {
username: String,
password: SecureString,
},
ApiKey {
header_name: String,
key: SecureString,
},
OAuth2(SharedOAuth2Config),
}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.
Fields
password: SecureStringThe password for Basic authentication.
ApiKey
API key authentication with custom header.
Adds <header_name>: <key> header.
OAuth2(SharedOAuth2Config)
oauth2 only.OAuth2 authentication.
This variant requires the oauth2 feature to be enabled.
Tokens are acquired automatically and cached for reuse.
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
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<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.