An Extension Output Checker (EOC) 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.
<?phpdeclare(strict_types=1);namespaceAcme\Extension;useWebauthn\AuthenticationExtensions\ExtensionOutputChecker;useWebauthn\AuthenticationExtensions\ExtensionOutputError;finalclassLocationExtensionOutputCheckerimplementsExtensionOutputChecker{publicfunctioncheck(AuthenticationExtensions $inputs,AuthenticationExtensions $outputs):void {if (!$inputs->has('loc')|| $inputs->get('loc')!==true) {return; }if (!$outputs->has('loc')) {//You may simply return but here we consider it is a mandatory extension output.thrownewExtensionOutputError( $inputs->get('loc'),'The location of the device is missing' ); } $location = $outputs->get('loc');//... Proceed with the output e.g. by logging the location of the device// or verifying it is in a specific area. }}
Extension Output Checker Handler
You can create as many EOC as needed. These services can be managed by a handler that will be injected to the Ceremony Step Manager Factory. Extensions will be automatically verified during the validation steps.
<?phpdeclare(strict_types=1);namespaceAcme\Extension;useWebauthn\AuthenticationExtensions\ExtensionOutputCheckerHandler;useWebauthn\CeremonyStep\CeremonyStepManagerFactory;$eocHandler =ExtensionOutputCheckerHandler::create();$eocHander->add(newLocationExtensionOutputChecker());// Add more EOC if needed.$csmFactory =newCeremonyStepManagerFactory();$csmFactory->setExtensionOutputCheckerHandler($eocHander);