Commit f7b7170
committed
refactor(server): migrate password and token-exchange to the Grant abstraction
Turn the token endpoint into a fixed pipeline of shared control points so a grant
cannot skip a security-sensitive step. Dispatch always runs, in order:
1. authenticate the client
2. validate the requested scopes (cross-client trust included)
3. resolve the connector and enforce the connector-authorization invariant
4. Authorize — the grant proves the identity against the resolved connector
5. mint the token response
6. write the response or error
A Grant only fills the parts unique to it — a scope policy, its connector id, and
Authorize — while the Endpoint owns every shared phase. The cross-client trust
check and the connector-authorization invariant (client allows the connector,
connector allows the grant type) now run in the pipeline, not inside each grant
where one could be forgotten: a grant supplies its connector id and the endpoint
resolves and checks it. A grant that uses no connector, like client_credentials,
returns an empty id and the step is skipped.
Token minting is unified: tokens.Issuer.Issue is the single mint every standard
grant uses, now issuing an ID token exactly when the openid scope was requested,
which also covers client_credentials. A grant whose response is non-standard
implements Minter; token-exchange uses it to mint the single RFC 8693 token, the
only response shape the standard mint does not produce.
A grant never touches the ResponseWriter: it returns a tokens.Response or an
*oauth2.Error, and the Endpoint writes it.
checkConnectorAllowed stays in the server package for the refresh grant, which has
not moved yet.
Signed-off-by: maksim.nabokikh <max.nabokih@gmail.com>1 parent f225b47 commit f7b7170
13 files changed
Lines changed: 591 additions & 478 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
13 | 13 | | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
19 | 20 | | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
| 21 | + | |
| 22 | + | |
24 | 23 | | |
25 | 24 | | |
26 | 25 | | |
| |||
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | 15 | | |
17 | 16 | | |
18 | 17 | | |
| |||
108 | 107 | | |
109 | 108 | | |
110 | 109 | | |
111 | | - | |
| 110 | + | |
112 | 111 | | |
113 | 112 | | |
114 | 113 | | |
| |||
148 | 147 | | |
149 | 148 | | |
150 | 149 | | |
151 | | - | |
| 150 | + | |
152 | 151 | | |
153 | 152 | | |
154 | 153 | | |
| |||
205 | 204 | | |
206 | 205 | | |
207 | 206 | | |
208 | | - | |
| 207 | + | |
209 | 208 | | |
210 | 209 | | |
211 | 210 | | |
| |||
264 | 263 | | |
265 | 264 | | |
266 | 265 | | |
267 | | - | |
| 266 | + | |
268 | 267 | | |
269 | 268 | | |
270 | 269 | | |
| |||
0 commit comments