Skip to content

Commit bcd5bba

Browse files
Spomkygitbook-bot
Spomky
authored andcommitted
GitBook: [master] 24 pages modified
1 parent b6f3281 commit bcd5bba

24 files changed

+181
-133
lines changed

SUMMARY.md

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
* [JWE creation](symfony-bundle/encrypted-tokens/jwe-creation.md)
3232
* [JWE decryption](symfony-bundle/encrypted-tokens/jwe-decryption.md)
3333
* [Configuration Helper](symfony-bundle/configuration-helper.md)
34+
* [Events](symfony-bundle/events.md)
35+
* [Profiling/Debugging](symfony-bundle/profiling-debugging.md)
3436
* [Console](console/README.md)
3537
* [Standalone Application](console/standalone.md)
3638
* [Symfony Console](console/symfony-console.md)
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
# Encrypted tokens and
22

3+
4+

advanced-topics/nested-tokens.md

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ The `NestedTokenLoader` and `NestedTokenBuilder` classes will help you to create
77
* `web-token/jwt-checker`
88
* `web-token/jwt-signature`
99

10+
**New in version 2.0**: a new package is available: `web-token/jwt-nested-token`. This package contains all the classes and dependencies will be directly managed by composer. You can install it if needed.
11+
1012
## Nested Token Loading
1113

1214
To instantiate the `NestedTokenLoader`, you need a `JWSLoader` and a `JWELoader`.

advanced-topics/serialization.md

+6-12
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,12 @@ The serializer manager can be helpful when your application deals more than one
9898

9999
require_once 'vendor/autoload.php';
100100

101-
use Jose\Component\Core\Converter\StandardConverter;
102101
use Jose\Component\Signature\Serializer;
103102

104-
$jsonConverter = new StandardConverter();
105-
106103
$manager = Serializer\JWSSerializerManager::create([
107-
new Serializer\CompactSerializer($jsonConverter),
108-
new Serializer\JSONFlattenedSerializer($jsonConverter),
109-
new Serializer\JSONGeneralSerializer($jsonConverter),
104+
new Serializer\CompactSerializer(),
105+
new Serializer\JSONFlattenedSerializer(),
106+
new Serializer\JSONGeneralSerializer(),
110107
]);
111108

112109
// Serializes the second signature (index = 1) of the variable $jws (JWS object) into JSON Flattened serialization mode.
@@ -194,15 +191,12 @@ The serializer manager can be helpful when your application deals more than one
194191

195192
require_once 'vendor/autoload.php';
196193

197-
use Jose\Component\Core\Converter\StandardConverter;
198194
use Jose\Component\Encryption\Serializer;
199195

200-
$jsonConverter = new StandardConverter();
201-
202196
$manager = Serializer\JWESerializerManager::create([
203-
new Serializer\CompactSerializer($jsonConverter),
204-
new Serializer\JSONFlattenedSerializer($jsonConverter),
205-
new Serializer\JSONGeneralSerializer($jsonConverter),
197+
new Serializer\CompactSerializer(),
198+
new Serializer\JSONFlattenedSerializer(),
199+
new Serializer\JSONGeneralSerializer(),
206200
]);
207201

208202
// Serializes the second recipient (index = 1) of the variable $jwe (JWE object) into JSON Flattened serialization mode.
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
# Signed tokens and
22

3+
4+

advanced-topics/signed-tokens-and/detached-payload.md

+8-19
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,28 @@ There is not much difference between the creation of a JWS with or without detac
1010
<?php
1111

1212
use Jose\Component\Core\AlgorithmManager;
13-
use Jose\Component\Core\Converter\StandardConverter;
1413
use Jose\Component\Core\JWK;
1514
use Jose\Component\Signature\Algorithm\HS256;
1615
use Jose\Component\Signature\JWSBuilder;
1716

