Passed
Push — master ( df7a06...000e40 )
by Tim
03:26
created

Passwordless::authenticate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
dl 0
loc 5
rs 10
c 1
b 0
f 0
eloc 3
nc 1
nop 1
1
<?php
2
3
/**
4
 * FIDO2 Passwordless authentication source.
5
 *
6
 * @package simplesamlphp/simplesamlphp-module-webauthn
7
 */
8
declare(strict_types=1);
9
10
namespace SimpleSAML\Module\webauthn\Auth\Source;
11
12
use SimpleSAML\Assert\Assert;
13
use SimpleSAML\Auth\Source;
14
use SimpleSAML\Configuration;
15
use SimpleSAML\Error;
16
use SimpleSAML\Logger;
17
use SimpleSAML\Module\webauthn\WebAuthn\StateData;
18
use SimpleSAML\Module\webauthn\WebAuthn\StaticProcessHelper;
19
use SimpleSAML\Module\webauthn\Controller\WebAuthn;
20
21
class Passwordless extends Source {
22
23
    /**
24
     * An object with all the parameters that will be needed in the process
25
     *
26
     * @var Module\webauthn\WebAuthn\StateData
0 ignored issues
show
Bug introduced by
The type SimpleSAML\Module\webaut...uthn\WebAuthn\StateData was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
27
     */
28
    private StateData $stateData;
29
30
    /**
31
     * @var string|null AuthnContextClassRef
32
     */
33
    private ?string $authnContextClassRef = null;
34
35
    /**
36
     * @var Configuration $authSourceConfig
37
     */
38
    private Configuration $authSourceConfig;
39
40
    public function __construct(array $info, array $config) {
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("authncontextclassref",'urn:rsa:names:tc:SAML:2.0:ac:classes:FIDO');
49
        $moduleConfig = Configuration::getOptionalConfig('module_webauthn.php')->toArray();
50
51
        $initialStateData = new StateData();
52
        WebAuthn::loadModuleConfig($moduleConfig, $initialStateData);
53
        $this->stateData = $initialStateData;
0 ignored issues
show
Documentation Bug introduced by
It seems like $initialStateData of type SimpleSAML\Module\webauthn\WebAuthn\StateData is incompatible with the declared type SimpleSAML\Module\webaut...uthn\WebAuthn\StateData of property $stateData.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
54
    }
55
56
    public function authenticate(array &$state): void {
57
        $state['saml:AuthnContextClassRef'] = $this->authnContextClassRef;
58
59
        StaticProcessHelper::prepareStatePasswordlessAuth($this->stateData, $state);
60
        StaticProcessHelper::saveStateAndRedirect($state);
61
    }
62
63
}
64