pub struct PasskeyAuthMethod {
pub config: PasskeyConfig,
pub token_manager: TokenManager,
pub registered_passkeys: RwLock<HashMap<String, PasskeyRegistration>>,
}
Expand description
Passkey/WebAuthn authentication method implementing FIDO2 standards.
PasskeyAuthMethod
provides a pure Rust implementation of WebAuthn/FIDO2
passkey authentication, supporting both platform authenticators (built into
devices) and roaming authenticators (USB security keys).
§Features
- FIDO2/WebAuthn Compliance: Implements the latest WebAuthn Level 2 specification
- Cross-Platform Support: Works with Windows Hello, Touch ID, YubiKey, and other authenticators
- Phishing Resistance: Cryptographic binding to origin prevents phishing attacks
- Passwordless Authentication: Eliminates password-related vulnerabilities
- Multi-Device Support: Users can register multiple authenticators
§Security Properties
- Public Key Cryptography: Each passkey uses unique key pairs
- Origin Binding: Passkeys are cryptographically bound to the website origin
- User Verification: Supports biometric and PIN-based user verification
- Replay Protection: Each authentication uses unique challenges
- Privacy: No biometric data leaves the user’s device
§Authenticator Types Supported
- Platform Authenticators: Windows Hello, Touch ID, Android Biometrics
- Roaming Authenticators: YubiKey, SoloKey, other FIDO2 security keys
- Hybrid Transport: QR code-based authentication between devices
§Registration Flow
- Generate registration challenge with user and relying party information
- Client creates credential using authenticator
- Verify attestation and store public key
- Associate passkey with user account
§Authentication Flow
- Generate authentication challenge
- Client signs challenge with private key
- Verify signature using stored public key
- Return authentication result
§Example
use auth_framework::methods::passkey::{PasskeyAuthMethod, PasskeyConfig};
let config = PasskeyConfig {
rp_name: "Example Corp".to_string(),
rp_id: "example.com".to_string(),
origin: "https://example.com".to_string(),
timeout: 60000,
require_user_verification: true,
};
let passkey_method = PasskeyAuthMethod::new(config, token_manager)?;
// Register a new passkey
let challenge = passkey_method.start_registration("user123", "user@example.com").await?;
// Authenticate with passkey
let auth_challenge = passkey_method.start_authentication("user123").await?;
§Thread Safety
This implementation is thread-safe and can be used in concurrent environments.
The internal passkey storage uses RwLock
for safe concurrent access.
§Production Considerations
- Replace in-memory storage with persistent database in production
- Configure appropriate timeout values for user experience
- Implement proper error handling for unsupported browsers
- Consider implementing credential management for device changes
Fields§
§config: PasskeyConfig
§token_manager: TokenManager
§registered_passkeys: RwLock<HashMap<String, PasskeyRegistration>>
Storage for registered passkeys (in production, use a database)
Implementations§
Source§impl PasskeyAuthMethod
impl PasskeyAuthMethod
Sourcepub fn new(config: PasskeyConfig, token_manager: TokenManager) -> Result<Self>
pub fn new(config: PasskeyConfig, token_manager: TokenManager) -> Result<Self>
Create a new passkey authentication method
Source§impl PasskeyAuthMethod
impl PasskeyAuthMethod
Sourcepub async fn advanced_verification_flow(
&self,
assertion_response: &str,
expected_challenge: &[u8],
stored_counter: u32,
public_key_jwk: &Value,
) -> Result<AdvancedVerificationResult>
pub async fn advanced_verification_flow( &self, assertion_response: &str, expected_challenge: &[u8], stored_counter: u32, public_key_jwk: &Value, ) -> Result<AdvancedVerificationResult>
Advanced passkey verification with full WebAuthn compliance Implements proper signature verification, replay protection, and attestation validation
Sourcepub async fn cross_platform_verification(
&self,
assertion_response: &str,
authenticator_types: &[AuthenticatorType],
) -> Result<CrossPlatformVerificationResult>
pub async fn cross_platform_verification( &self, assertion_response: &str, authenticator_types: &[AuthenticatorType], ) -> Result<CrossPlatformVerificationResult>
Cross-platform passkey verification for multiple authenticator types
Trait Implementations§
Source§impl AuthMethod for PasskeyAuthMethod
impl AuthMethod for PasskeyAuthMethod
type MethodResult = MethodResult
type AuthToken = AuthToken
Source§async fn authenticate(
&self,
credential: Credential,
_metadata: CredentialMetadata,
) -> Result<Self::MethodResult>
async fn authenticate( &self, credential: Credential, _metadata: CredentialMetadata, ) -> Result<Self::MethodResult>
Authenticate using the provided credentials.
Source§fn validate_config(&self) -> Result<()>
fn validate_config(&self) -> Result<()>
Validate configuration for this method.
Source§fn supports_refresh(&self) -> bool
fn supports_refresh(&self) -> bool
Check if this method supports refresh tokens.
Auto Trait Implementations§
impl !Freeze for PasskeyAuthMethod
impl RefUnwindSafe for PasskeyAuthMethod
impl Send for PasskeyAuthMethod
impl Sync for PasskeyAuthMethod
impl Unpin for PasskeyAuthMethod
impl UnwindSafe for PasskeyAuthMethod
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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