Extensions

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!

The Symfony Way

The easiest way to manage that is by using the creation and request profiles.
config/packages/webauthn.yaml
1
webauthn:
2
3
creation_profiles:
4
default:
5
rp:
6
name: 'My Application'
7
id: 'example.com'
8
extensions:
9
loc: true
10
request_profiles:
11
default:
12
rp_id: 'example.com'
13
extensions:
14
loc: true
Copied!
Export as PDF
Copy link
Edit on GitHub