Skip to content

Commit 21d0805

Browse files
committed
Reintroduce custom fetch to buildAuthenticatedFetch as an option
Fixes #3810
1 parent ee89bc9 commit 21d0805

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

packages/core/src/authenticatedFetch/fetchFactory.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,9 @@ async function makeAuthenticatedRequest(
9595
url: RequestInfo | URL,
9696
defaultRequestInit?: RequestInit,
9797
dpopKey?: KeyPair,
98+
unauthFetch = fetch,
9899
) {
99-
return fetch(
100+
return unauthFetch(
100101
url,
101102
await buildAuthenticatedHeaders(
102103
url.toString(),
@@ -147,6 +148,7 @@ const computeRefreshDelay = (expiresIn?: number): number => {
147148
* @param accessToken an access token, either a Bearer token or a DPoP one.
148149
* @param options The option object may contain two objects: the DPoP key token
149150
* is bound to if applicable, and options to customize token renewal behavior.
151+
* @param {typeof fetch} [options.fetch=fetch] A custom fetch function (defaults to the global fetch).
150152
*
151153
* @returns A fetch function that adds an appropriate Authorization header with
152154
* the provided token, and adds a DPoP header if applicable.
@@ -158,6 +160,7 @@ export function buildAuthenticatedFetch(
158160
refreshOptions?: RefreshOptions;
159161
expiresIn?: number;
160162
eventEmitter?: EventEmitter;
163+
fetch?: typeof fetch; // optional custom fetch
161164
},
162165
): typeof fetch {
163166
let currentAccessToken = accessToken;
@@ -258,6 +261,7 @@ export function buildAuthenticatedFetch(
258261
url,
259262
requestInit,
260263
options?.dpopKey,
264+
options?.fetch,
261265
);
262266

263267
const failedButNotExpectedAuthError =
@@ -280,6 +284,7 @@ export function buildAuthenticatedFetch(
280284
response.url,
281285
requestInit,
282286
options.dpopKey,
287+
options.fetch,
283288
);
284289
}
285290
return response;

0 commit comments

Comments
 (0)