Extensions
The following example is totally fictive. We will add an extension input loc=true to the request option object.
1
<?php
2
3
declare(strict_types=1);
4
5
use Webauthn\AuthenticationExtensions\AuthenticationExtension;
6
use Webauthn\AuthenticationExtensions\AuthenticationExtensionsClientInputs;
7
use Webauthn\PublicKeyCredentialRequestOptions;
8
9
// Extensions
10
$extensions = AuthenticationExtensionsClientInputs::create()
11
->add(AuthenticationExtension::create('loc', true))
12
;
13
14
// Public Key Credential Request Options
15
$publicKeyCredentialRequestOptions =
16
PublicKeyCredentialRequestOptions::create(
17
random_bytes(32) // Challenge
18
)
19
->setExtensions($extensions)
20
;
Copied!

Extension Output Checker

An Extension Output Checker will check the extension output.
It must implement the interface Webauthn\AuthenticationExtensions\ExtensionOutputChecker and throw an exception of type Webauthn\AuthenticationExtension\ExtensionOutputError in case of error.
Devices may ignore the extension inputs. The extension outputs are therefore not guaranteed.
In the previous example, we asked for the location of the device and we expect to receive geolocation data in the extension output.
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Acme\Extension;
6
7
use Webauthn\AuthenticationExtensions\ExtensionOutputChecker;
8
use Webauthn\AuthenticationExtensions\ExtensionOutputError;
9
10
final class LocationExtensionOutputChecker
11
{
12
public function check(AuthenticationExtensionsClientInputs $inputs, AuthenticationExtensionsClientOutputs $outputs): void
13
{
14
if (!$inputs->has('loc') || $inputs->get('loc') !== true) {
15
return;
16
}
17
18
if (!$outputs->has('loc')) {
19
//You may simply return but here we consider it is a mandatory extension output.
20
throw new ExtensionOutputError(
21
$inputs->get('loc'),
22
'The location of the device is missing'
23
);
24
}
25
26
$location = $outputs->get('loc');
27
//... Proceed with the output e.g. by logging the location of the device
28
// or verifying it is in a specific area.
29
}
30
}
Copied!
Export as PDF
Copy link
Edit on GitHub