ebay-api
Version:
eBay API for Node and Browser
96 lines (95 loc) • 3.37 kB
TypeScript
import { EventCallback } from '../nanoevents.js';
import Base from '../api/base.js';
import { IEBayApiRequest } from '../request.js';
import { AppConfig, Scope } from '../types/index.js';
export type Token = {
access_token: string;
expires_in: number;
token_type: string;
};
export type ClientToken = Token;
export type AuthToken = Token & {
refresh_token: string;
refresh_token_expires_in: number;
};
/**
* https://developer.ebay.com/api-docs/static/oauth-tokens.html
*
* Client credentials grant flow mints a new Application access token that you can use to access the resources owned by the application.
* Authorization code grant flow mints a new User access token that you can use to access the resources owned by the user.
*/
export default class OAuth2 extends Base {
static readonly IDENTITY_ENDPOINT: Record<string, string>;
static readonly AUTHORIZE_ENDPOINT: Record<string, string>;
static readonly defaultScopes: Scope;
private readonly emitter;
private scope;
private _clientToken?;
private _authToken?;
constructor(config: AppConfig, req: IEBayApiRequest);
on(event: string, callback: EventCallback): () => void;
static generateAuthUrl(sandbox: boolean, appId: string, ruName: string, scope: string[], state?: string): string;
get identityEndpoint(): string;
/**
* Return the access token.
* First return user access token, if not set Application Access Token.
*/
getAccessToken(): Promise<string>;
getUserAccessToken(): string | null;
getApplicationAccessToken(): Promise<string>;
setClientToken(clientToken?: Token): void;
setScope(scope: Scope): void;
getScope(): string[];
/**
* Client credentials grant flow.
*/
mintApplicationAccessToken(): Promise<ClientToken>;
/**
* Client credentials grant flow.
*/
obtainApplicationAccessToken(): Promise<ClientToken>;
/**
* Generates URL for consent page landing.
*
* @param ruName RuName
* @param scope the scopes
* @param state state parameter returned in the redirect URL
*/
generateAuthUrl(ruName?: string, scope?: string[], state?: string): string;
/**
* Authorization code grant flow.
*
* Mint the user access token for the given code.
*
* @param code the code
* @param ruName the redirectUri
*/
mintUserAccessToken(code: string, ruName?: string | undefined): Promise<any>;
/**
* Authorization code grant flow.
*
* Mint the access token for the given code.
*
* @param code the code
* @param ruName the redirectUri
*/
getToken(code: string, ruName?: string | undefined): Promise<any>;
/**
* Authorization code grant flow.
*/
refreshUserAccessToken(): Promise<AuthToken>;
/**
* Gets and sets the user access token for the given code.
*
* Authorization code grant flow.
*
* @param code the code
*/
obtainToken(code: string): Promise<AuthToken>;
getCredentials(): AuthToken | ClientToken | null;
setCredentials(authToken: AuthToken | string): void;
/**
* Refresh the user access token if set or application access token
*/
refreshToken(): Promise<Token>;
}