Passwordless   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 47
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A authenticate() 0 6 1
A __construct() 0 18 1
1
<?php
2
3
/**
4
 * FIDO2 Passwordless authentication source.
5
 *
6
 * @package simplesamlphp/simplesamlphp-module-webauthn
7
 */
8
9
declare(strict_types=1);
10
11
namespace SimpleSAML\Module\webauthn\Auth\Source;
12
13
use SimpleSAML\Auth\Source;
14
use SimpleSAML\Configuration;
15
use SimpleSAML\Module\webauthn\Controller\WebAuthn;
16
use SimpleSAML\Module\webauthn\WebAuthn\StateData;
17
use SimpleSAML\Module\webauthn\WebAuthn\StaticProcessHelper;
18
19
class Passwordless extends Source
20
{
21
    /**
22
     * An object with all the parameters that will be needed in the process
23
     *
24
     * @var \SimpleSAML\Module\webauthn\WebAuthn\StateData
25
     */
26
    protected StateData $stateData;
27
28
    /**
29
     * @var string|null AuthnContextClassRef
30
     */
31
    protected ?string $authnContextClassRef = null;
32
33
    /**
34
     * @var \SimpleSAML\Configuration $authSourceConfig
35
     */
36
    protected Configuration $authSourceConfig;
37
38
39
    public function __construct(array $info, array $config)
40
    {
41
        // Call the parent constructor first, as required by the interface
42
        parent::__construct($info, $config);
43
44
        $this->authSourceConfig = Configuration::loadFromArray(
45
            $config,
46
            'authsources[' . var_export($this->authId, true) . ']',
47
        );
48
        $this->authnContextClassRef = $this->authSourceConfig->getOptionalString(
49
            "authncontextclassref",
50
            'urn:rsa:names:tc:SAML:2.0:ac:classes:FIDO',
51
        );
52
        $moduleConfig = Configuration::getOptionalConfig('module_webauthn.php')->toArray();
53
54
        $initialStateData = new StateData();
55
        WebAuthn::loadModuleConfig($moduleConfig, $initialStateData);
56
        $this->stateData = $initialStateData;
57
    }
58
59
60
    public function authenticate(array &$state): void
61
    {
62
        $state['saml:AuthnContextClassRef'] = $this->authnContextClassRef;
63
64
        StaticProcessHelper::prepareStatePasswordlessAuth($this->stateData, $state);
65
        StaticProcessHelper::saveStateAndRedirect($state);
66
    }
67
}
68