1817
// The algorithm manager with the HS256 algorithm.
19-
$algorithmManager = AlgorithmManager::create([
18+
$algorithmManager = new AlgorithmManager([
2019
new HS256(),
2120
]);
2221

2322
// Our key.
24-
$jwk = JWK::create([
23+
$jwk = new JWK([
2524
'kty' => 'oct',
2625
'k' => 'dzI6nbW4OcNF-AtfxGAmuyz7IpHRudBI0WgGjZWgaRJt6prBn3DARXgUR8NVwKhfL43QBIU2Un3AvCGCHRgY4TbEqhOi8-i98xxmCggNjde4oaW6wkJ2NgM3Ss9SOX9zS3lcVzdCMdum-RwVJ301kbin4UtGztuzJBeg5oVN00MGxjC2xWwyI0tgXVs-zJs5WlafCuGfX1HrVkIf5bvpE0MQCSjdJpSeVao6-RSTYDajZf7T88a2eVjeW31mMAg-jzAWfUrii61T_bYPJFOXW8kkRWoa1InLRdG6bKB9wQs9-VdXZP60Q4Yuj_WZ-lO7qV9AEFrUkkjpaDgZT86w2g',
2726
]);
2827

29-
// The JSON Converter.
30-
$jsonConverter = new StandardConverter();
31-
3228
// We instantiate our JWS Builder.
3329
$jwsBuilder = new JWSBuilder(
34-
$jsonConverter,
3530
$algorithmManager
3631
);
3732

3833
// The payload we want to sign
39-
$payload = $jsonConverter->encode([
34+
$payload = json_encode([
4035
'iat' => time(),
4136
'nbf' => time(),
4237
'exp' => time() + 3600,
@@ -61,36 +56,30 @@ The loading of a signed token with a detached payload is as easy as when the pay
6156
<?php
6257

6358
use Jose\Component\Core\AlgorithmManager;
64-
use Jose\Component\Core\Converter\StandardConverter;
6559
use Jose\Component\Core\JWK;
6660
use Jose\Component\Signature\Algorithm\HS256;
6761
use Jose\Component\Signature\JWSVerifier;
6862
use Jose\Component\Signature\Serializer\JWSSerializerManager;
6963
use Jose\Component\Signature\Serializer\CompactSerializer;
7064

7165
// The algorithm manager with the HS256 algorithm.
72-
$algorithmManager = AlgorithmManager::create([
66+
$algorithmManager = new AlgorithmManager([
7367
new HS256(),
7468
]);
7569

7670
// Our key.
77-
$jwk = JWK::create([
71+
$jwk = new JWK([
7872
'kty' => 'oct',
7973
'k' => 'dzI6nbW4OcNF-AtfxGAmuyz7IpHRudBI0WgGjZWgaRJt6prBn3DARXgUR8NVwKhfL43QBIU2Un3AvCGCHRgY4TbEqhOi8-i98xxmCggNjde4oaW6wkJ2NgM3Ss9SOX9zS3lcVzdCMdum-RwVJ301kbin4UtGztuzJBeg5oVN00MGxjC2xWwyI0tgXVs-zJs5WlafCuGfX1HrVkIf5bvpE0MQCSjdJpSeVao6-RSTYDajZf7T88a2eVjeW31mMAg-jzAWfUrii61T_bYPJFOXW8kkRWoa1InLRdG6bKB9wQs9-VdXZP60Q4Yuj_WZ-lO7qV9AEFrUkkjpaDgZT86w2g',
8074
]);
8175

82-
// The JSON Converter.
83-
$jsonConverter = new StandardConverter();
84-
8576
// The serializer manager. We only use the JWS Compact Serialization Mode.
86-
$serializerManager = JWSSerializerManager::create([
87-
new CompactSerializer($jsonConverter),
77+
$serializerManager = new JWSSerializerManager([
78+
new CompactSerializer(),
8879
]);
8980

9081
// We instantiate our JWS Verifier.
91-
$jwsVerifier = new JWSVerifier(
92-
$algorithmManager
93-
);
82+
$jwsVerifier = new JWSVerifier($algorithmManager);
9483

9584
// The detached payload
9685
$payload = '{"iat":1507896992,"nbf":1507896992,"exp":1507900592,"iss":"My service","aud":"Your application"}';

advanced-topics/signed-tokens-and/multiple-signatures.md

+3-7
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,12 @@ $jws = $jwsBuilder
1717
The variable `$jws` will be a valid JWS object with all computed signatures. Next step is the serialization of these signatures.
1818

1919
```php
20-
use Jose\Component\Core\Converter\StandardConverter;
2120
use Jose\Component\Signature\Serializer;
2221

23-
// The JSON Converter.
24-
$jsonConverter = new StandardConverter();
25-
2622
$manager = Serializer\JWSSerializerManager::create([
27-
new Serializer\CompactSerializer($jsonConverter),
28-
new Serializer\JsonFlattenedSerializer($jsonConverter),
29-
new Serializer\JsonGeneralSerializer($jsonConverter),
23+
new Serializer\CompactSerializer(),
24+
new Serializer\JsonFlattenedSerializer(),
25+
new Serializer\JsonGeneralSerializer(),
3026
]);
3127

3228
$tokenWithAllSignatures = $manager->serialize('jws_json_general', $jws);

components/algorithm-management-jwa.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use Jose\Component\Core\AlgorithmManager;
2121
use Jose\Component\Signature\Algorithm\PS256;
2222
use Jose\Component\Signature\Algorithm\ES512;
2323

24-
$algorithm_manager = AlgorithmManager::create([
24+
$algorithm_manager = new AlgorithmManager([
2525
new PS256(),
2626
new ES512(),
2727
]);

components/claim-checker.md

+3-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ In the following example, we will create a manager able to check the `aud` \(Aud
1818
use Jose\Component\Checker\ClaimCheckerManager;
1919
use Jose\Component\Checker;
2020

21-
$claimCheckerManager = ClaimCheckerManager::create(
21+
$claimCheckerManager = new ClaimCheckerManager(
2222
[
2323
new Checker\IssuedAtChecker(),
2424
new Checker\NotBeforeChecker(),
@@ -28,14 +28,10 @@ $claimCheckerManager = ClaimCheckerManager::create(
2828
);
2929
```
3030

31-
When instantiated, call the method `check` to check the claims of a JWT object. This method only accept an array. You have to retrieve this array by converting the JWT payload.
31+
When instantiated, call the method `check` to check the claims of a JWT object. This method only accept an associative array. You have to retrieve this array by converting the JWT payload.
3232

3333
```php
34-
use Jose\Component\Core\Converter\StandardConverter;
35-
36-
$jsonConverter = new StandardConverter();
37-
38-
$claims = $jsonConverter->decode($jwt->getPayload());
34+
$claims = json_decode($jwt->getPayload(), true);
3935
$claimCheckerManager->check($claims);
4036
```
4137

components/encrypted-tokens-jwe/encryption-algorithms.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ use Jose\Component\Encryption\Algorithm\KeyEncryption\A128KW;
7474
use Jose\Component\Encryption\Algorithm\KeyEncryption\PBES2HS256A128KW;
7575
use Jose\Component\Encryption\Algorithm\ContentEncryption\A128CBCHS256;
7676

77-
$algorithmManager = AlgorithmManager::create([
77+
$algorithmManager = new AlgorithmManager([
7878
new A128KW(),
7979
new PBES2HS256A128KW(),
8080
new A128CBCHS256(),
@@ -96,7 +96,7 @@ Example with 16 bytes \(128 bits\) salt and 1024 counts:
9696
use Jose\Component\Core\AlgorithmManager;
9797
use Jose\Component\Encryption\Algorithm\KeyEncryption\PBES2HS256A128KW;
9898

99-
$algorithmManager = AlgorithmManager::create([
99+
$algorithmManager = new AlgorithmManager([
100100
new PBES2HS256A128KW(16, 1024),
101101
]);
102102
```

components/encrypted-tokens-jwe/jwe-creation.md

+8-14
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,35 @@ The computation of a JWE is done by the `JWEBuilder` object. This object require
44

55
* an algorithm manager with key encryption algorithms
66
* an algorithm manager with content encryption algorithms
7-
* a compression method manager. No compression method is needed if you do not intent to compress the payload
8-
* and a JSON converter.
7+
* a compression method manager. No compression method is needed if you do not intent to compress the payload.
98

109
```php
1110
<?php
1211

1312
use Jose\Component\Core\AlgorithmManager;
14-
use Jose\Component\Core\Converter\StandardConverter;
1513
use Jose\Component\Encryption\Algorithm\KeyEncryption\A256KW;
1614
use Jose\Component\Encryption\Algorithm\ContentEncryption\A256CBCHS512;
1715
use Jose\Component\Encryption\Compression\CompressionMethodManager;
1816
use Jose\Component\Encryption\Compression\Deflate;
1917
use Jose\Component\Encryption\JWEBuilder;
2018

2119
// The key encryption algorithm manager with the A256KW algorithm.
22-
$keyEncryptionAlgorithmManager = AlgorithmManager::create([
20+
$keyEncryptionAlgorithmManager = new AlgorithmManager([
2321
new A256KW(),
2422
]);
2523

2624
// The content encryption algorithm manager with the A256CBC-HS256 algorithm.
27-
$contentEncryptionAlgorithmManager = AlgorithmManager::create([
25+
$contentEncryptionAlgorithmManager = new AlgorithmManager([
2826
new A256CBCHS512(),
2927
]);
3028

3129
// The compression method manager with the DEF (Deflate) method.
32-
$compressionMethodManager = CompressionMethodManager::create([
30+
$compressionMethodManager = new CompressionMethodManager([
3331
new Deflate(),
3432
]);
3533

36-
// The JSON Converter.
37-
$jsonConverter = new StandardConverter();
38-
3934
// We instantiate our JWE Builder.
4035
$jweBuilder = new JWEBuilder(
41-
$jsonConverter,
4236
$keyEncryptionAlgorithmManager,
4337
$contentEncryptionAlgorithmManager,
4438
$compressionMethodManager
@@ -51,13 +45,13 @@ Now let's create our first JWE object.
5145
use Jose\Component\Core\JWK;
5246

5347
// Our key.
54-
$jwk = JWK::create([
48+
$jwk = new JWK([
5549
'kty' => 'oct',
5650
'k' => 'dzI6nbW4OcNF-AtfxGAmuyz7IpHRudBI0WgGjZWgaRJt6prBn3DARXgUR8NVwKhfL43QBIU2Un3AvCGCHRgY4TbEqhOi8-i98xxmCggNjde4oaW6wkJ2NgM3Ss9SOX9zS3lcVzdCMdum-RwVJ301kbin4UtGztuzJBeg5oVN00MGxjC2xWwyI0tgXVs-zJs5WlafCuGfX1HrVkIf5bvpE0MQCSjdJpSeVao6-RSTYDajZf7T88a2eVjeW31mMAg-jzAWfUrii61T_bYPJFOXW8kkRWoa1InLRdG6bKB9wQs9-VdXZP60Q4Yuj_WZ-lO7qV9AEFrUkkjpaDgZT86w2g',
5751
]);
5852

59-
// The payload we want to encrypt. The payload MUST be a string hence we use our JSON Converter.
60-
$payload = $jsonConverter->encode([
53+
// The payload we want to encrypt. It MUST be a string.
54+
$payload = json_encode([
6155
'iat' => time(),
6256
'nbf' => time(),
6357
'exp' => time() + 3600,
@@ -84,7 +78,7 @@ We will use the compact serialization mode. This is the most common mode as it i
8478
```php
8579
use Jose\Component\Encryption\Serializer\CompactSerializer;
8680

87-
$serializer = new CompactSerializer($jsonConverter); // The serializer
81+
$serializer = new CompactSerializer(); // The serializer
8882

8983
$token = $serializer->serialize($jwe, 0); // We serialize the recipient at index 0 (we only have one recipient).
9084
```

components/encrypted-tokens-jwe/jwe-loading.md

+5-9
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ use Jose\Component\Encryption\Compression\Deflate;
1919
use Jose\Component\Encryption\JWEDecrypter;
2020

2121
// The key encryption algorithm manager with the A256KW algorithm.
22-
$keyEncryptionAlgorithmManager = AlgorithmManager::create([
22+
$keyEncryptionAlgorithmManager = new AlgorithmManager([
2323
new A256KW(),
2424
]);
2525

2626
// The content encryption algorithm manager with the A256CBC-HS256 algorithm.
27-
$contentEncryptionAlgorithmManager = AlgorithmManager::create([
27+
$contentEncryptionAlgorithmManager = new AlgorithmManager([
2828
new A256CBCHS512(),
2929
]);
3030

3131
// The compression method manager with the DEF (Deflate) method.
32-
$compressionMethodManager = CompressionMethodManager::create([
32+
$compressionMethodManager = new CompressionMethodManager([
3333
new Deflate(),
3434
]);
3535

@@ -48,7 +48,6 @@ Now we can try to deserialize and decrypt the input we receive. We will continue
4848
```php
4949
<?php
5050

51-
use Jose\Component\Core\Converter\StandardConverter;
5251
use Jose\Component\Core\JWK;
5352
use Jose\Component\Encryption\Serializer\JWESerializerManager;
5453
use Jose\Component\Encryption\Serializer\CompactSerializer;
@@ -59,12 +58,9 @@ $jwk = JWK::create([
5958
'k' => 'dzI6nbW4OcNF-AtfxGAmuyz7IpHRudBI0WgGjZWgaRJt6prBn3DARXgUR8NVwKhfL43QBIU2Un3AvCGCHRgY4TbEqhOi8-i98xxmCggNjde4oaW6wkJ2NgM3Ss9SOX9zS3lcVzdCMdum-RwVJ301kbin4UtGztuzJBeg5oVN00MGxjC2xWwyI0tgXVs-zJs5WlafCuGfX1HrVkIf5bvpE0MQCSjdJpSeVao6-RSTYDajZf7T88a2eVjeW31mMAg-jzAWfUrii61T_bYPJFOXW8kkRWoa1InLRdG6bKB9wQs9-VdXZP60Q4Yuj_WZ-lO7qV9AEFrUkkjpaDgZT86w2g',
6059
]);
6160

62-
// The JSON Converter.
63-
$jsonConverter = new StandardConverter();
64-
6561
// The serializer manager. We only use the JWE Compact Serialization Mode.
66-
$serializerManager = JWESerializerManager::create([
67-
new CompactSerializer($jsonConverter),
62+
$serializerManager = new JWESerializerManager([
63+
new CompactSerializer(),
6864
]);
6965

7066
// The input we want to decrypt

components/header-checker.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use Jose\Component\Checker\HeaderCheckerManager;
2828
use Jose\Component\Checker\AlgorithmChecker;
2929
use Jose\Component\Signature\JWSTokenSupport;
3030

31-
$headerCheckerManager = HeaderCheckerManager::create(
31+
$headerCheckerManager = new HeaderCheckerManager(
3232
[
3333
new AlgorithmChecker(['HS256']), // We check the header "alg" (algorithm)
3434
],
@@ -87,6 +87,8 @@ The following header checkers are provided:
8787

8888
If you need, you can create you own header checker. It must implement the interface `Jose\Component\Checker\HeaderChecker`. In the following example, we will check that the protected header parameter `custom` is an array with value `foo` or `bar`.
8989

90+
{% code-tabs %}
91+
{% code-tabs-item title="Acme\\Checker\\CustomChecker.php" %}
9092
```php
9193
<?php
9294

@@ -95,9 +97,6 @@ namespace Acme\Checker;
9597
use Jose\Component\Checker\HeaderChecker;
9698
use Jose\Component\Checker\InvalidHeaderException;
9799

98-
/**
99-
* Class CustomChecker.
100-
*/
101100
final class CustomChecker implements HeaderChecker
102101
{
103102
public function checkHeader($value)
@@ -120,4 +119,6 @@ final class CustomChecker implements HeaderChecker
120119
}
121120
}
122121
```
122+
{% endcode-tabs-item %}
123+
{% endcode-tabs %}
123124

0 commit comments

Comments
 (0)