JWT Framework
Search…
Key Set (JWKSet)
You can create a JWKSet object using three static methods:
    new JWKSet(array $keys): creates a JWKSet using a list of JWK objects.
    JWKSet::createFromJson(string $json): creates a JWKSet using a JSON object.
    JWKSet::createFromKeyData(array $values): creates a JWKSet using a decoded JSON object.
Hereafter all methods available for a JWKSet object. The variable $jwkset is a valid JWKSet object.
Please note a JWKSet object is an immutable object
1
<?php
2
// Returns all keys
3
$jwkset->all();
4
5
// Check if the key set has the key with the key ID 'KEY ID'.
6
$jwkset->has('KEY ID');
7
8
// Retreive the key with the key ID 'KEY ID'.
9
$jwkset->get('KEY ID');
10
11
// Counts the keys in the key set.
12
$jwkset->count(); // The method count($jwkset) has the same behaviour.
13
14
// Adds a key to the key set.
15
// /!\ As the JWKSet object is immutable, this method will create a new key set. The previous key set is unchanged.
16
$newJwkset = $jwkset->with($jwk);
17
18
// Removes a key to the key set.
19
// /!\ As the JWKSet object is immutable, this method will create a new key set. The previous key set is unchanged.
20
$newJwkset = $jwkset->without('KEY ID');
21
22
// Selects a key according to the requirements.
23
// The first argument is the key usage ("sig" of "enc")
24
// The second argument is the algorithm to be used (optional)
25
// The third argument is an associative array this constraints (optional)
26
$key = $jwkset->selectKey('sig', $algorithm, ['kid' => 'KEY ID']);
27
28
// You can iterate on a key set
29
foreach($jwkset as $kid => $jwk) {
30
// Action with the key done here
31
}
32
33
// The JWKSet object can be serialized into JSON
34
json_encode($jwkset);
Copied!
Last modified 9mo ago
Copy link