Test Failed
Push — master ( 9eb68a...5271f3 )
by Thomas
02:48
created

AppIdExtension   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 12
c 1
b 0
f 1
dl 0
loc 29
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A parseResponse() 0 8 2
A processExtension() 0 12 4
A __construct() 0 3 1
1
<?php
2
3
namespace MadWizard\WebAuthn\Extension\AppId;
4
5
use MadWizard\WebAuthn\Exception\ExtensionException;
6
use MadWizard\WebAuthn\Exception\ParseException;
7
use MadWizard\WebAuthn\Extension\AbstractExtension;
8
use MadWizard\WebAuthn\Extension\ExtensionInputInterface;
9
use MadWizard\WebAuthn\Extension\ExtensionOutputInterface;
10
use MadWizard\WebAuthn\Extension\ExtensionProcessingContext;
11
use MadWizard\WebAuthn\Extension\ExtensionResponseInterface;
12
13
class AppIdExtension extends AbstractExtension
14
{
15
    public function __construct()
16
    {
17
        parent::__construct('appid', [self::OPERATION_AUTHENTICATION]);
18
    }
19
20
    public function parseResponse(ExtensionResponseInterface $extensionResponse): ExtensionOutputInterface
21
    {
22
        $extensionOutput = $extensionResponse->getClientExtensionOutput();
23
        if (!is_bool($extensionOutput)) {
24
            throw new ParseException('Expecting boolean value in appid extension output.');
25
        }
26
27
        return new AppIdExtensionOutput($extensionOutput);
28
    }
29
30
    public function processExtension(ExtensionInputInterface $input, ExtensionOutputInterface $output, ExtensionProcessingContext $context): void
31
    {
32
        if (!$input instanceof AppIdExtensionInput) {
33
            throw new ExtensionException('Expecting appid extension input to be AppIdExtensionInput.');
34
        }
35
        if (!$output instanceof AppIdExtensionOutput) {
36
            throw new ExtensionException('Expecting appid extension input to be AppIdExtensionInput.');
37
        }
38
        // SPEC: Client extension output: If true, the AppID was used and thus, when verifying an assertion,
39
        // the Relying Party MUST expect the rpIdHash to be the hash of the AppID, not the RP ID.
40
        if ($output->getAppIdUsed()) {
41
            $context->setOverruledRpId($input->getAppId());
42
        }
43
    }
44
}
45