Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support targeting browser in login command #537

Merged
merged 2 commits into from Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion command-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
"noprompt",
"setalias",
"setdefaultdevhubusername",
"setdefaultusername"
"setdefaultusername",
"browser"
],
"alias": ["force:auth:web:login"]
}
Expand Down
6 changes: 4 additions & 2 deletions messages/web.login.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"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.",
"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.",
"examples": [
"$ sfdx auth:web:login -a TestOrg1",
"$ sfdx auth:web:login -i <OAuth client id>",
"$ sfdx auth:web:login -r https://MyDomainName--SandboxName.sandbox.my.salesforce.com"
"$ sfdx auth:web:login -r https://MyDomainName--SandboxName.sandbox.my.salesforce.com",
"$ sfdx auth:web:login -a TestOrg1 -b firefox"
],
"browser": "browser where the org opens",
"deviceWarning": "auth:web:login doesn't work when authorizing to a headless environment. Use auth:device:login instead.",
"invalidClientId": "Invalid client credentials. Verify the OAuth client secret and ID. %s"
}
10 changes: 9 additions & 1 deletion src/commands/auth/web/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export default class Login extends SfdxCommand {
public static aliases = ['force:auth:web:login'];

public static readonly flagsConfig: FlagsConfig = {
browser: flags.enum({
char: 'b',
description: messages.getMessage('browser'),
options: ['chrome', 'edge', 'firefox'], // These are ones supported by "open" package
This conversation was marked as resolved.
Show resolved Hide resolved
}),
clientid: flags.string({
char: 'i',
description: commonMessages.getMessage('clientId'),
Expand Down Expand Up @@ -102,7 +107,10 @@ export default class Login extends SfdxCommand {
private async executeLoginFlow(oauthConfig: OAuth2Config): Promise<AuthInfo> {
const oauthServer = await WebOAuthServer.create({ oauthConfig });
await oauthServer.start();
await open(oauthServer.getAuthorizationUrl(), { wait: false });
const openOptions = this.flags.browser
? { app: { name: open.apps[this.flags.browser as string] as open.AppName }, wait: false }
: { wait: false };
await open(oauthServer.getAuthorizationUrl(), openOptions);
return oauthServer.authorizeAndSave();
}
}
Expand Down