1. Go to this page and download the library: Download pronin/webauthn-emulator library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
pronin / webauthn-emulator example snippets
use WebauthnEmulator\Authenticator;
use WebauthnEmulator\CredentialRepository\FileRepository;
// Instantiate the file repository to store credentials
$storage = new FileRepository('path/to/credential/storage.txt');
// Create the authenticator instance
$authenticator = new Authenticator($storage);
use WebauthnEmulator\Authenticator;
use WebauthnEmulator\CredentialRepository\FileRepository;
// Instantiate the file repository to store credentials
$storage = new FileRepository('path/to/credential/storage.txt');
// Create the authenticator instance
$authenticator = new Authenticator($storage);
$registrationChallenge = [
// ... (challenge data provided by the relying party)
];
// Generate a response to the registration challenge
$attestation = $authenticator->getAttestation(
registerOptions: $registrationChallenge,
origin: 'https://service.example.com', // optional
extra: ['crossOrigin' => false] // optional
);
echo(json_encode($attestation, JSON_PRETTY_PRINT));
/* Output:
{
"id": "HB_Pkygg...LQK3WkA",
"rawId": "HB\/Pkygg...LQK3WkA=",
"response": {
"clientDataJSON": "eyJ0e...pbyJ9",
"attestationObject": "o2Nmb...y4kw="
},
"type": "public-key"
}
*/
use WebauthnEmulator\Authenticator;
// Example of recoding a standard base64 string to base64url
echo Authenticator::base64Normal2Url('wib1OPW9EkDeiwUoyTgJ1+PpFG4dljeXodqRX15DG+gBAAAABQ==');
// Output: wib1OPW9EkDeiwUoyTgJ1-PpFG4dljeXodqRX15DG-gBAAAABQ
// Example of recoding a base64url string to standard base64
echo Authenticator::base64Url2Normal('wib1OPW9EkDeiwUoyTgJ1-PpFG4dljeXodqRX15DG-gBAAAABQ');
// Output: wib1OPW9EkDeiwUoyTgJ1+PpFG4dljeXodqRX15DG+gBAAAABQ==
use WebauthnEmulator\Authenticator;
$input = [
"id" => "HB_PkyggPmHCHbcYyQCfLXTakdmq3WGCcOBjLQK3WkA", // already base64url-encoded
"rawId" => "HB/PkyggPmHCHbcYyQCfLXTakdmq3WGCcOBjLQK3WkA=", // standard base64
];
// Example of recoding an array of standard base64 strings to base64url
$base64urlArray = Authenticator::base64Normal2Url($input);
/* Result:
[
"id" => "HB_PkyggPmHCHbcYyQCfLXTakdmq3WGCcOBjLQK3WkA", // left as is
"rawId" => "HB_PkyggPmHCHbcYyQCfLXTakdmq3WGCcOBjLQK3WkA", // recoded to base64url
]
*/
// Example of recoding an array of base64url to standard base64
$base64Array = Authenticator::base64Url2Normal($input);
/* Result:
[
"id" => "HB/PkyggPmHCHbcYyQCfLXTakdmq3WGCcOBjLQK3WkA=", // recoded to standard base64
"rawId" => "HB/PkyggPmHCHbcYyQCfLXTakdmq3WGCcOBjLQK3WkA=", // left as is
]
*/
use WebauthnEmulator\CredentialRepository\FileRepository;
// Path to the JSON file that will store the credentials
$storagePath = 'path/to/credential/storage.txt';
// Create a new FileRepository instance
$storage = new FileRepository($storagePath);
use WebauthnEmulator\CredentialRepository\RepositoryInterface;
use WebauthnEmulator\CredentialInterface;
class CustomRepository implements RepositoryInterface {
// Implement the retrieve credentials by rpId
}
public function getById(string $rpId, string $id): CredentialInterface {
// Logic to retrieve a credential by rpId and id
}
}
use WebauthnEmulator\Authenticator;
// Assuming $customStorage is an instance of your custom repository
$authenticator = new Authenticator($customStorage);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.