UNPKG

@google/clasp

Version:

Develop Apps Script Projects locally

33 lines (32 loc) 1.34 kB
import inquirer from 'inquirer'; import { intl } from '../intl.js'; import { AuthorizationCodeFlow, parseAuthResponseUrl } from './auth_code_flow.js'; export class ServerlessAuthorizationCodeFlow extends AuthorizationCodeFlow { constructor(oauth2client) { super(oauth2client); } async getRedirectUri() { return 'http://localhost:8888'; } async promptAndReturnCode(authorizationUrl) { const prompt = intl.formatMessage({ id: "Tx67iE", defaultMessage: [{ type: 0, value: "Authorize clasp by visiting the following URL on another device: " }, { type: 1, value: "url" }, { type: 0, value: " After authorization, copy the URL in the browser. Enter the URL from your browser after completing authorization" }] }, { url: authorizationUrl, }); const answer = await inquirer.prompt([ { message: prompt, name: 'url', type: 'input', }, ]); const { code, error } = parseAuthResponseUrl(answer.url); if (error) { throw new Error(error); } if (!code) { const msg = intl.formatMessage({ id: "XvVmSR", defaultMessage: [{ type: 0, value: "Missing code in responde URL" }] }); throw new Error(msg); } return code; } }