|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* The MIT License (MIT) |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (c) 2014-2016 Spomky-Labs |
|
7
|
|
|
* |
|
8
|
|
|
* This software may be modified and distributed under the terms |
|
9
|
|
|
* of the MIT license. See the LICENSE file for details. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace SpomkyLabs\JoseBundle\Helper; |
|
13
|
|
|
|
|
14
|
|
|
use Assert\Assertion; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* This helper will help you to create services configuration. |
|
18
|
|
|
*/ |
|
19
|
|
|
final class ConfigurationHelper |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @param string $name |
|
23
|
|
|
* @param string[] $header_checkers |
|
24
|
|
|
* @param string[] $claim_checkers |
|
25
|
|
|
* @param bool $is_public |
|
26
|
|
|
* |
|
27
|
|
|
* @return array |
|
28
|
|
|
*/ |
|
29
|
|
|
public static function getCheckerConfiguration($name, array $header_checkers, array $claim_checkers, $is_public = true) |
|
30
|
|
|
{ |
|
31
|
|
|
Assertion::string($name); |
|
32
|
|
|
Assertion::notEmpty($name); |
|
33
|
|
|
Assertion::allString($header_checkers); |
|
34
|
|
|
Assertion::allString($claim_checkers); |
|
35
|
|
|
|
|
36
|
|
|
return [ |
|
37
|
|
|
'jose' => [ |
|
38
|
|
|
'checkers' => [ |
|
39
|
|
|
$name => [ |
|
40
|
|
|
'is_public' => $is_public, |
|
41
|
|
|
'claims' => $claim_checkers, |
|
42
|
|
|
'headers' => $header_checkers, |
|
43
|
|
|
], |
|
44
|
|
|
], |
|
45
|
|
|
], |
|
46
|
|
|
]; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param string $name |
|
51
|
|
|
* @param string[] $signature_algorithms |
|
52
|
|
|
* @param bool $create_verifier |
|
53
|
|
|
* @param bool $is_public |
|
54
|
|
|
* |
|
55
|
|
|
* @return array |
|
56
|
|
|
*/ |
|
57
|
|
|
public static function getSignerConfiguration($name, array $signature_algorithms, $create_verifier = false, $is_public = true) |
|
58
|
|
|
{ |
|
59
|
|
|
Assertion::string($name); |
|
60
|
|
|
Assertion::notEmpty($name); |
|
61
|
|
|
Assertion::allString($signature_algorithms); |
|
62
|
|
|
Assertion::notEmpty($signature_algorithms); |
|
63
|
|
|
Assertion::boolean($create_verifier); |
|
64
|
|
|
|
|
65
|
|
|
return [ |
|
66
|
|
|
'jose' => [ |
|
67
|
|
|
'signers' => [ |
|
68
|
|
|
$name => [ |
|
69
|
|
|
'is_public' => $is_public, |
|
70
|
|
|
'algorithms' => $signature_algorithms, |
|
71
|
|
|
'create_verifier' => $create_verifier, |
|
72
|
|
|
], |
|
73
|
|
|
], |
|
74
|
|
|
], |
|
75
|
|
|
]; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @param string $name |
|
80
|
|
|
* @param string[] $signature_algorithms |
|
81
|
|
|
* @param bool $is_public |
|
82
|
|
|
* |
|
83
|
|
|
* @return array |
|
84
|
|
|
*/ |
|
85
|
|
|
public static function getVerifierConfiguration($name, array $signature_algorithms, $is_public = true) |
|
86
|
|
|
{ |
|
87
|
|
|
Assertion::string($name); |
|
88
|
|
|
Assertion::notEmpty($name); |
|
89
|
|
|
Assertion::allString($signature_algorithms); |
|
90
|
|
|
Assertion::notEmpty($signature_algorithms); |
|
91
|
|
|
|
|
92
|
|
|
return [ |
|
93
|
|
|
'jose' => [ |
|
94
|
|
|
'verifiers' => [ |
|
95
|
|
|
$name => [ |
|
96
|
|
|
'is_public' => $is_public, |
|
97
|
|
|
'algorithms' => $signature_algorithms, |
|
98
|
|
|
], |
|
99
|
|
|
], |
|
100
|
|
|
], |
|
101
|
|
|
]; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @param string $name |
|
106
|
|
|
* @param string[] $key_encryption_algorithms |
|
107
|
|
|
* @param string[] $content_encryption_algorithms |
|
108
|
|
|
* @param string[] $compression_methods |
|
109
|
|
|
* @param bool $create_decrypter |
|
110
|
|
|
* @param bool $is_public |
|
111
|
|
|
* |
|
112
|
|
|
* @return array |
|
113
|
|
|
*/ |
|
114
|
|
|
public static function getEncrypterConfiguration($name, array $key_encryption_algorithms, array $content_encryption_algorithms, array $compression_methods = ['DEF'], $create_decrypter = false, $is_public = true) |
|
115
|
|
|
{ |
|
116
|
|
|
Assertion::string($name); |
|
117
|
|
|
Assertion::notEmpty($name); |
|
118
|
|
|
Assertion::allString($key_encryption_algorithms); |
|
119
|
|
|
Assertion::notEmpty($key_encryption_algorithms); |
|
120
|
|
|
Assertion::allString($content_encryption_algorithms); |
|
121
|
|
|
Assertion::notEmpty($content_encryption_algorithms); |
|
122
|
|
|
Assertion::boolean($create_decrypter); |
|
123
|
|
|
|
|
124
|
|
|
return [ |
|
125
|
|
|
'jose' => [ |
|
126
|
|
|
'encrypters' => [ |
|
127
|
|
|
$name => [ |
|
128
|
|
|
'is_public' => $is_public, |
|
129
|
|
|
'key_encryption_algorithms' => $key_encryption_algorithms, |
|
130
|
|
|
'content_encryption_algorithms' => $content_encryption_algorithms, |
|
131
|
|
|
'compression_methods' => $compression_methods, |
|
132
|
|
|
'create_decrypter' => $create_decrypter, |
|
133
|
|
|
], |
|
134
|
|
|
], |
|
135
|
|
|
], |
|
136
|
|
|
]; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* @param string $name |
|
141
|
|
|
* @param string[] $key_encryption_algorithms |
|
142
|
|
|
* @param string[] $content_encryption_algorithms |
|
143
|
|
|
* @param string[] $compression_methods |
|
144
|
|
|
* @param bool $is_public |
|
145
|
|
|
* |
|
146
|
|
|
* @return array |
|
147
|
|
|
*/ |
|
148
|
|
|
public static function getDecrypterConfiguration($name, array $key_encryption_algorithms, array $content_encryption_algorithms, array $compression_methods = ['DEF'], $is_public = true) |
|
149
|
|
|
{ |
|
150
|
|
|
Assertion::string($name); |
|
151
|
|
|
Assertion::notEmpty($name); |
|
152
|
|
|
Assertion::allString($key_encryption_algorithms); |
|
153
|
|
|
Assertion::notEmpty($key_encryption_algorithms); |
|
154
|
|
|
Assertion::allString($content_encryption_algorithms); |
|
155
|
|
|
Assertion::notEmpty($content_encryption_algorithms); |
|
156
|
|
|
|
|
157
|
|
|
return [ |
|
158
|
|
|
'jose' => [ |
|
159
|
|
|
'decrypters' => [ |
|
160
|
|
|
$name => [ |
|
161
|
|
|
'is_public' => $is_public, |
|
162
|
|
|
'key_encryption_algorithms' => $key_encryption_algorithms, |
|
163
|
|
|
'content_encryption_algorithms' => $content_encryption_algorithms, |
|
164
|
|
|
'compression_methods' => $compression_methods, |
|
165
|
|
|
], |
|
166
|
|
|
], |
|
167
|
|
|
], |
|
168
|
|
|
]; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* @param string $name |
|
173
|
|
|
* @param string $signer |
|
174
|
|
|
* @param string|null $encrypter |
|
175
|
|
|
* @param bool $is_public |
|
176
|
|
|
* |
|
177
|
|
|
* @return array |
|
178
|
|
|
*/ |
|
179
|
|
|
public static function getJWTCreatorConfiguration($name, $signer, $encrypter = null, $is_public = true) |
|
180
|
|
|
{ |
|
181
|
|
|
Assertion::string($name); |
|
182
|
|
|
Assertion::notEmpty($name); |
|
183
|
|
|
Assertion::string($signer); |
|
184
|
|
|
Assertion::notEmpty($signer); |
|
185
|
|
|
Assertion::nullOrString($encrypter); |
|
186
|
|
|
|
|
187
|
|
|
return [ |
|
188
|
|
|
'jose' => [ |
|
189
|
|
|
'jwt_creators' => [ |
|
190
|
|
|
$name => [ |
|
191
|
|
|
'is_public' => $is_public, |
|
192
|
|
|
'signer' => $signer, |
|
193
|
|
|
'encrypter' => $encrypter, |
|
194
|
|
|
], |
|
195
|
|
|
], |
|
196
|
|
|
], |
|
197
|
|
|
]; |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* @param string $name |
|
202
|
|
|
* @param string $verifier |
|
203
|
|
|
* @param string $checker |
|
204
|
|
|
* @param string|null $decrypter |
|
205
|
|
|
* @param bool $is_public |
|
206
|
|
|
* |
|
207
|
|
|
* @return array |
|
208
|
|
|
*/ |
|
209
|
|
|
public static function getJWTLoaderConfiguration($name, $verifier, $checker, $decrypter = null, $is_public = true) |
|
210
|
|
|
{ |
|
211
|
|
|
Assertion::string($name); |
|
212
|
|
|
Assertion::notEmpty($name); |
|
213
|
|
|
Assertion::string($verifier); |
|
214
|
|
|
Assertion::notEmpty($verifier); |
|
215
|
|
|
Assertion::string($checker); |
|
216
|
|
|
Assertion::notEmpty($checker); |
|
217
|
|
|
Assertion::nullOrString($decrypter); |
|
218
|
|
|
|
|
219
|
|
|
return [ |
|
220
|
|
|
'jose' => [ |
|
221
|
|
|
'jwt_loaders' => [ |
|
222
|
|
|
$name => [ |
|
223
|
|
|
'is_public' => $is_public, |
|
224
|
|
|
'verifier' => $verifier, |
|
225
|
|
|
'checker' => $checker, |
|
226
|
|
|
'decrypter' => $decrypter, |
|
227
|
|
|
], |
|
228
|
|
|
], |
|
229
|
|
|
], |
|
230
|
|
|
]; |
|
231
|
|
|
} |
|
232
|
|
|
} |
|
233
|
|
|
|