fix(sdk): add automatic 401 retry with token refresh to openapi-fetch middleware#103
Merged
fix(sdk): add automatic 401 retry with token refresh to openapi-fetch middleware#103
Conversation
… middleware The SDK had automatic token refresh for auth.fetch() calls (WebDAV), but openapi-fetch clients (OCAPI, SLAS, SCAPI, etc.) did not retry on 401. For long-running operations, if a token expires mid-operation, API calls would fail. This adds an onResponse handler to createAuthMiddleware() that: - Detects 401 responses - Invalidates the cached token via auth.invalidateToken() - Gets a fresh token via auth.getAuthorizationHeader() - Retries the request once with the new token Uses WeakSet/WeakMap to track retried requests and preserve request bodies.
Utility script for manually testing 401 retry behavior during long-running operations. Polls active code version every 10 seconds.
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.
Summary
createAuthMiddleware()for openapi-fetch clientsinvalidateToken?(): voidtoAuthStrategyinterfaceProblem
The SDK had automatic token refresh for
auth.fetch()calls (used by WebDAV), but openapi-fetch clients did NOT retry on 401. For long-running operations (e.g., 60-minute job polls), if a token expired or was revoked mid-operation, API calls would fail.Solution
Add an
onResponsehandler tocreateAuthMiddleware()that:auth.invalidateToken()auth.getAuthorizationHeader()Uses
WeakSetto track retried requests (prevents infinite loops) andWeakMapto store cloned request bodies for retry.Test plan