Commit 7fbbeac
committed
feat: add pluggable resource validator for resource servers
This validates the token audience (if there is one) against the request
URI.
Specs are unclear on *exactly* how this validation should be done.
Most implementations seem to require an *exact* match between the token
`aud` and the resource server identifier (Auth0, Okta, AWS Cognito)
This is a pain because it requires some extra configuration on the
resource server to define what exactly is 'the resource server identifier'
- is it the host name, a hardcoded identifier or some subresource path?
I have opted for a pluggable system so the project can define what
approach to use, but I've chosen a default approach which I hope is
more flexible and requires no configuration - we match the token
audience claim to the request using a url prefix.
i.e. when requesting `https://example.com/users/foo`, a token with
`aud: ["https://example.com/users"]` would match.
This approach is implemented by Ory Hydra:
https://www.ory.com/docs/hydra/guides/audiences#audience-in-authorization-code-implicit-and-hybrid-flows
I also found a ticket requesting this feature for Ory Oathkeeper:
ory/oathkeeper#656
Changes:
- Add `validate_resource_as_url_prefix()` with URL prefix matching logic
- New setting: `RESOURCE_SERVER_TOKEN_RESOURCE_VALIDATOR` (pluggable)
- Use the validator function in `validate_bearer_token()` when the token
has an audience claim1 parent d9faac2 commit 7fbbeac
File tree
6 files changed
+334
-35
lines changed- docs
- oauth2_provider
- tests
6 files changed
+334
-35
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
105 | 111 | | |
106 | 112 | | |
107 | 113 | | |
108 | | - | |
| 114 | + | |
| 115 | + | |
109 | 116 | | |
110 | | - | |
111 | | - | |
112 | | - | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
113 | 121 | | |
114 | | - | |
115 | | - | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
116 | 125 | | |
117 | | - | |
118 | | - | |
119 | | - | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
120 | 129 | | |
121 | | - | |
122 | | - | |
123 | | - | |
| 130 | + | |
124 | 131 | | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
125 | 137 | | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | 138 | | |
132 | | - | |
133 | | - | |
134 | | - | |
| 139 | + | |
| 140 | + | |
135 | 141 | | |
136 | | - | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
137 | 146 | | |
138 | | - | |
139 | | - | |
140 | | - | |
| 147 | + | |
141 | 148 | | |
142 | | - | |
143 | | - | |
144 | | - | |
| 149 | + | |
145 | 150 | | |
146 | | - | |
147 | | - | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
288 | 288 | | |
289 | 289 | | |
290 | 290 | | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
291 | 318 | | |
292 | 319 | | |
293 | 320 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
477 | 477 | | |
478 | 478 | | |
479 | 479 | | |
480 | | - | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
481 | 483 | | |
482 | 484 | | |
483 | 485 | | |
484 | 486 | | |
485 | 487 | | |
486 | 488 | | |
| 489 | + | |
| 490 | + | |
487 | 491 | | |
| 492 | + | |
488 | 493 | | |
489 | | - | |
490 | | - | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
491 | 498 | | |
492 | 499 | | |
493 | | - | |
494 | | - | |
495 | 500 | | |
496 | 501 | | |
497 | 502 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
44 | 81 | | |
45 | 82 | | |
46 | 83 | | |
| |||
481 | 518 | | |
482 | 519 | | |
483 | 520 | | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
484 | 529 | | |
485 | 530 | | |
486 | 531 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
117 | 121 | | |
118 | 122 | | |
119 | 123 | | |
| |||
154 | 158 | | |
155 | 159 | | |
156 | 160 | | |
| 161 | + | |
157 | 162 | | |
158 | 163 | | |
159 | 164 | | |
| |||
0 commit comments