You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: advanced-topics/nested-tokens.md
+16-10
Original file line number
Diff line number
Diff line change
@@ -1,31 +1,38 @@
1
1
# Nested Tokens
2
2
3
-
JWT can be signed or encrypted and both operations can be performed when you needed. This library is able to create and load nested tokens using dedicated classes.
3
+
JWT can be signed or encrypted and both. A nested token is a signed token enclosed in an encrypted one. This order is very important: signed then encrypted.
4
4
5
-
The `NestedTokenLoader` and `NestedTokenBuilder` classes are available when the `web-token/jwt-encryption` component is installed. However, you must also install the following component to use it:
5
+
The `NestedTokenLoader` and `NestedTokenBuilder` classes will help you to create nested tokens with ease. They are provided by the `web-token/jwt-encryption` component. However, you must also install the following component to use it:
6
6
7
7
*`web-token/jwt-checker`
8
8
*`web-token/jwt-signature`
9
9
10
10
## Nested Token Loading
11
11
12
-
To instantiate the `NestedTokenLoader`, you just need a `JWSLoader` and a `JWELoader`.
12
+
To instantiate the `NestedTokenLoader`, you need a `JWSLoader` and a `JWELoader`.
13
13
14
14
```php
15
15
use Jose\Component\Encryption\NestedTokenLoader;
16
16
17
17
$nestedTokenLoader = new NestedTokenLoader($jweLoader, $jwsLoader);
18
18
```
19
19
20
-
Its use is very straightforward, you just have to call the method `load` using the token, the encryption and signature key sets. The last argument \(`$signature` in the following example\) will represents the signature used to verify the signed token. You should use this variable if the returned `JWS` object contains more than one signature.
20
+
Its use is very straightforward, you just have to call the method `load` using the token, the encryption and signature key sets.
21
+
22
+
The last argument \(`$signature` in the following example\) will represents the signature index of the verified signature. This is only useful when multiple signature support is used.
To instantiate the `NestedTokenBuilderder`, you will need a `JWSBuilder`, a `JWEBuilder`, a `JWESerializerManager` and a `JWSSerializerManager`.
30
+
To instantiate the `NestedTokenBuilderder`, you will need the following components:
31
+
32
+
* a `JWSBuilder`,
33
+
* a `JWEBuilder`,
34
+
* a `JWESerializerManager`,
35
+
* a `JWSSerializerManager`
29
36
30
37
```php
31
38
use Jose\Component\Encryption\NestedTokenBuilder;
@@ -55,7 +62,7 @@ $token = $builder->create(
55
62
);
56
63
```
57
64
58
-
As a remainder, if one of the following parameter is set, the compact serialization mode _cannot_ be used:
65
+
As a reminder, if one of the following parameter is set, the compact serialization mode _cannot_ be used:
59
66
60
67
* signature unprotected header,
61
68
* JWE shared unprotected header,
@@ -102,14 +109,11 @@ These services can be called from the container \(unless private\) or injected i
102
109
103
110
As any other services, you can create a nested token loader or builder from another bundle extension. The following bundle extension class will create the same configuration and services as above.
104
111
105
-
```yaml
112
+
```php
106
113
class AcmeExtension extends Extension implements PrependExtensionInterface
107
114
{
108
115
...
109
116
110
-
/**
111
-
* {@inheritdoc}
112
-
*/
113
117
public function prepend(ContainerBuilder $container)
0 commit comments