createRemoteTokenIssuer and any other component that needs to authenticate with an external service.
All strategies implement the AuthHeaderProvider type:
noAuth) or contain one or more headers such as Authorization.
Strategy Comparison
noAuth
Returns empty headers. Use for local development, trusted networks, or public endpoints that do not require authentication.sharedSecretAuth
Returns a static header with a secret value. Use when both services share a pre-configured API key or internal secret.signedJwtAuth
Signs a short-lived JWT using the SDK’sAccessTokenIssuer. Use when the backend validates JWTs signed by your Key0 instance (particularly useful with RS256 key pairs).
The generated JWT includes the following claims:
oauthClientCredentialsAuth
Fetches an access token from an OAuth 2.0 provider using the Client Credentials grant. Caches the token in memory and automatically re-fetches when it expires (with a 10-second buffer).
Behavior details:
- Sends a
POSTrequest withContent-Type: application/x-www-form-urlencoded. - Expects a JSON response with
access_token(string) andexpires_in(number, seconds). - Caches the token and re-fetches 10 seconds before expiry.
- 10-second request timeout via
AbortController. - Throws
Key0Errorwith codeINTERNAL_ERRORand HTTP 500 if the token request fails.
createRemoteTokenIssuer
Creates afetchResourceCredentials callback that delegates token issuance to a remote HTTP endpoint. Use this when your backend (not Key0) is responsible for issuing API keys or custom tokens after payment.
RemoteTokenIssuerConfig
Request format: The callback sends a
POST with Content-Type: application/json and the IssueTokenParams as the body.
Expected response: A JSON object with token (string, required) and optionally tokenType (string, defaults to "Bearer").
Error handling:
Related
Standalone Service Example
Deploy Key0 as a standalone service using auth helpers for backend calls.
Backend Integration Example
Wire up remote token issuance with your existing backend.
Factory
createKey0() — the top-level factory that accepts auth-related config.

