pub enum Credential {
Show 13 variants
Password {
username: String,
password: String,
},
OAuth {
authorization_code: String,
redirect_uri: Option<String>,
code_verifier: Option<String>,
state: Option<String>,
},
OAuthRefresh {
refresh_token: String,
},
ApiKey {
key: String,
},
Jwt {
token: String,
},
Bearer {
token: String,
},
Basic {
credentials: String,
},
Custom {
method: String,
data: HashMap<String, String>,
},
Mfa {
primary_credential: Box<Credential>,
mfa_code: String,
challenge_id: String,
},
Certificate {
certificate: Vec<u8>,
private_key: Vec<u8>,
passphrase: Option<String>,
},
OpenIdConnect {
id_token: String,
access_token: Option<String>,
refresh_token: Option<String>,
},
DeviceCode {
device_code: String,
client_id: String,
user_code: Option<String>,
verification_uri: Option<String>,
verification_uri_complete: Option<String>,
expires_in: Option<u64>,
interval: Option<u64>,
},
EnhancedDeviceFlow {
device_code: String,
user_code: String,
verification_uri: String,
verification_uri_complete: Option<String>,
expires_in: u64,
interval: u64,
client_id: String,
client_secret: Option<String>,
scopes: Vec<String>,
},
}Expand description
Represents different types of credentials that can be used for authentication.
Variants§
Password
Username and password credentials
OAuth
OAuth authorization code flow
OAuthRefresh
OAuth refresh token
ApiKey
API key authentication
Jwt
JSON Web Token
Bearer
Bearer token (generic)
Basic
Basic authentication (username:password base64 encoded)
Custom
Custom authentication with flexible key-value pairs
Mfa
Multi-factor authentication token
Certificate
Certificate-based authentication
OpenIdConnect
OpenID Connect ID token
DeviceCode
Device flow credentials (device code polling)
Fields
EnhancedDeviceFlow
Enhanced device flow credentials with full OAuth device flow support
Implementations§
Source§impl Credential
impl Credential
Sourcepub fn password(
username: impl Into<String>,
password: impl Into<String>,
) -> Self
pub fn password( username: impl Into<String>, password: impl Into<String>, ) -> Self
Create password credentials.
§Example
let cred = Credential::password("alice", "s3cret!");
assert_eq!(cred.credential_type(), "password");Sourcepub fn oauth_code(authorization_code: impl Into<String>) -> Self
pub fn oauth_code(authorization_code: impl Into<String>) -> Self
Create OAuth authorization code credentials.
Start with the authorization code only; attach optional fields like
redirect_uri via the OAuth variant’s public fields.
Sourcepub fn oauth_code_with_pkce(
authorization_code: impl Into<String>,
code_verifier: impl Into<String>,
) -> Self
pub fn oauth_code_with_pkce( authorization_code: impl Into<String>, code_verifier: impl Into<String>, ) -> Self
Create OAuth authorization code credentials with PKCE.
Includes a code verifier for the Proof Key for Code Exchange flow.
Sourcepub fn oauth_refresh(refresh_token: impl Into<String>) -> Self
pub fn oauth_refresh(refresh_token: impl Into<String>) -> Self
Create OAuth refresh token credentials
Sourcepub fn device_code(
device_code: impl Into<String>,
client_id: impl Into<String>,
) -> Self
pub fn device_code( device_code: impl Into<String>, client_id: impl Into<String>, ) -> Self
Create device code credentials for device flow.
Starts a device authorization grant with just the device code and
client ID. Optional fields (user_code, verification_uri, etc.)
are available on the DeviceCode variant.
Sourcepub fn basic(username: impl Into<String>, password: impl Into<String>) -> Self
pub fn basic(username: impl Into<String>, password: impl Into<String>) -> Self
Create basic authentication credentials
Sourcepub fn custom(method: impl Into<String>, data: HashMap<String, String>) -> Self
pub fn custom(method: impl Into<String>, data: HashMap<String, String>) -> Self
Create custom credentials with arbitrary key-value data.
The method string identifies the custom auth method, while
data carries method-specific fields.
§Example
use std::collections::HashMap;
let mut data = HashMap::new();
data.insert("hardware_token".into(), "ABC123".into());
let cred = Credential::custom("hardware", data);Sourcepub fn mfa(
primary_credential: Credential,
mfa_code: impl Into<String>,
challenge_id: impl Into<String>,
) -> Self
pub fn mfa( primary_credential: Credential, mfa_code: impl Into<String>, challenge_id: impl Into<String>, ) -> Self
Create MFA credentials that wrap a primary credential with a second-factor code and challenge identifier.
Sourcepub fn certificate(
certificate: Vec<u8>,
private_key: Vec<u8>,
passphrase: Option<String>,
) -> Self
pub fn certificate( certificate: Vec<u8>, private_key: Vec<u8>, passphrase: Option<String>, ) -> Self
Create certificate credentials from raw DER-encoded bytes.
For certificates already verified by TLS, consider
client_cert_from_tls instead.
Sourcepub fn client_cert_from_tls(der_certificate: Vec<u8>) -> Self
pub fn client_cert_from_tls(der_certificate: Vec<u8>) -> Self
Create credentials representing a client certificate that was already verified by the mTLS handshake. The private key is not required — key possession was proved by TLS; supplying one has no effect.
Sourcepub fn openid_connect(id_token: impl Into<String>) -> Self
pub fn openid_connect(id_token: impl Into<String>) -> Self
Create SAML assertion credentials - REMOVED for security
Create OpenID Connect credentials
Sourcepub fn credential_type(&self) -> &str
pub fn credential_type(&self) -> &str
Get the credential type as a string
Sourcepub fn supports_refresh(&self) -> bool
pub fn supports_refresh(&self) -> bool
Check if this credential supports refresh
Sourcepub fn refresh_token(&self) -> Option<&str>
pub fn refresh_token(&self) -> Option<&str>
Extract refresh token if available
Sourcepub fn is_sensitive(&self) -> bool
pub fn is_sensitive(&self) -> bool
Check if this credential is sensitive and should be masked in logs
Sourcepub fn safe_display(&self) -> String
pub fn safe_display(&self) -> String
Get a safe representation for logging (masks sensitive data)
Trait Implementations§
Source§impl Clone for Credential
impl Clone for Credential
Source§fn clone(&self) -> Credential
fn clone(&self) -> Credential
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Credential
impl Debug for Credential
Source§impl<'de> Deserialize<'de> for Credential
impl<'de> Deserialize<'de> for Credential
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>,
Auto Trait Implementations§
impl Freeze for Credential
impl RefUnwindSafe for Credential
impl Send for Credential
impl Sync for Credential
impl Unpin for Credential
impl UnsafeUnpin for Credential
impl UnwindSafe for Credential
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more