Skip to content

Commit 6eb35e0

Browse files
authored
feat: support targeting browser in login command (#537)
* feat: support targeting browser in login command * refactor: using flags.enum instead of flag.string
1 parent 2aed4be commit 6eb35e0

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

command-snapshot.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@
8383
"noprompt",
8484
"setalias",
8585
"setdefaultdevhubusername",
86-
"setdefaultusername"
86+
"setdefaultusername",
87+
"browser"
8788
],
8889
"alias": ["force:auth:web:login"]
8990
}

messages/web.login.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
{
2-
"description": "authorize an org using the web login flow\nIf you specify an --instanceurl value, this value overrides the sfdcLoginUrl value in your sfdx-project.json file. To specify a My Domain URL, use the format MyDomainName.my.salesforce.com (not MyDomainName.lightning.force.com). To log in to a sandbox, set --instanceurl to https://MyDomainName--SandboxName.sandbox.my.salesforce.com.",
2+
"description": "authorize an org using the web login flow\nIf you specify an --instanceurl value, this value overrides the sfdcLoginUrl value in your sfdx-project.json file. To specify a My Domain URL, use the format MyDomainName.my.salesforce.com (not MyDomainName.lightning.force.com). To log in to a sandbox, set --instanceurl to https://MyDomainName--SandboxName.sandbox.my.salesforce.com.\nTo open in a specific browser, use the --browser parameter. Supported browsers are \"chrome\", \"edge\", and \"firefox\". If you don't specify --browser, the org opens in your default browser.",
33
"examples": [
44
"$ sfdx auth:web:login -a TestOrg1",
55
"$ sfdx auth:web:login -i <OAuth client id>",
6-
"$ sfdx auth:web:login -r https://MyDomainName--SandboxName.sandbox.my.salesforce.com"
6+
"$ sfdx auth:web:login -r https://MyDomainName--SandboxName.sandbox.my.salesforce.com",
7+
"$ sfdx auth:web:login -a TestOrg1 -b firefox"
78
],
9+
"browser": "browser where the org opens",
810
"deviceWarning": "auth:web:login doesn't work when authorizing to a headless environment. Use auth:device:login instead.",
911
"invalidClientId": "Invalid client credentials. Verify the OAuth client secret and ID. %s"
1012
}

src/commands/auth/web/login.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ export default class Login extends SfdxCommand {
2626
public static aliases = ['force:auth:web:login'];
2727

2828
public static readonly flagsConfig: FlagsConfig = {
29+
browser: flags.enum({
30+
char: 'b',
31+
description: messages.getMessage('browser'),
32+
options: ['chrome', 'edge', 'firefox'], // These are ones supported by "open" package
33+
}),
2934
clientid: flags.string({
3035
char: 'i',
3136
description: commonMessages.getMessage('clientId'),
@@ -102,7 +107,10 @@ export default class Login extends SfdxCommand {
102107
private async executeLoginFlow(oauthConfig: OAuth2Config): Promise<AuthInfo> {
103108
const oauthServer = await WebOAuthServer.create({ oauthConfig });
104109
await oauthServer.start();
105-
await open(oauthServer.getAuthorizationUrl(), { wait: false });
110+
const openOptions = this.flags.browser
111+
? { app: { name: open.apps[this.flags.browser as string] as open.AppName }, wait: false }
112+
: { wait: false };
113+
await open(oauthServer.getAuthorizationUrl(), openOptions);
106114
return oauthServer.authorizeAndSave();
107115
}
108116
}

0 commit comments

Comments
 (0)