1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Gandung\JWT\Accessor; |
4
|
|
|
|
5
|
|
|
use Gandung\JWT\Validator\Validator; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @author Paulus Gandung Prakosa <[email protected]> |
9
|
|
|
*/ |
10
|
|
|
class JoseHeaderAccessor implements JoseHeaderAccessorInterface |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var array |
14
|
|
|
*/ |
15
|
|
|
private $jose; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var \Gandung\JWT\ValidatorInterface |
19
|
|
|
*/ |
20
|
|
|
private $validator; |
21
|
|
|
|
22
|
|
|
public function __construct($header) |
23
|
|
|
{ |
24
|
|
|
$this->jose = $header; |
25
|
|
|
$this->configureValidator(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* {@inheritdoc} |
30
|
|
|
*/ |
31
|
|
|
public function getAlgorithm(): string |
32
|
|
|
{ |
33
|
|
|
$this->validator->validateFromArray( |
|
|
|
|
34
|
|
|
$this->jose, |
35
|
|
|
new \Gandung\JWT\Validator\Constraints\Jose\Algorithm |
36
|
|
|
); |
37
|
|
|
|
38
|
|
|
return $this->jose[\Gandung\JWT\Token\Jose::ALGORITHM]; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
|
|
public function getJwkSetUrl(): string |
45
|
|
|
{ |
46
|
|
|
$this->validator->validateFromArray( |
|
|
|
|
47
|
|
|
$this->jose, |
48
|
|
|
new \Gandung\JWT\Validator\Constraints\Jose\JWKSetUrl |
49
|
|
|
); |
50
|
|
|
|
51
|
|
|
return $this->jose[\Gandung\JWT\Token\Jose::JWK_SET_URL]; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* {@inheritdoc} |
56
|
|
|
*/ |
57
|
|
|
public function getJsonWebKey(): string |
58
|
|
|
{ |
59
|
|
|
$this->validator->validateFromArray( |
|
|
|
|
60
|
|
|
$this->jose, |
61
|
|
|
new \Gandung\JWT\Validator\Constraints\Jose\JsonWebKey |
62
|
|
|
); |
63
|
|
|
|
64
|
|
|
return $this->jose[\Gandung\JWT\Token\Jose::JSON_WEB_KEY]; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* {@inheritdoc} |
69
|
|
|
*/ |
70
|
|
|
public function getKeyID(): string |
71
|
|
|
{ |
72
|
|
|
$this->validator->validateFromArray( |
|
|
|
|
73
|
|
|
$this->jose, |
74
|
|
|
new \Gandung\JWT\Validator\Constraints\Jose\KeyID |
75
|
|
|
); |
76
|
|
|
|
77
|
|
|
return $this->jose[\Gandung\JWT\Token\Jose::KEY_ID]; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* {@inheritdoc} |
82
|
|
|
*/ |
83
|
|
|
public function getX509Url(): string |
84
|
|
|
{ |
85
|
|
|
$this->validator->validateFromArray( |
|
|
|
|
86
|
|
|
$this->jose, |
87
|
|
|
new \Gandung\JWT\Validator\Constraints\Jose\X509Url |
88
|
|
|
); |
89
|
|
|
|
90
|
|
|
return $this->jose[\Gandung\JWT\Token\Jose::X509_URL]; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* {@inheritdoc} |
95
|
|
|
*/ |
96
|
|
|
public function getX509CertificateChain(): string |
97
|
|
|
{ |
98
|
|
|
$this->validator->validateFromArray( |
|
|
|
|
99
|
|
|
$this->jose, |
100
|
|
|
new \Gandung\JWT\Validator\Constraints\Jose\X509CertificateChain |
101
|
|
|
); |
102
|
|
|
|
103
|
|
|
return $this->jose[\Gandung\JWT\Token\Jose::X509_CERTIFICATE_CHAIN]; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* {@inheritdoc} |
108
|
|
|
*/ |
109
|
|
|
public function getType(): string |
110
|
|
|
{ |
111
|
|
|
$this->validator->validateFromArray( |
|
|
|
|
112
|
|
|
$this->jose, |
113
|
|
|
new \Gandung\JWT\Validator\Constraints\Jose\Type |
114
|
|
|
); |
115
|
|
|
|
116
|
|
|
return $this->jose[\Gandung\JWT\Token\Jose::TYPE]; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* {@inheritdoc} |
121
|
|
|
*/ |
122
|
|
|
public function getContentType(): string |
123
|
|
|
{ |
124
|
|
|
$this->validator->validateFromArray( |
|
|
|
|
125
|
|
|
$this->jose, |
126
|
|
|
new \Gandung\JWT\Validator\Constraints\Jose\ContentType |
127
|
|
|
); |
128
|
|
|
|
129
|
|
|
return $this->jose[\Gandung\JWT\Token\Jose::CONTENT_TYPE]; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* {@inheritdoc} |
134
|
|
|
*/ |
135
|
|
|
public function get(): array |
136
|
|
|
{ |
137
|
|
|
return $this->jose; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Configure validator object. |
142
|
|
|
* |
143
|
|
|
* @param array $constraints |
144
|
|
|
* @return void |
145
|
|
|
*/ |
146
|
|
|
private function configureValidator($constraints = []) |
147
|
|
|
{ |
148
|
|
|
$this->validator = new Validator; |
149
|
|
|
|
150
|
|
|
foreach ($constraints as $v) { |
151
|
|
|
$this->validator->addConstraint($v); |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.