-
Notifications
You must be signed in to change notification settings - Fork 41
/
loginurl.ts
43 lines (32 loc) · 1.49 KB
/
loginurl.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { flags, SfdxCommand } from '@salesforce/command';
import * as assert from 'assert';
import { exec2JSON } from '@mshanemc/plugin-helpers';
export default class LoginURL extends SfdxCommand {
public static description = 'generate a long-lived shareable login url for the org';
public static examples = [
`sfdx shane:user:loginurl
// generates a url including un and pw query strings to simplify logging into the scratch org
`,
`sfdx shane:user:loginurl -p /lightning/setup/ObjectManager/home
// same, but sets the start url to ObjectManager
`
];
protected static flagsConfig = {
starturl: flags.string({ char: 'p', description: 'url to open' })
};
protected static requiresUsername = true;
public async run(): Promise<any> {
const auth = this.org.getConnection().getAuthInfoFields();
// this.ux.logJson(auth);
assert.ok(auth.password, 'No password is set...run sfdx shane:user:password:set first');
const username = this.org.getUsername();
const resultObject = await exec2JSON(`sfdx force:org:display --json -u ${username}`);
// this.ux.logJson(resultObject.result);
let url = `${auth.loginUrl}/login.jsp?un=${encodeURIComponent(auth.username)}&pw=${encodeURIComponent(resultObject.result.password)}`;
if (this.flags.starturl) {
url = `${url}&startURL=${encodeURIComponent(this.flags.starturl)}`;
}
this.ux.log(url);
return url;
}
}