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 extends MyProviderBase implements OAuthClientProvider {
prepareTokenRequest(scope?: string) {
const params = new URLSearchParams({ grant_type: 'client_credentials' });
if (scope) params.set('scope', scope);
return params;
}
}
const tokens = await fetchToken(new MyProvider(), authServerUrl, { metadata });
Unified token fetching that works with any grant type via
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.