1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Charcoal\User\Config; |
4
|
|
|
|
5
|
|
|
use InvalidArgumentException; |
6
|
|
|
|
7
|
|
|
// From locomotivemtl/charcoal-config |
8
|
|
|
use Charcoal\Config\AbstractConfig; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* JWT / auth configuration. |
12
|
|
|
*/ |
13
|
|
|
class JWTConfig extends AbstractConfig |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
private $privateKey; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
private $publicKey; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
public $id; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
public $issuer; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
public $audience; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var integer |
42
|
|
|
*/ |
43
|
|
|
public $expiration; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Sets the private key location. |
47
|
|
|
* |
48
|
|
|
* @param string $key The private key location. |
49
|
|
|
* @throws InvalidArgumentException If the argument is not a string. |
50
|
|
|
* @return self |
51
|
|
|
*/ |
52
|
|
|
public function setPrivateKey($key) |
53
|
|
|
{ |
54
|
|
|
if (!is_string($key)) { |
55
|
|
|
throw new InvalidArgumentException( |
56
|
|
|
'Private key must be a string.' |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
$this->privateKey = $key; |
60
|
|
|
return $this; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Retrieves the private key location. |
65
|
|
|
* |
66
|
|
|
* @return string |
67
|
|
|
*/ |
68
|
|
|
public function privateKey() |
69
|
|
|
{ |
70
|
|
|
return $this->privateKey; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Sets the public key location. |
75
|
|
|
* |
76
|
|
|
* @param string $key The public key location. |
77
|
|
|
* @throws InvalidArgumentException If the argument is not a string. |
78
|
|
|
* @return self |
79
|
|
|
*/ |
80
|
|
|
public function setPublicKey($key) |
81
|
|
|
{ |
82
|
|
|
if (!is_string($key)) { |
83
|
|
|
throw new InvalidArgumentException( |
84
|
|
|
'Public key must be a string.' |
85
|
|
|
); |
86
|
|
|
} |
87
|
|
|
$this->publicKey = $key; |
88
|
|
|
return $this; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Retrieves the public key location. |
93
|
|
|
* |
94
|
|
|
* @return string |
95
|
|
|
*/ |
96
|
|
|
public function publicKey() |
97
|
|
|
{ |
98
|
|
|
return $this->publicKey; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Sets the private key location. |
103
|
|
|
* |
104
|
|
|
* @param string $id The private key location. |
105
|
|
|
* @throws InvalidArgumentException If the argument is not a string. |
106
|
|
|
* @return self |
107
|
|
|
*/ |
108
|
|
|
public function setId($id) |
109
|
|
|
{ |
110
|
|
|
if (!is_string($id)) { |
111
|
|
|
throw new InvalidArgumentException( |
112
|
|
|
'Private key must be a string.' |
113
|
|
|
); |
114
|
|
|
} |
115
|
|
|
$this->id = $id; |
116
|
|
|
return $this; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Retrieves the private key location. |
121
|
|
|
* |
122
|
|
|
* @return string |
123
|
|
|
*/ |
124
|
|
|
public function id() |
125
|
|
|
{ |
126
|
|
|
return $this->id; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Sets the token issuer |
131
|
|
|
* |
132
|
|
|
* @param string $issuer The private key location. |
133
|
|
|
* @throws InvalidArgumentException If the argument is not a string. |
134
|
|
|
* @return self |
135
|
|
|
*/ |
136
|
|
|
public function setIssuer($issuer) |
137
|
|
|
{ |
138
|
|
|
if (!is_string($issuer)) { |
139
|
|
|
throw new InvalidArgumentException( |
140
|
|
|
'Private key must be a string.' |
141
|
|
|
); |
142
|
|
|
} |
143
|
|
|
$this->issuer = $issuer; |
144
|
|
|
return $this; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Retrieves the token issuer. |
149
|
|
|
* |
150
|
|
|
* @return string |
151
|
|
|
*/ |
152
|
|
|
public function issuer() |
153
|
|
|
{ |
154
|
|
|
return $this->issuer; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Sets the token audience. |
159
|
|
|
* |
160
|
|
|
* @param string $audience The token audience. |
161
|
|
|
* @throws InvalidArgumentException If the argument is not a string. |
162
|
|
|
* @return self |
163
|
|
|
*/ |
164
|
|
|
public function setAudience($audience) |
165
|
|
|
{ |
166
|
|
|
if (!is_string($audience)) { |
167
|
|
|
throw new InvalidArgumentException( |
168
|
|
|
'Private key must be a string.' |
169
|
|
|
); |
170
|
|
|
} |
171
|
|
|
$this->audience = $audience; |
172
|
|
|
return $this; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Retrieves the token audience. |
177
|
|
|
* |
178
|
|
|
* @return string |
179
|
|
|
*/ |
180
|
|
|
public function audience() |
181
|
|
|
{ |
182
|
|
|
return $this->audience; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Sets the expiration (in seconds). |
187
|
|
|
* |
188
|
|
|
* @param string|integer $expiration The expiration time, in seconds. |
189
|
|
|
* @return self |
190
|
|
|
*/ |
191
|
|
|
public function setExpiration($expiration) |
192
|
|
|
{ |
193
|
|
|
$this->expiration = (int)$expiration; |
194
|
|
|
return $this; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* Retrieves the expiration time (in seconds). |
199
|
|
|
* |
200
|
|
|
* @return integer |
201
|
|
|
*/ |
202
|
|
|
public function expiration() |
203
|
|
|
{ |
204
|
|
|
return $this->expiration; |
205
|
|
|
} |
206
|
|
|
} |
207
|
|
|
|