@squidcloud/client
Version:
A typescript implementation of the Squid client
37 lines (36 loc) • 1.86 kB
TypeScript
import { GetAccessTokenResponse } from '../../internal-common/src/public-types/external-auth/external-auth.public-types';
/**
* Client for managing authentication tokens for external integrations.
*
* Provides methods for saving and retrieving auth tokens for external services.
* @category ExternalAuth
*/
export declare class ExternalAuthClient {
private readonly integrationId;
private readonly rpcManager;
/**
* Takes an auth token, potentially exchanges the auth token with an external api depending on the external auth,
* and stores the result in Squid's secure storage.
*
* This function requires Squid to be initialized with an API key
*
* @param authCode - The authorization code obtained from the auth provider's callback.
* @param identifier - A user-specific identifier (usually a user ID) to associate with the tokens.
* This allows multiple users to connect their own accounts to the same integration.
* @returns A promise that resolves with the access token and its expiration time.
*/
saveAuthCode(authCode: string, identifier: string): Promise<GetAccessTokenResponse>;
/**
* Retrieves a valid access token for the integration.
* Automatically refreshes the token if it has expired or is about to expire.
*
* This function requires Squid to be initialized with an API key
*
* @param identifier - The user-specific identifier that was used when saving the auth code.
* @returns A promise that resolves with a valid access token and its expiration time.
*
* @throws Error if no tokens are found for the given integration and identifier.
* The user must first complete the auth flow by calling `saveAuthCode()`.
*/
getAccessToken(identifier: string): Promise<GetAccessTokenResponse>;
}