@@ -417,10 +417,14 @@ const oauth4webapiRequestOptions = (
417417 targetUrl : string ,
418418 timeoutMs : number | undefined ,
419419 endpointUrlPolicy : OAuthEndpointUrlPolicy = { } ,
420+ customFetch ?: typeof globalThis . fetch ,
420421) : Record < string , unknown > => {
421422 const options : Record < string , unknown > = {
422423 signal : AbortSignal . timeout ( timeoutMs ?? OAUTH2_DEFAULT_TIMEOUT_MS ) ,
423424 } ;
425+ if ( customFetch ) {
426+ ( options as { [ oauth . customFetch ] ?: typeof globalThis . fetch } ) [ oauth . customFetch ] = customFetch ;
427+ }
424428 if (
425429 isLoopbackHttpUrl ( targetUrl ) ||
426430 ( URL . canParse ( targetUrl ) &&
@@ -510,6 +514,7 @@ export type ExchangeAuthorizationCodeInput = {
510514 readonly resource ?: string ;
511515 readonly timeoutMs ?: number ;
512516 readonly endpointUrlPolicy ?: OAuthEndpointUrlPolicy ;
517+ readonly fetch ?: typeof globalThis . fetch ;
513518} ;
514519
515520export const exchangeAuthorizationCode = (
@@ -545,7 +550,12 @@ export const exchangeAuthorizationCode = (
545550 clientAuth ,
546551 "authorization_code" ,
547552 params ,
548- oauth4webapiRequestOptions ( input . tokenUrl , input . timeoutMs , input . endpointUrlPolicy ) ,
553+ oauth4webapiRequestOptions (
554+ input . tokenUrl ,
555+ input . timeoutMs ,
556+ input . endpointUrlPolicy ,
557+ input . fetch ,
558+ ) ,
549559 ) ;
550560 return await processTokenEndpointResponse ( as , client , response ) ;
551561 } ,
@@ -568,6 +578,7 @@ export type ExchangeClientCredentialsInput = {
568578 readonly resource ?: string ;
569579 readonly timeoutMs ?: number ;
570580 readonly endpointUrlPolicy ?: OAuthEndpointUrlPolicy ;
581+ readonly fetch ?: typeof globalThis . fetch ;
571582} ;
572583
573584export const exchangeClientCredentials = (
@@ -593,7 +604,12 @@ export const exchangeClientCredentials = (
593604 client ,
594605 clientAuth ,
595606 params ,
596- oauth4webapiRequestOptions ( input . tokenUrl , input . timeoutMs , input . endpointUrlPolicy ) ,
607+ oauth4webapiRequestOptions (
608+ input . tokenUrl ,
609+ input . timeoutMs ,
610+ input . endpointUrlPolicy ,
611+ input . fetch ,
612+ ) ,
597613 ) ;
598614 const result = await oauth . processClientCredentialsResponse ( as , client , response ) ;
599615 return tokenResponseFrom ( result ) ;
@@ -621,6 +637,7 @@ export type RefreshAccessTokenInput = {
621637 readonly resource ?: string ;
622638 readonly timeoutMs ?: number ;
623639 readonly endpointUrlPolicy ?: OAuthEndpointUrlPolicy ;
640+ readonly fetch ?: typeof globalThis . fetch ;
624641} ;
625642
626643export const refreshAccessToken = (
@@ -652,7 +669,12 @@ export const refreshAccessToken = (
652669 clientAuth ,
653670 input . refreshToken ,
654671 {
655- ...oauth4webapiRequestOptions ( input . tokenUrl , input . timeoutMs , input . endpointUrlPolicy ) ,
672+ ...oauth4webapiRequestOptions (
673+ input . tokenUrl ,
674+ input . timeoutMs ,
675+ input . endpointUrlPolicy ,
676+ input . fetch ,
677+ ) ,
656678 additionalParameters,
657679 } ,
658680 ) ;
0 commit comments