PasskeyAuthMethod

Struct PasskeyAuthMethod 

Source
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

  1. Generate registration challenge with user and relying party information
  2. Client creates credential using authenticator
  3. Verify attestation and store public key
  4. Associate passkey with user account

§Authentication Flow

  1. Generate authentication challenge
  2. Client signs challenge with private key
  3. Verify signature using stored public key
  4. 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

Source

pub fn new(config: PasskeyConfig, token_manager: TokenManager) -> Result<Self>

Create a new passkey authentication method

Source

pub async fn register_passkey( &mut self, _user_id: &str, _user_name: &str, _user_display_name: &str, ) -> Result<()>

Fallback for when passkeys feature is disabled

Source§

impl PasskeyAuthMethod

Source

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

Source

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

Source§

type MethodResult = MethodResult

Source§

type AuthToken = AuthToken

Source§

fn name(&self) -> &str

Get the name of this authentication method.
Source§

async fn authenticate( &self, credential: Credential, _metadata: CredentialMetadata, ) -> Result<Self::MethodResult>

Authenticate using the provided credentials.
Source§

fn validate_config(&self) -> Result<()>

Validate configuration for this method.
Source§

fn supports_refresh(&self) -> bool

Check if this method supports refresh tokens.
Source§

async fn refresh_token( &self, _refresh_token: String, ) -> Result<Self::AuthToken, AuthError>

Refresh a token if supported.
Source§

impl Debug for PasskeyAuthMethod

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,