Repository navigation
feat: apiKeyProvider covers the HTTP APIs (process, queue, files, tokens) - #226
Merged
Merged
Conversation
…ens)
`createDecartClient({ apiKeyProvider })` now resolves the credential for every
HTTP request too, not only for realtime connects and reconnects. The provider
is called right before each request (including every `submitAndPoll` status
poll and the result download) and wins over `apiKey`. Its result goes through
the same checks as a realtime dial's (`INVALID_API_KEY` for an empty or
non-string result, `TOKEN_EXPIRED` for an already expired client token).
Without a provider nothing changes; proxy mode sends no key and never calls it.
Docs note that the API checks the token once the request body has fully
arrived, so uploads need a token minted with an `expiresIn` that covers them.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Apps that authenticate with short-lived client tokens can now use one client for everything:
apiKeyProvidersupplies the credential for every HTTP request (process,queue,files,tokens), not just realtime connects and reconnects. Until now the HTTP APIs ignored it, so a browser app had to mint a token and build a new client before every batch call. The provider is called right before each request, including everysubmitAndPollstatus poll and the result download, and wins overapiKey; without a provider nothing changes, and proxy mode never calls it. Because the API checks the token once the request body has fully arrived, the docs now say to mint upload tokens with anexpiresInthat covers the upload.Usage
Note
Medium Risk
Auth behavior changes for apps using apiKeyProvider with batch/HTTP APIs (more provider calls, different keys per poll); proxy and static apiKey paths are unchanged.
Overview
apiKeyProvidernow supplies credentials for all direct HTTP APIs, not only realtime connect/reconnect.createDecartClientbuilds a sharedgetApiKeyfromcreateCredentialSourcewhen a provider is set in non-proxy mode; process, queue, files, and tokens call it immediately before each request (including everysubmitAndPollstatus poll and the result download). The provider overrides a staticapiKey; behavior is unchanged when no provider is configured. Proxy mode still sends no API key and does not invoke the provider for HTTP.Docs and JSDoc now describe per-request minting, no SDK caching, and that upload tokens need an
expiresInlong enough for the body to finish uploading because auth is checked after the request body arrives. Unit tests cover per-request keys, invalid provider results, and proxy mode skipping the provider.Reviewed by Cursor Bugbot for commit 1e90149. Bugbot is set up for automated code reviews on this repo. Configure here.