OAuth client provider that implements prepareTokenRequest()
The authorization server's base URL
Configuration for the token request
OptionalauthorizationCode?: stringAuthorization code for the default authorization_code grant flow
OptionalfetchFn?: FetchLikeOptionalmetadata?: AuthorizationServerMetadataOptionalresource?: URLPromise resolving to OAuth tokens
// Provider for client_credentials:
class MyProvider implements OAuthClientProvider {
prepareTokenRequest(scope) {
const params = new URLSearchParams({ grant_type: 'client_credentials' });
if (scope) params.set('scope', scope);
return params;
}
// ... other methods
}
const tokens = await fetchToken(provider, authServerUrl, { metadata });
Unified token fetching that works with any grant type via provider.prepareTokenRequest().
This function provides a single entry point for obtaining tokens regardless of the OAuth grant type. The provider's prepareTokenRequest() method determines which grant to use and supplies the grant-specific parameters.