The passkey provider is Trilbdev\TwoFactorLibrary\Modules\Passkey\PasskeyProvider.
This provider offers a lightweight WebAuthn-style server-side building block for passkey flows. It includes:
- challenge generation for registration and authentication requests
- registration option generation
- registration verification helpers
- authentication option generation
- authentication verification helpers
- a simpler challenge/signature convenience API for lightweight credential validation
<?php
use Trilbdev\TwoFactorLibrary\TwoFactorAuthentication;
$auth = new TwoFactorAuthentication('Example', 'user@example.com');
$credential = $auth->passkey()->createCredential(
'user-123',
'user@example.com',
'challenge-123',
['rpId' => 'example.com']
);
$valid = $auth->passkey()->validateCredential(
$credential['id'],
'user@example.com',
'challenge-123',
$credential['signature'],
'example.com'
);<?php
$options = $auth->passkey()->createRegistrationOptions(
'user-123',
'user@example.com',
'Example User',
[
'rpId' => 'example.com',
'origin' => 'https://example.com',
'rpName' => 'Example',
'requireResidentKey' => false,
]
);
$clientDataJson = json_encode([
'type' => 'webauthn.create',
'challenge' => $options['challenge'],
'origin' => 'https://example.com',
'crossOrigin' => false,
], JSON_THROW_ON_ERROR);$verified = $auth->passkey()->verifyRegistration(
$clientDataJson,
$attestationObject,
$options['challenge'],
'example.com',
'https://example.com'
);<?php
$loginOptions = $auth->passkey()->createAuthenticationOptions(
['credential-1'],
['rpId' => 'example.com', 'origin' => 'https://example.com']
);$verified = $auth->passkey()->verifyAuthentication(
$clientDataJson,
$authenticatorData,
$signature,
$publicKeyPem,
$loginOptions['challenge'],
'example.com',
'https://example.com'
);The provider currently recognizes these platforms:
androidiosipadoswindowsmacoschromeos
$supports = $auth->passkey()->supportsPlatform('ios');createCredential(string $userId, string $email, string $challenge, array $options = []): arrayvalidateCredential(string $id, string $email, string $challenge, string $signature, ?string $rpId = null): boolcreateRegistrationOptions(string $userId, string $userName, string $displayName, array $options = []): arrayverifyRegistration(string $clientDataJson, string $attestationObject, string $challenge, string $rpId = 'example.com', string $origin = 'https://example.com'): boolcreateAuthenticationOptions(array $credentialIds = [], array $options = []): arrayverifyAuthentication(string $clientDataJson, string $authenticatorData, string $signature, string $publicKeyPem, string $challenge, string $rpId = 'example.com', string $origin = 'https://example.com'): boolsupportsPlatform(string $platform): bool
This is a lightweight passkey implementation intended for challenge validation and WebAuthn-style server flows. It is not a full browser credential manager or a full WebAuthn specification engine.