Skip to content

Commit a988ee2

Browse files
Spomkygitbook-bot
Spomky
authored andcommitted
GitBook: [master] one page modified
1 parent e45fbce commit a988ee2

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

advanced-topics/nested-tokens.md

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,38 @@
11
# Nested Tokens
22

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.
44

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:
66

77
* `web-token/jwt-checker`
88
* `web-token/jwt-signature`
99

1010
## Nested Token Loading
1111

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`.
1313

1414
```php
1515
use Jose\Component\Encryption\NestedTokenLoader;
1616

1717
$nestedTokenLoader = new NestedTokenLoader($jweLoader, $jwsLoader);
1818
```
1919

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.
2123

2224
```php
2325
$jws = $nestedTokenLoader->load($token, $encryptionKeySet, $signatureKeySet, $signature);
2426
```
2527

2628
## Nested Token Building
2729

28-
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`
2936

3037
```php
3138
use Jose\Component\Encryption\NestedTokenBuilder;
@@ -55,7 +62,7 @@ $token = $builder->create(
5562
);
5663
```
5764

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:
5966

6067
* signature unprotected header,
6168
* JWE shared unprotected header,
@@ -102,14 +109,11 @@ These services can be called from the container \(unless private\) or injected i
102109

103110
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.
104111

105-
```yaml
112+
```php
106113
class AcmeExtension extends Extension implements PrependExtensionInterface
107114
{
108115
...
109116
110-
/**
111-
* {@inheritdoc}
112-
*/
113117
public function prepend(ContainerBuilder $container)
114118
{
115119
ConfigurationHelper::addNestedTokenLoader($container, 'loader_1', ['jwe_compact'], ['RSA-OAEP'], ['A128GCM'], ['DEF'], [], ['jws_compact'], ['PS256'], [], true, []);
@@ -118,3 +122,5 @@ class AcmeExtension extends Extension implements PrependExtensionInterface
118122
}
119123
```
120124

125+
126+

0 commit comments

Comments
 (0)