From b5216f70491665eb2983706d639da3a1f90742f5 Mon Sep 17 00:00:00 2001 From: Paul Engel Date: Fri, 2 Apr 2021 17:17:31 +0200 Subject: [PATCH] feat: support logging in with FusionAuth (#213) * feat: support logging in with FusionAuth * refactor: improve login credentials code --- package.json | 2 +- src/utils/ide.ts | 25 +++++++++++++++---------- yarn.lock | 8 ++++---- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 65dae81d..2c82a885 100644 --- a/package.json +++ b/package.json @@ -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": [ diff --git a/src/utils/ide.ts b/src/utils/ide.ts index cc0755ac..963f78ca 100644 --- a/src/utils/ide.ts +++ b/src/utils/ide.ts @@ -113,8 +113,11 @@ class IDE { await this.webhead.get('/login'); } - const entireCredentials = async (): Promise => { - if (this.webhead.$('form [name="username"]').length) { + const ensureAuth = async (): Promise => { + 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([ { @@ -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 => { + const ensure2FA = async (): Promise => { if (this.webhead.$('form [name="otp"]').length) { const { otp } = await prompts([ { @@ -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; } } diff --git a/yarn.lock b/yarn.lock index c24ecfab..cb116057 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"