Commit 8b9ed36
committed
feature symfony#54932 [Security][SecurityBundle] OIDC discovery (vincentchalamon)
This PR was merged into the 7.3 branch.
Discussion
----------
[Security][SecurityBundle] OIDC discovery
This PR introduces [OIDC discovery](https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfigurationResponse) on `oidc` and `oidc_user_info` token handlers.
| Q | A
| ------------- | ---
| Branch? | 7.2
| Bug fix? | no
| New feature? | yes
| Deprecations? | yes
| Issues | Fix symfony#50433 Fix symfony#50434
| License | MIT
| Doc PR | symfony/symfony-docs#20579 |
### TODO
- [x] use JWSLoader in OidcTokenHandler
- [x] introduce OidcUserInfoDiscoveryTokenHandler
- [x] introduce OidcDiscoveryTokenHandler
- [x] update src/**/CHANGELOG.md files
- [x] update UPGRADE-*.md files
- [x] add tests on AccessTokenFactoryTest with discovery
- [x] create documentation PR
### What is OIDC Discovery?
[OIDC discovery](https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfigurationResponse) is a generic endpoint on the OIDC server, which gives any public information such as signature public keys and endpoints URIs (userinfo, token, etc.). An example is available on the API Platform Demo:
https://demo.api-platform.com/oidc/realms/demo/.well-known/openid-configuration.
Using the OIDC discovery simplifies the `oidc` security configuration, allowing to just configure the discovery and let Symfony store the configuration and the keyset in cache. For instance, if the _userinfo_endpoint_ or _signature keyset_ change on the OIDC server, no need to update the environment variables in the Symfony application, just clear the corresponding cache and it'll retrieve the configuration and the keyset accordingly on the next request.
In the `oidc_user_info` security configuration, it does the same logic but only about _userinfo_endpoint_ as this token handler doesn't need the _keyset_.
### How Do I Use This New Feature in Symfony?
The current `oidc` token handler configuration requires a `keyset` option which may change on the OIDC server. It is configured as following:
```yaml
# config/packages/security.yaml
security:
firewalls:
main:
access_token:
oidc:
claim: 'email'
audience: 'symfony'
issuers: ['https://example.com/']
algorithms: ['RS256']
keyset: '{"keys":[{"kty":"EC",...}]}'
```
> Note: those parameters should be configured with environment variables.
With the `discovery` option, Symfony will retrieve the `keyset` directly from the OIDC discovery URI and store it in a cache:
```yaml
# config/packages/security.yaml
security:
firewalls:
main:
access_token:
oidc:
# 'keyset' option is not necessary anymore as it's retrieved from OIDC discovery and stored in cache
claim: 'email'
audience: 'symfony'
issuers: ['https://example.com/']
algorithms: ['RS256']
discovery:
base_uri: 'https://example.com/oidc/realms/master/'
cache:
id: cache.app # require to create this cache in framework.yaml
```
> Note: some other parameters might be retrieven from the OIDC discovery, maybe 'algorithm' or 'issuers'. To discuss.
The current `oidc_user_info` token handler required a `base_uri` corresponding to the _userinfo_endpoint_ URI on the OIDC server. This URI may change if it's changed on the OIDC server. Introducing the discovery helps to configure it dynamically.
The current configuration looks like the following:
```yaml
# config/packages/security.yaml
security:
firewalls:
main:
access_token:
oidc_user_info:
# 'base_uri' is the userinfo_endpoint URI
base_uri: 'https://example.com/oidc/realms/master/protocol/openid-connect/userinfo'
claim: 'email'
```
With the `discovery`, it will look like this:
```yaml
# config/packages/security.yaml
security:
firewalls:
main:
access_token:
oidc_user_info:
# 'base_uri' can be the userinfo_endpoint for backward compatibility
# and can be the OIDC server url in addition of 'discovery' option
base_uri: 'https://example.com/oidc/realms/master/'
claim: 'email'
discovery:
cache:
id: cache.app # require to create this cache in framework.yaml
```
Commits
-------
93f369a feat(security): OIDC discoveryFile tree
10 files changed
+271
-14
lines changed- src/Symfony
- Bundle/SecurityBundle
- DependencyInjection/Security/AccessToken
- Resources/config
- Tests
- DependencyInjection/Security/Factory
- Functional/app/AccessToken
- Component/Security/Http
- AccessToken/Oidc
10 files changed
+271
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| 63 | + | |
| 64 | + | |
63 | 65 | | |
64 | 66 | | |
65 | 67 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
Lines changed: 45 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| |||
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
41 | 64 | | |
42 | | - | |
43 | | - | |
| 65 | + | |
44 | 66 | | |
45 | 67 | | |
46 | 68 | | |
| |||
74 | 96 | | |
75 | 97 | | |
76 | 98 | | |
77 | | - | |
78 | | - | |
| 99 | + | |
| 100 | + | |
79 | 101 | | |
80 | 102 | | |
81 | 103 | | |
| |||
101 | 123 | | |
102 | 124 | | |
103 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
104 | 145 | | |
105 | 146 | | |
106 | 147 | | |
| |||
129 | 170 | | |
130 | 171 | | |
131 | 172 | | |
132 | | - | |
133 | 173 | | |
134 | 174 | | |
135 | 175 | | |
| |||
Lines changed: 31 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
37 | | - | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
40 | 55 | | |
41 | 56 | | |
42 | 57 | | |
| |||
55 | 70 | | |
56 | 71 | | |
57 | 72 | | |
58 | | - | |
| 73 | + | |
59 | 74 | | |
60 | 75 | | |
61 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
62 | 91 | | |
63 | 92 | | |
64 | 93 | | |
| |||
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
95 | 100 | | |
96 | 101 | | |
97 | 102 | | |
| |||
Lines changed: 95 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
117 | | - | |
| 117 | + | |
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
| |||
340 | 340 | | |
341 | 341 | | |
342 | 342 | | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
343 | 395 | | |
344 | 396 | | |
345 | 397 | | |
| |||
407 | 459 | | |
408 | 460 | | |
409 | 461 | | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
410 | 504 | | |
411 | 505 | | |
412 | 506 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| |||
0 commit comments