Skip to content

Commit e201d3a

Browse files
committed
refactor: workaround dpop nonce caching caveats with customFetch
1 parent fa7414e commit e201d3a

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

docs/variables/customFetch.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ Known caveats:
3131

3232
- Expect Type-related issues when passing the inputs through to fetch-like modules, they hardly
3333
ever get their typings inline with actual fetch, you should `@ts-expect-error` them.
34-
- Returning self-constructed [Response](https://developer.mozilla.org/docs/Web/API/Response) instances prohibits AS/RS-signalled DPoP Nonce
35-
caching.
3634

3735
## Examples
3836

src/index.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,6 @@ export const clockTolerance: unique symbol = Symbol()
215215
*
216216
* - Expect Type-related issues when passing the inputs through to fetch-like modules, they hardly
217217
* ever get their typings inline with actual fetch, you should `@ts-expect-error` them.
218-
* - Returning self-constructed {@link !Response} instances prohibits AS/RS-signalled DPoP Nonce
219-
* caching.
220218
*
221219
* @example
222220
*
@@ -2212,7 +2210,7 @@ export async function pushedAuthorizationRequest(
22122210
headers,
22132211
options,
22142212
)
2215-
options?.DPoP?.cacheNonce(response)
2213+
options?.DPoP?.cacheNonce(response, url)
22162214
return response
22172215
}
22182216

@@ -2239,7 +2237,7 @@ export interface DPoPHandle {
22392237
*
22402238
* @internal
22412239
*/
2242-
cacheNonce(response: Response): void
2240+
cacheNonce(response: Response, url: URL): void
22432241
/**
22442242
* Calculates the JWK Thumbprint of the DPoP public key using the SHA-256 hash function for use as
22452243
* the optional `dpop_jkt` authorization request parameter.
@@ -2332,11 +2330,11 @@ class DPoPHandler implements DPoPHandle {
23322330
headers.set('dpop', await signJwt(this.#header, payload, this.#privateKey))
23332331
}
23342332

2335-
cacheNonce(response: Response): void {
2333+
cacheNonce(response: Response, url: URL): void {
23362334
try {
23372335
const nonce = response.headers.get('dpop-nonce')
23382336
if (nonce) {
2339-
this.#set(new URL(response.url).origin, nonce)
2337+
this.#set(url.origin, nonce)
23402338
}
23412339
} catch {}
23422340
}
@@ -2871,7 +2869,7 @@ async function resourceRequest(
28712869
redirect: 'manual',
28722870
signal: signal(url, options?.signal),
28732871
})
2874-
options?.DPoP?.cacheNonce(response)
2872+
options?.DPoP?.cacheNonce(response, url)
28752873
return response
28762874
}
28772875

@@ -3404,7 +3402,7 @@ async function tokenEndpointRequest(
34043402
headers,
34053403
options,
34063404
)
3407-
options?.DPoP?.cacheNonce(response)
3405+
options?.DPoP?.cacheNonce(response, url)
34083406
return response
34093407
}
34103408

@@ -6485,7 +6483,7 @@ export async function dynamicClientRegistrationRequest(
64856483
redirect: 'manual',
64866484
signal: signal(url, options?.signal),
64876485
})
6488-
options?.DPoP?.cacheNonce(response)
6486+
options?.DPoP?.cacheNonce(response, url)
64896487
return response
64906488
}
64916489

0 commit comments

Comments
 (0)