-
Notifications
You must be signed in to change notification settings - Fork 64
Description
Is your feature request related to a problem? Please describe.
I would like to add an option --incognito-browser for box login, which opens a new browser instance in incognito mode. This allows a user to login with an account different from the one currently logged in.
Describe the solution you'd like
This option can be easily realized by upgrading open and with small changes:
diff --git a/package.json b/package.json
index 2f78fc1..ee138fa 100644
--- a/package.json
+++ b/package.json
@@ -44,7 +44,7 @@
"lodash": "^4.17.13",
"mkdirp": "^1.0.4",
"nanoid": "^3.3.1",
- "open": "^8.0.4",
+ "open": "^10.1.0",
"ora": "^5.4.1",
"p-event": "^2.3.1"
},
diff --git a/src/commands/login.js b/src/commands/login.js
index 580ea76..c50b746 100644
--- a/src/commands/login.js
+++ b/src/commands/login.js
@@ -10,7 +10,6 @@ const BoxCLIError = require('../cli-error');
const CLITokenCache = require('../token-cache');
const pkg = require('../../package.json');
const chalk = require('chalk');
-const open = require('open');
const express = require('express');
const inquirer = require('inquirer');
const path = require('path');
@@ -20,6 +19,9 @@ const { nanoid } = require('nanoid');
class OAuthLoginCommand extends BoxCommand {
async run() {
+ const open_module = await import('open');
+ const open = open_module.default;
+ const apps = open_module.apps;
const { flags } = this.parse(OAuthLoginCommand);
const environmentsObj = await this.getEnvironments();
const port = flags.port;
@@ -183,7 +185,11 @@ class OAuthLoginCommand extends BoxCommand {
`http://localhost:${port}/callback?state=${authInfo.state}&code=${authInfo.code}`
);
} else {
- open(authorizeUrl);
+ if (flags['incognito-browser']) {
+ open(authorizeUrl, {newInstance: true, app: {name: apps.browserPrivate}});
+ } else {
+ open(authorizeUrl);
+ }
this.info(
chalk`{yellow If you are redirect to files view, please make sure that your Redirect URI is set up correctly and restart the login command.}`
);
@@ -205,6 +211,11 @@ OAuthLoginCommand.flags = {
description: 'Manually visit authorize URL and input code',
default: false,
}),
+ 'incognito-browser': flags.boolean({
+ char: 'i',
+ description: 'Visit authorize URL with incognito browser',
+ default: false,
+ }),
name: flags.string({
char: 'n',
description: 'Set a name for the environment',open 8.0.4 doesn't contain a critical patch sindresorhus/open#332, so at least 10.0.3 is necessary. As sindresorhus/open@v10.0.3...v10.1.0 doesn't have any change about dependencies, the latest 10.1.0 should be okay. Since 9.0.0, the package also supports a portable way to open a browser, which is utilized in the above diff (cf. sindresorhus/open#266, sindresorhus/open#294).
The downside is that this requires Node.js 18.x.
Describe alternatives you've considered
Utilizing any customized open. This is technically possible, though will lead to confusion in the future.