Passwordless   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 45
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 Configuration $authSourceConfig
35
     */
36
    protected Configuration $authSourceConfig;
37
38
    public function __construct(array $info, array $config)
39
    {
40
        // Call the parent constructor first, as required by the interface
41
        parent::__construct($info, $config);
42
43
        $this->authSourceConfig = Configuration::loadFromArray(
44
            $config,
45
            'authsources[' . var_export($this->authId, true) . ']',
46
        );
47
        $this->authnContextClassRef = $this->authSourceConfig->getOptionalString(
48
            "authncontextclassref",
49
            'urn:rsa:names:tc:SAML:2.0:ac:classes:FIDO',
50
        );
51
        $moduleConfig = Configuration::getOptionalConfig('module_webauthn.php')->toArray();
52
53
        $initialStateData = new StateData();
54
        WebAuthn::loadModuleConfig($moduleConfig, $initialStateData);
55
        $this->stateData = $initialStateData;
56
    }
57
58
    public function authenticate(array &$state): void
59
    {
60
        $state['saml:AuthnContextClassRef'] = $this->authnContextClassRef;
61
62
        StaticProcessHelper::prepareStatePasswordlessAuth($this->stateData, $state);
63
        StaticProcessHelper::saveStateAndRedirect($state);
64
    }
65
}
66