Configuration parameters. See AuthorizationOptions for details.
Injects Authorization headers using a TokenProvider interface. When a
401 Unauthorized response is received, the middleware calls the token provider
again (allowing token refresh) and retries according to the configured backoff
strategy. Existing Authorization headers are respected and not overridden.
Only 401 status triggers retry; other error statuses pass through unchanged.
import { withAuthorization } from "@qfetch/middleware-authorization";
import { constant, upto } from "@proventuslabs/retry-strategies";
const qfetch = withAuthorization({
tokenProvider: {
getToken: async () => ({
accessToken: "my-token",
tokenType: "Bearer"
})
},
strategy: () => upto(1, constant(0))
})(fetch);
Middleware that injects authorization headers and retries on 401 responses.