qfetch
    Preparing search index...

    Interface TokenProvider

    Provider interface for retrieving authorization credentials.

    Implement this interface to supply tokens to the withAuthorization middleware. The provider is called before each request and on retry after 401 responses, allowing for token refresh or rotation.

    // Static token provider
    const staticProvider: TokenProvider = {
    getToken: async () => ({
    accessToken: "my-api-key",
    tokenType: "Bearer"
    })
    };
    // Refreshing token provider (e.g., for OAuth)
    class OAuthTokenProvider implements TokenProvider {
    private accessToken: string;
    private refreshToken: string;

    async getToken(): Promise<AuthorizationToken> {
    if (this.isExpired()) {
    await this.refresh();
    }
    return { accessToken: this.accessToken, tokenType: "Bearer" };
    }
    }
    interface TokenProvider {
        getToken(): Promise<AuthorizationToken>;
    }
    Index

    Methods

    Methods

    • Retrieves the current authorization credentials.

      Called before each request and before each retry attempt on 401 responses. Implementations may return cached tokens or fetch fresh ones as needed.

      Returns Promise<AuthorizationToken>

      A promise resolving to the authorization token credentials.

      If token retrieval fails, the error propagates to the caller.