Skip to content

Commit

Permalink
feat: support logging in with FusionAuth (#213)
Browse files Browse the repository at this point in the history
* feat: support logging in with FusionAuth

* refactor: improve login credentials code
  • Loading branch information
archan937 authored Apr 2, 2021
1 parent 173f0e8 commit b5216f7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"ts-node": "^8.8.2",
"tsconfig-paths": "^3.9.0",
"typescript": "^3.5.3",
"webhead": "^1.1.1"
"webhead": "^1.1.2"
},
"ava": {
"extensions": [
Expand Down
25 changes: 15 additions & 10 deletions src/utils/ide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,11 @@ class IDE {
await this.webhead.get('/login');
}

const entireCredentials = async (): Promise<void> => {
if (this.webhead.$('form [name="username"]').length) {
const ensureAuth = async (): Promise<void> => {
const cassieLogin = !!this.webhead.$('form [name="username"]').length;
const fusionAuthLogin = !!this.webhead.$('form [name="loginId"]').length;

if (cassieLogin || fusionAuthLogin) {
const config = fs.readJsonSync(this.configFile);
const { email, password } = await prompts([
{
Expand All @@ -133,16 +136,18 @@ class IDE {
config.email = email;
fs.writeFileSync(this.configFile, JSON.stringify(config, null, 2));

await this.webhead.submit('form', {
username: email,
const identifier = cassieLogin ? 'username' : 'loginId';
const input = {
[identifier]: email,
password,
});
};

await entireCredentials();
await this.webhead.submit('form', input);
await ensureAuth();
}
};

const entire2FA = async (): Promise<void> => {
const ensure2FA = async (): Promise<void> => {
if (this.webhead.$('form [name="otp"]').length) {
const { otp } = await prompts([
{
Expand All @@ -153,12 +158,12 @@ class IDE {
]);

await this.webhead.submit('form', { otp });
await entire2FA();
await ensure2FA();
}
};

await entireCredentials();
await entire2FA();
await ensureAuth();
await ensure2FA();
this.loggedIn = true;
}
}
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10663,10 +10663,10 @@ wcwidth@^1.0.0, wcwidth@^1.0.1:
dependencies:
defaults "^1.0.3"

webhead@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/webhead/-/webhead-1.1.1.tgz#a484904a99a12b901c54ead41a0ded184d2dfd57"
integrity sha512-EW4dicBO82kQK8ir77imeFK0Q3iYaoOUCNAR/jXixYvYG312dwvCQB2U7yv5NxljSqagZOE4+yHL0P1bJhl0Cg==
webhead@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/webhead/-/webhead-1.1.2.tgz#bd3c0c2fd89a954097ff5bacc9a2dd88407219a6"
integrity sha512-r0Ww/l7IQ1jUqfvZW1+sn7QuOO3S4JTL+BMlWbssacfFoNNNNlOCOSpPvjO19+KT2jczKm3EH1o/OScpt/88wg==
dependencies:
"@types/cheerio" "^0.22.22"
cheerio "^1.0.0-rc.3"
Expand Down

0 comments on commit b5216f7

Please sign in to comment.