Repository navigation
Commit 473f2bf
feat(sdk): the Rust SDK signs in clients that must push their requests (#240)
Closes #236
Auth lets a client require pushed authorization requests
(`--require-par`) and refuses that client's front-channel requests. The
Rust SDK never pushed, so an app using it couldn't sign in with such a
client. The SDK now pushes whenever discovery advertises the PAR
endpoint, as the TypeScript SDK does.
## How
- `Client::authorize` is now `async` and returns `Result<(Url,
PendingLogin), LoginError>`. With PAR advertised, it pushes the request,
authenticated as at the token endpoint (Basic for confidential clients,
`client_id` for public ones). It then returns
`/oauth/authorize?client_id=…&request_uri=…`. `PendingLogin` is
unchanged.
- `LoginError::Push(OAuthError)` reports a refused push, keeping its
OAuth `error`. `LoginError::Randomness` replaces the bare `rand::Error`.
- The axum `/login` route answers 502 when the push fails.
- Discovery also requires the PAR endpoint to use https, like every
other endpoint.
- Any 2xx status from auth counts as success, since PAR answers 201.
- `docs/architecture/sdk.md` states the rule: SDKs push whenever
discovery advertises the endpoint.
- **Decision for review:** `LoginError::Randomness` reports the shared
category `network`, since none covers a local failure. The alternative
is a new category in the shared error types.
## Since review
- **Exact statuses:** each endpoint must answer with its own success
status, 201 for the push and 200 for the others, matching the TypeScript
SDK.
- **`request_uri`:** an empty or whitespace one is refused
(`pushes_need_a_created_request_uri`).
- **Revocation:** its 200 body is ignored (RFC 7009 §2.2).
- **Tests:** the unit test checks that a pushed request carries
`acr_values` and `max_age`.
## Proof
- `authorize_pushes_when_advertised` and
`refused_pushes_keep_the_oauth_error` run against a mock PAR endpoint.
- `sdk_login_routes_push_for_clients_that_must` (database-backed) signs
a `require_pushed_authorization_requests` client in through the axum
routes against real auth.
- The step-up test now resumes through `/oauth/authorize/resume`,
because a `request_uri` works once.
- Clippy and rustdoc with warnings denied, nextest (27), doc tests (48)
and the full `just db test` (307) all pass.
Reviewed with review-loop: 5 rounds with 5× Claude Opus 5.5 on xhigh,
over the whole stack and #240. Verdict: approved
> [!NOTE]
> Written by Claude Opus 5.5 in Claude Code and reviewed by GPT 6.1 Sol
and Claude Opus 5.5 (via T3 Code)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->
## Rust SDK authorization flow
`Client::authorize` is now asynchronous and returns `Result<(Url,
PendingLogin), LoginError>`. It uses fallible OS randomness to create
the state, nonce, and PKCE verifier. `PendingLogin` is unchanged, so
these values remain server-side.
When issuer discovery advertises
`pushed_authorization_request_endpoint`, the SDK sends the authorization
request there using the client’s token-endpoint authentication. The
browser URL contains only `client_id` and the returned `request_uri`.
When discovery does not advertise PAR, the SDK retains the query-string
authorization flow.
`LoginError` adds `Randomness` and `Push` variants. A rejected push
retains its OAuth error. Randomness failures map to the shared `network`
category. Successful HTTP responses with any 2xx status are accepted by
the shared response reader.
## Axum login routes
The `/login` route awaits `Client::authorize`. It returns 500 when OS
randomness is unavailable and 502 when authorization fails, including a
failed push. The route documentation describes the possible push and the
502 response.
## Discovery validation
Issuer metadata validation now rejects a non-HTTPS pushed authorization
endpoint with `DiscoveryError::InsecureEndpoint`. The existing checks
remain unchanged when discovery does not advertise that endpoint.
## Tests and support
SDK tests cover pushing to an advertised endpoint, limiting the browser
URL to `client_id` and `request_uri`, preserving OAuth errors from
rejected pushes, and rejecting completion with a different client as
`ForeignLogin`. The auth-service integration tests cover login for
clients that require PAR. The step-up test resumes the claimed
authorization transaction through the provider’s resume endpoint.
Test support now shares metadata loading and local server setup helpers.
The auth-service step-up test also checks that the pushed request
carries the step-up requirement.
## Documentation
The SDK architecture guide documents the PAR behavior, client
authentication, redirect parameters, and error categories. The
`Client::authorize` documentation and examples reflect the asynchronous
API.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>1 parent d3d2e45 commit 473f2bf
8 files changed
Lines changed: 366 additions & 97 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1959 | 1959 | | |
1960 | 1960 | | |
1961 | 1961 | | |
| 1962 | + | |
1962 | 1963 | | |
1963 | 1964 | | |
1964 | 1965 | | |
| |||
2348 | 2349 | | |
2349 | 2350 | | |
2350 | 2351 | | |
| 2352 | + | |
| 2353 | + | |
| 2354 | + | |
| 2355 | + | |
| 2356 | + | |
| 2357 | + | |
| 2358 | + | |
| 2359 | + | |
| 2360 | + | |
| 2361 | + | |
| 2362 | + | |
| 2363 | + | |
| 2364 | + | |
| 2365 | + | |
| 2366 | + | |
| 2367 | + | |
| 2368 | + | |
| 2369 | + | |
2351 | 2370 | | |
2352 | 2371 | | |
2353 | 2372 | | |
| |||
2375 | 2394 | | |
2376 | 2395 | | |
2377 | 2396 | | |
| 2397 | + | |
| 2398 | + | |
2378 | 2399 | | |
2379 | | - | |
2380 | | - | |
2381 | | - | |
2382 | 2400 | | |
2383 | 2401 | | |
2384 | 2402 | | |
| |||
2403 | 2421 | | |
2404 | 2422 | | |
2405 | 2423 | | |
2406 | | - | |
| 2424 | + | |
| 2425 | + | |
| 2426 | + | |
| 2427 | + | |
| 2428 | + | |
| 2429 | + | |
| 2430 | + | |
| 2431 | + | |
| 2432 | + | |
| 2433 | + | |
| 2434 | + | |
| 2435 | + | |
| 2436 | + | |
| 2437 | + | |
2407 | 2438 | | |
2408 | 2439 | | |
2409 | 2440 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
| 10 | + | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
152 | | - | |
| 152 | + | |
| 153 | + | |
153 | 154 | | |
154 | 155 | | |
155 | 156 | | |
| |||
377 | 378 | | |
378 | 379 | | |
379 | 380 | | |
380 | | - | |
381 | | - | |
382 | | - | |
| 381 | + | |
383 | 382 | | |
384 | | - | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
385 | 400 | | |
386 | 401 | | |
387 | 402 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | 26 | | |
28 | 27 | | |
29 | 28 | | |
| |||
258 | 257 | | |
259 | 258 | | |
260 | 259 | | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
| 260 | + | |
266 | 261 | | |
267 | 262 | | |
268 | 263 | | |
| |||
272 | 267 | | |
273 | 268 | | |
274 | 269 | | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
| 270 | + | |
281 | 271 | | |
282 | 272 | | |
283 | 273 | | |
| |||
0 commit comments