Failed Conditions
Push — master ( ed7204...c7c4bc )
by Florent
01:40
created

PublicKeyCredentialRequestOptions::getRpId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2018 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace U2FAuthentication\Fido2;
15
16
use Traversable;
17
use U2FAuthentication\Fido2\AuthenticationExtensions\AuthenticationExtensionsClientInputs;
18
19
class PublicKeyCredentialRequestOptions implements \JsonSerializable
20
{
21
    public const USER_VERIFICATION_REQUIREMENT_REQUIRED = 'required';
22
    public const USER_VERIFICATION_REQUIREMENT_PREFERRED = 'preferred';
23
    public const USER_VERIFICATION_REQUIREMENT_DISCOURAGED = 'discouraged';
24
25
    private $challenge;
26
27
    private $timeout;
28
29
    private $rpId;
30
31
    /**
32
     * @var PublicKeyCredentialDescriptor[]
33
     */
34
    private $allowCredentials;
35
36
    private $userVerification;
37
38
    private $extensions;
39
40
    /**
41
     * PublicKeyCredentialRequestOptions constructor.
42
     *
43
     * @param PublicKeyCredentialDescriptor[] $allowCredentials
44
     */
45
    public function __construct(string $challenge, ?int $timeout = null, ?string $rpId = null, array $allowCredentials = [], ?string $userVerification = null, ?AuthenticationExtensionsClientInputs $extensions = null)
46
    {
47
        $this->challenge = $challenge;
48
        $this->timeout = $timeout;
49
        $this->rpId = $rpId;
50
        $this->allowCredentials = $allowCredentials;
51
        $this->userVerification = $userVerification;
52
        $this->extensions = $extensions;
53
    }
54
55
    public function getChallenge(): string
56
    {
57
        return $this->challenge;
58
    }
59
60
    public function getTimeout(): ?int
61
    {
62
        return $this->timeout;
63
    }
64
65
    public function getRpId(): ?string
66
    {
67
        return $this->rpId;
68
    }
69
70
    /**
71
     * @return PublicKeyCredentialDescriptor[]
72
     */
73
    public function getAllowCredentials(): array
74
    {
75
        return $this->allowCredentials;
76
    }
77
78
    public function getUserVerification(): ?string
79
    {
80
        return $this->userVerification;
81
    }
82
83
    public function getExtensions(): ?AuthenticationExtensionsClientInputs
84
    {
85
        return $this->extensions;
86
    }
87
88
    public function jsonSerialize(): array
89
    {
90
        $json = [
91
            'challenge' => base64_encode($this->challenge),
92
        ];
93
94
        if ($this->rpId) {
95
            $json['rpId'] = $this->rpId;
96
        }
97
98
        if ($this->userVerification) {
99
            $json['userVerification'] = $this->userVerification;
100
        }
101
102
        if (!empty($this->allowCredentials)) {
103
            $json['allowCredentials'] = $this->allowCredentials;
104
        }
105
106
        if ($this->extensions && 0 !== $this->extensions->count()) {
107
            $json['extensions'] = $this->extensions;
108
        }
109
110
        if (!\is_null($this->timeout)) {
111
            $json['timeout'] = $this->timeout;
112
        }
113
114
        return $json;
115
    }
116
}
117