File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -203,6 +203,42 @@ $jwks = ['keys' => []];
203
203
JWT::decode($payload, JWK::parseKeySet($jwks));
204
204
```
205
205
206
+ Using Cached Key Sets
207
+ ---------------------
208
+
209
+ The ` CachedKeySet ` class can be used to fetch JWK keys from a public URI. This has
210
+ the following advantages:
211
+
212
+ 1 . The results are cached for performance
213
+ 2 . If an unrecognized key is requested, the cache is refreshed, to accomodate for key rotation.
214
+
215
+ ``` php
216
+ use Firebase\JWT\CachedKeySet;
217
+ use Firebase\JWT\JWT;
218
+
219
+ // The URI for the JWK keys you wish to cash the results from
220
+ $jwkUri = 'https://www.gstatic.com/iap/verify/public_key-jwk';
221
+
222
+ // Create an HTTP client (can be any PSR-7 compatible HTTP client)
223
+ $httpClient = new GuzzleHttp\Client();
224
+
225
+ // Create an HTTP request factory (can be any PSR-17 compatible HTTP request factory)
226
+ $httpFactory = new GuzzleHttp\Psr\HttpFactory();
227
+
228
+ // Create a cache item pool (can be any PSR-6 compatible cache item pool)
229
+ $cacheItemPool = Phpfastcache\CacheManager::getInstance('files');
230
+
231
+ $keySet = new CachedKeySet(
232
+ $jwkUri,
233
+ $httpClient,
234
+ $httpFactory,
235
+ $cacheItemPool
236
+ );
237
+
238
+ $decoded = JWT::decode($payload, $keySet);
239
+ ```
240
+
241
+
206
242
Miscellaneous
207
243
-------------
208
244
You can’t perform that action at this time.
0 commit comments