Support passwordless auth (#129)

* support passwordless auth (using Authenticator app)

* update readme
This commit is contained in:
HMCDAT
2024-07-24 20:01:45 +07:00
committed by GitHub
parent a39a861dab
commit 2b4cd505c0
2 changed files with 39 additions and 11 deletions

View File

@@ -83,6 +83,7 @@ Under development, however mainly for personal use!
- [x] Multi-Account Support - [x] Multi-Account Support
- [x] Session Storing - [x] Session Storing
- [x] 2FA Support - [x] 2FA Support
- [x] Passwordless Support
- [x] Headless Support - [x] Headless Support
- [x] Discord Webhook Support - [x] Discord Webhook Support
- [x] Desktop Searches - [x] Desktop Searches

View File

@@ -70,10 +70,37 @@ export class Login {
await page.fill('#i0118', password) await page.fill('#i0118', password)
await page.click('#idSIButton9') await page.click('#idSIButton9')
this.bot.log('LOGIN', 'Password entered successfully')
// When erroring at this stage it means a 2FA code is required // When erroring at this stage it means a 2FA code is required
} catch (error) { } catch (error) {
this.bot.log('LOGIN', '2FA code required') // this.bot.log('LOGIN', 'App approval required because you have passwordless enabled.');
let numberToPress: string | null = await (await page.waitForSelector('#displaySign', { state: 'visible', timeout: 2000 })).textContent();
if (!numberToPress) {
await page.click('button[aria-describedby="confirmSendTitle"]');
await this.bot.utils.wait(2000);
numberToPress = await (await page.waitForSelector('#displaySign', { state: 'visible', timeout: 2000 })).textContent();
}
if (numberToPress) {
while (true) {
try {
this.bot.log('LOGIN', 'Press the number below on your Authenticator app to approve the login');
this.bot.log('LOGIN', 'If you press the wrong number or the "Deny" button, try again in 60 seconds');
this.bot.log('LOGIN', 'Number to press: ' + numberToPress);
await page.waitForSelector('#i0281', { state: 'detached', timeout: 60000 })
break;
} catch (error) {
this.bot.log('LOGIN', 'The code is expired. Trying to get the new code...');
(await page.waitForSelector('button[aria-describedby="pushNotificationsTitle errorDescription"]', { state: 'visible', timeout: 5000 })).click();
numberToPress = await (await page.waitForSelector('#displaySign', { state: 'visible', timeout: 2000 })).textContent();
}
}
this.bot.log('LOGIN', 'Login successfully approved!');
} else {
this.bot.log('LOGIN', '2FA code required')
// Wait for user input // Wait for user input
const code = await new Promise<string>((resolve) => { const code = await new Promise<string>((resolve) => {
rl.question('Enter 2FA code:\n', (input) => { rl.question('Enter 2FA code:\n', (input) => {
@@ -84,9 +111,9 @@ export class Login {
await page.fill('input[name="otc"]', code) await page.fill('input[name="otc"]', code)
await page.keyboard.press('Enter') await page.keyboard.press('Enter')
}
this.bot.log('LOGIN', 'Password entered successfully') }
}
} catch (error) { } catch (error) {
this.bot.log('LOGIN', 'An error occurred:' + error, 'error') this.bot.log('LOGIN', 'An error occurred:' + error, 'error')