adachsoft / auth-webauthn
WebAuthn passkey verification adapter for AdachSoft authentication contracts.
Requires
- php: ^8.3
- adachsoft/auth-contracts: ^0.5
- web-auth/webauthn-lib: ^5.3
Requires (Dev)
- adachsoft/php-code-style: ^0.7.4
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.3
- phpunit/phpunit: ^13
- rector/rector: ^2.9
- symplify/phpstan-rules: ^14.19
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
adachsoft/auth-webauthn provides the PasskeyVerifierInterface adapter for adachsoft/auth-contracts. It creates browser-ready WebAuthn options and verifies registration and authentication responses with web-auth/webauthn-lib. Cryptography, authenticator-data processing, and CBOR/COSE handling are delegated to that library.
Requirements and installation
Requires PHP 8.3 or later.
composer require adachsoft/auth-webauthn
Composer installs adachsoft/auth-contracts and web-auth/webauthn-lib together with the serialization dependencies required by webauthn-lib.
Usage
Wiring with PasskeyService
Create a relying-party configuration and supply the verifier to PasskeyService. The repositories, token generator, policy provider, and clock are provided by the host application.
<?php
declare(strict_types=1);
use AdachSoft\AuthContracts\Dto\RelyingPartyDto;
use AdachSoft\AuthContracts\Service\PasskeyService;
use AdachSoft\AuthWebauthn\WebauthnPasskeyVerifier;
$relyingParty = new RelyingPartyDto(
id: 'login.example.com',
name: 'Example Login',
origins: ['https://login.example.com'],
);
$passkeyService = new PasskeyService(
credentialRepository: $passkeyCredentialRepository,
challengeRepository: $passkeyChallengeRepository,
verifier: new WebauthnPasskeyVerifier(),
sessionRepository: $sessionRepository,
tokenGenerator: $tokenGenerator,
policyProvider: $policyProvider,
clock: $clock,
relyingParty: $relyingParty,
);
$registration = $passkeyService->startRegistration($accountId, $userName, $displayName);
// Return $registration->options as JSON to the browser.
The application owns HTTP routing and transport. Protect registration with the application's account authorization, send challenge IDs back to the matching finish operation, and preserve the one-time challenge handling performed by PasskeyService.
Relying-party configuration
The RP ID is a domain name only: do not include a scheme, port, or path. Origins must be exact origins (scheme, host, and optional port), with no path, trailing slash, wildcard, or subdomain expansion. Use HTTPS in production. Plain HTTP is accepted only for localhost development origins.
$relyingParty = new RelyingPartyDto(
id: 'example.com',
name: 'Example',
origins: [
'https://example.com',
'https://admin.example.com',
],
);
The RP ID may be a registrable parent domain such as example.com while each allowed origin remains an exact host. Add only origins controlled by the relying party.
Browser integration
The options are PHP arrays suitable for JSON encoding. Binary fields are represented as unpadded base64url strings:
- Registration:
challenge,user.id, and eachexcludeCredentials[].id. - Authentication:
challengeand eachallowCredentials[].id. - Browser responses:
id/rawId,clientDataJSON,attestationObject,authenticatorData,signature, and a non-nulluserHandle.
The browser must convert option fields that represent binary data to ArrayBuffer values before calling navigator.credentials.create() or navigator.credentials.get(). Convert response ArrayBuffer fields back to unpadded base64url when serializing the browser result as JSON. type and transports are ordinary strings; transport arrays are passed through unchanged. An empty allowCredentials list requests a discoverable credential.
Security behavior
- User verification is required for both ceremonies; registration also requires a resident credential.
- Attestation conveyance is
none; authenticator identity is not collected or trusted. - Challenges, exact allowed origins, RP ID hashes, signatures, authenticator data, and credential keys are validated by webauthn-lib. This package does not implement cryptography or parse CBOR/COSE itself.
- webauthn-lib's built-in counter rejection is disabled in the adapter. The verified counter is returned to
PasskeyService, which applies the counter policy before updating the stored credential. VerifiedPasskeyRegistrationDto::publicKeycontains an opaque serialized webauthn-libCredentialRecord. Store and return it unchanged; do not treat it as an application-level key format. Registration verification stores the decoded handle from the browser registration options in that record. During authentication, webauthn-lib rejects an assertion whose user handle differs from the expected stored handle.- Use HTTPS, CSRF protection, rate limiting, secure session transport, and persistent credential/challenge repositories in production. The relying-party challenge repository must preserve the single-use semantics provided by
PasskeyService.
Development
composer install
vendor/bin/phpunit
vendor/bin/phpstan analyse
vendor/bin/php-cs-fixer fix --dry-run
vendor/bin/rector process --dry-run