@lancedb/lancedb • Docs
@lancedb/lancedb / OAuthHeaderProvider
Class: OAuthHeaderProvider¶
Example implementation: OAuth token provider with automatic refresh.
This is an example implementation showing how to manage OAuth tokens with automatic refresh when they expire.
Example¶
async function fetchToken(): Promise<TokenResponse> {
const response = await fetch("https://oauth.example.com/token", {
method: "POST",
body: JSON.stringify({
grant_type: "client_credentials",
client_id: "your-client-id",
client_secret: "your-client-secret"
}),
headers: { "Content-Type": "application/json" }
});
const data = await response.json();
return {
accessToken: data.access_token,
expiresIn: data.expires_in
};
}
const provider = new OAuthHeaderProvider(fetchToken);
const headers = provider.getHeaders();
// Returns: {"authorization": "Bearer <your-token>"}
Extends¶
Constructors¶
new OAuthHeaderProvider()¶
Initialize the OAuth provider.
Parameters¶
-
tokenFetcher Function to fetch new tokens. Should return object with 'accessToken' and optionally 'expiresIn'.
-
refreshBufferSeconds:
number=300Seconds before expiry to refresh token. Default 300 (5 minutes).
Returns¶
Overrides¶
Methods¶
getHeaders()¶
Get OAuth headers, refreshing token if needed. Note: This is synchronous for now as the Rust implementation expects sync. In a real implementation, this would need to handle async properly.
Returns¶
Record<string, string>
Headers with Bearer token authorization.
Throws¶
If unable to fetch or refresh token.
Overrides¶
refreshToken()¶
Manually refresh the token. Call this before using getHeaders() to ensure token is available.
Returns¶
Promise<void>