x-api-sdk-ts
Version:
TypeScript Library for the X (ex-twitter) API V2
27 lines (26 loc) • 1.08 kB
TypeScript
import { NullablePartial, TwitterApiScope } from '../../types/x-api/shared';
import { AbstractOAuthConstructor } from './IOAuthConstructor';
export interface IOAuth2Token {
accessToken: string;
refreshToken: string;
tokenExpiresAt: number;
}
export interface IOAuth2Config extends Partial<IOAuth2Token> {
clientId: string;
scopes: TwitterApiScope[];
redirectUri?: string;
state?: string;
clientSecret?: string;
codeVerifier?: string;
}
export declare abstract class AbstractOAuth2Auth extends AbstractOAuthConstructor<IOAuth2Config> {
abstract setToken(token: IOAuth2Token): this;
abstract getToken(): NullablePartial<IOAuth2Token>;
abstract generateAuthorizeUrl(state: string, codeChallenge?: string | null, codeChallengeMethod?: 'S256' | 'plain'): string;
abstract exchangeAuthCodeForToken(code: string, redirectUri: string, codeVerifier: string): Promise<this>;
abstract refreshAccessToken(): Promise<this>;
abstract getHeaders(): Promise<{
Authorization: string;
}>;
abstract isTokenExpired(): boolean;
}