File tree 1 file changed +6
-1
lines changed
packages/core/src/authenticatedFetch 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -95,8 +95,9 @@ async function makeAuthenticatedRequest(
95
95
url : RequestInfo | URL ,
96
96
defaultRequestInit ?: RequestInit ,
97
97
dpopKey ?: KeyPair ,
98
+ unauthFetch = fetch ,
98
99
) {
99
- return fetch (
100
+ return unauthFetch (
100
101
url ,
101
102
await buildAuthenticatedHeaders (
102
103
url . toString ( ) ,
@@ -147,6 +148,7 @@ const computeRefreshDelay = (expiresIn?: number): number => {
147
148
* @param accessToken an access token, either a Bearer token or a DPoP one.
148
149
* @param options The option object may contain two objects: the DPoP key token
149
150
* 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).
150
152
*
151
153
* @returns A fetch function that adds an appropriate Authorization header with
152
154
* the provided token, and adds a DPoP header if applicable.
@@ -158,6 +160,7 @@ export function buildAuthenticatedFetch(
158
160
refreshOptions ?: RefreshOptions ;
159
161
expiresIn ?: number ;
160
162
eventEmitter ?: EventEmitter ;
163
+ fetch ?: typeof fetch ; // optional custom fetch
161
164
} ,
162
165
) : typeof fetch {
163
166
let currentAccessToken = accessToken ;
@@ -258,6 +261,7 @@ export function buildAuthenticatedFetch(
258
261
url ,
259
262
requestInit ,
260
263
options ?. dpopKey ,
264
+ options ?. fetch ,
261
265
) ;
262
266
263
267
const failedButNotExpectedAuthError =
@@ -280,6 +284,7 @@ export function buildAuthenticatedFetch(
280
284
response . url ,
281
285
requestInit ,
282
286
options . dpopKey ,
287
+ options . fetch ,
283
288
) ;
284
289
}
285
290
return response ;
You can’t perform that action at this time.
0 commit comments