@salesforce/core
Version:
Core libraries to interact with SFDX projects, orgs, and APIs.
72 lines (71 loc) • 2.26 kB
TypeScript
import { AsyncCreatable } from '@salesforce/kit';
import { OAuth2Config } from '@jsforce/jsforce-node';
import { JsonMap, Nullable } from '@salesforce/ts-types';
import { AuthInfo } from './org/authInfo';
export type DeviceCodeResponse = {
device_code: string;
interval: number;
user_code: string;
verification_uri: string;
} & JsonMap;
export type DeviceCodePollingResponse = {
access_token: string;
refresh_token: string;
signature: string;
scope: string;
instance_url: string;
id: string;
token_type: string;
issued_at: string;
} & JsonMap;
/**
* Handles device based login flows
*
* Usage:
* ```
* const oauthConfig = {
* loginUrl: this.flags.instanceurl,
* clientId: this.flags.clientid,
* };
* const deviceOauthService = await DeviceOauthService.create(oauthConfig);
* const loginData = await deviceOauthService.requestDeviceLogin();
* console.log(loginData);
* const approval = await deviceOauthService.awaitDeviceApproval(loginData);
* const authInfo = await deviceOauthService.authorizeAndSave(approval);
* ```
*/
export declare class DeviceOauthService extends AsyncCreatable<OAuth2Config> {
static RESPONSE_TYPE: string;
static GRANT_TYPE: string;
static SCOPE: string;
private static POLLING_COUNT_MAX;
private logger;
private options;
private pollingCount;
constructor(options: OAuth2Config);
/**
* Begin the authorization flow by requesting the login
*
* @returns {Promise<DeviceCodeResponse>}
*/
requestDeviceLogin(): Promise<DeviceCodeResponse>;
/**
* Polls the server until successful response OR max attempts have been made
*
* @returns {Promise<Nullable<DeviceCodePollingResponse>>}
*/
awaitDeviceApproval(loginData: DeviceCodeResponse): Promise<Nullable<DeviceCodePollingResponse>>;
/**
* Creates and saves new AuthInfo
*
* @returns {Promise<AuthInfo>}
*/
authorizeAndSave(approval: DeviceCodePollingResponse): Promise<AuthInfo>;
protected init(): Promise<void>;
private getLoginOptions;
private getPollingOptions;
private getDeviceFlowRequestUrl;
private poll;
private shouldContinuePolling;
private pollForDeviceApproval;
}