Dex TypeScript SDK 1.29.0
    Preparing search index...

    Class ApiKeyCredential

    Exchanges an API key for short-lived Dex bearer tokens.

    Use this instead of FileCredential when the application holds an API key rather than a rotating token file. The first call exchanges the key. Calls after 80% of the token's lifetime start one shared background refresh and continue using the valid token. Failed refreshes are retried no more often than every five seconds while that token remains valid. Expired-token callers await the same exchange, bounded by the exchange timeout. A rejected token is discarded. Unary calls retry once, and pull streams reconnect immediately once before using the Worker's backoff.

    The token URL must use HTTPS, except loopback HTTP is accepted for local endpoints. Token endpoint redirects are never followed. Credential inspection contains no secrets. Exchange errors redact the API key, cached and two most recently issued access tokens, the failed response's access token, and JWT-shaped substrings before truncating each endpoint error field to 200 characters. A JWT-shaped substring has three or more base64url segments of at least 10 characters each. The rule also applies to the token URL and can redact other text of that shape, such as a long dotted host name. Raw transport causes are omitted. Concurrent calls are safe. The credential owns no persistent HTTP client or timer; an in-flight exchange ends within the configured timeout. An injected fetch is owned by the application. The application owns this credential when sharing it among Clients and Workers; closing either does not close the credential.

    const credential = new ApiKeyCredential({
    tokenUrl: "https://auth.example.com/token",
    serverId: "dex-server-id",
    apiKey: process.env.DEX_API_KEY!,
    });
    const client = new Client(registry, cache, { credential });
    const worker = new Worker(registry, cache, { credential, pull: {} });
    try { await worker.start(); await client.searchFlows("", 10); }
    finally { await client.close(); await worker.close(); }

    Implements

    Index

    Constructors

    Methods

    Constructors

    Methods

    • Hides API key and access token values from Node inspection.

      Returns string

      A redacted credential description.

    • Hides API key and access token values from JSON serialization.

      Returns object

      An empty object without credential secrets.

    • Returns a valid access token, exchanging the API key when needed. Concurrent callers share one exchange. A valid token is returned immediately during refresh. When no valid token exists, this waits up to the exchange timeout.

      Returns Promise<string>

      The current bearer access token.

      Error when the token endpoint rejects the request, returns invalid data, or cannot be reached in time.