import { pick, isArray } from 'lodash'; import request from '../../../utils/request'; export interface GetAuthCodeOptions { appId: string; scopes: 'auth_user' | 'auth_base' | string[]; } // Generated by https://quicktype.io export interface AuthResult { authCode: string; authDestUrl: string; } // Generated by https://quicktype.io export interface ReqAuthResult { authCode: string; authDestUrl: string; authResultCode: string; errorScopes: null; resultCode: string; success: boolean; successScopes: string[]; } export async function getAuthCode(options: GetAuthCodeOptions): Promise { let scopes: any = options.scopes; if (isArray(scopes)) { scopes = scopes.join(','); } const result = await request({ method: 'GET', host: 'ide', path: '/cli/sim/auth.json', needSign: true, data: { ...options, scopes, }, }); return pick(result, ['authCode', 'authDestUrl']); }