(handler: H)
| 16 | * @see https://datatracker.ietf.org/doc/html/rfc9700#section-4.12 |
| 17 | */ |
| 18 | export function oauthApiHandler<H extends AnyHandler>(handler: H): H { |
| 19 | const wrapped = apiHandler(async (...args: Parameters<H>) => { |
| 20 | const response = await handler(...args); |
| 21 | if (response.status === 307 || response.status === 308) { |
| 22 | throw new Error( |
| 23 | `OAuth authorization server emitted HTTP ${response.status} redirect; ` + |
| 24 | `per RFC 9700 §4.12 the authorization server MUST NOT use 307/308. ` + |
| 25 | `Use 303 (See Other) instead.` |
| 26 | ); |
| 27 | } |
| 28 | return response; |
| 29 | }); |
| 30 | |
| 31 | return wrapped as H; |
| 32 | } |
no test coverage detected