Notes
Notes - notes.io |
/* istanbul ignore next */
const Controller = require('../../lib/controller');
const MFAHandler = require('./mfa.handler');
const PuppeteerHelper = require('../../lib/helper/puppeteer.helper');
const logger = require('../../lib/common/log').logger;
const EVENTS = require('../../lib/common/constants').tlevents;
/**
* The Hartford Financial Services Group, Inc. MFA Handler
*/
class Insr_1valb7miRhmKk5ekNkGvWFAS0JwCustomHandler extends MFAHandler {
constructor(session_id) {
super(session_id);
this.session = global.session_mgr.get_session(session_id);
this.ph = new PuppeteerHelper(this.session.page);
}
async chk_identifier(page) {
logger.debug(`Insr_1valb7miRhmKk5ekNkGvWFAS0JwCustomHandler -> chk_identifier -> ${this.session_id}`);
const elements = ['input[id="radiobtnidsendTextId"][type="radio"], input[aria-label="Text Code"][type="radio"]', 'input[id="radiobtnidsendEmailID"][type="radio"], input[aria-label*="@"][type="radio"]', 'input[id="radiobtnidsendCallId"][type="radio"], input[aria-label="Call Me"][type="radio"]', `//*[contains(text(), "send you a temporary access code")] | //*[contains(text(), "For Security, Please Verify Your Device")] | //*[contains(text(), "Get Code")]`];
let session = global.session_mgr.get_session(this.session_id);
try {
await this.ph.waitForXPath(elements[3], page); //MFA Select Page (https://account.thehartford.com/customer/#/login/mfaSelect?appid=CSC)
} catch (e) {
logger.warn(e);
}
if (await this.ph.isElementExist(elements[0], page)) {
logger.info('Insr_1valb7miRhmKk5ekNkGvWFAS0JwCustomHandler -> chk_identifier -> Text Code Phone MFA Matched!!');
session.is_sms_passcode_mfa = true;
return true;
}
if (await this.ph.isElementExist(elements[1], page)) {
logger.info('Insr_1valb7miRhmKk5ekNkGvWFAS0JwCustomHandler -> chk_identifier -> Text Code By Email MFA Matched!!');
session.is_email_passcode_mfa = true;
return true;
}
if (await this.ph.isElementExist(elements[2], page)) {
logger.info('Insr_1valb7miRhmKk5ekNkGvWFAS0JwCustomHandler -> chk_identifier -> Call Me Phone Passcode MFA Matched!!');
session.is_call_passcode_mfa = true;
return true;
}
return false;
}
async has_mfa(page) {
logger.debug(`Insr_1valb7miRhmKk5ekNkGvWFAS0JwCustomHandler -> has_mfa -> ${this.session_id}`);
if (!await this.chk_identifier(page)) {
return false;
}
let session = global.session_mgr.get_session(this.session_id);
session.mfa = this;
session.mfa.filepath = __filename.split('mfa/')[1] || "";
return true;
}
async get_mfa_details(page) {
logger.debug(`Insr_1valb7miRhmKk5ekNkGvWFAS0JwCustomHandler -> get_mfa_details -> ${this.session_id}`);
return await this.set_auth_method(page);
}
async trigger_passcode(page, selector) {
logger.debug(`Insr_1valb7miRhmKk5ekNkGvWFAS0JwCustomHandler -> trigger_passcode - started`);
const elements = ['button[aria-label="Get Code"]', 'input#securityCode, input[arial-label="Code"], input[name*="Code"]'];
await this.ph.waitForSelector(selector, page, {
timeout: 10000,
visible: false
});
await this.ph.performHiddenClick(selector, page); //Click on "Text Code"/"Email"/"Call Me" radio input
await this.ph.waitForSelector(elements[0], page);
await this.ph.performClick(elements[0], page); //Click on "Get Code" button
try {
await this.ph.waitForSelector(elements[1], page); //Wait for Code input element
} catch (e) {
logger.warn(e);
}
}
async set_auth_method(page) {
logger.debug(`Insr_1valb7miRhmKk5ekNkGvWFAS0JwCustomHandler -> set_auth_method -> ${this.session_id}`);
let session = global.session_mgr.get_session(this.session_id);
const elements = ['input[id="radiobtnidsendTextId"][type="radio"], input[aria-label="Text Code"][type="radio"]', 'input[id="radiobtnidsendEmailID"][type="radio"], input[aria-label*="@"][type="radio"]', 'input[id="radiobtnidsendCallId"][type="radio"], input[aria-label="Call Me"][type="radio"]'];
if (session.is_sms_passcode_mfa) {
await this.trigger_passcode(page, elements[0]);
return session.mfa.details = {
"mfa_type": 'PASSCODE',
"mfa_method": 'SMS',
"destination": null //Need to update this later
};
}
if (session.is_email_passcode_mfa) {
await this.trigger_passcode(page, elements[1]);
return session.mfa.details = {
"mfa_type": 'PASSCODE',
"mfa_method": 'EMAIL',
"destination": null //Need to update this later
};
}
if (session.is_call_passcode_mfa) {
await this.trigger_passcode(page, elements[2]);
return session.mfa.details = {
"mfa_type": 'PASSCODE',
"mfa_method": 'CALL',
"destination": null //Need to update this later
};
}
}
async check_session_expired_screen(page) {
logger.debug('Insr_1valb7miRhmKk5ekNkGvWFAS0JwCustomHandler -> check_session_expired_screen -> started');
const elements = ['//*[text()[contains(., "Your session has expired")]]', ['Your session has expired']];
let is_error = await this.ph.searchError(elements[1], page);
if (is_error) {
logger.debug(await this.ph.getErrorText(page));
}
let eh = await this.ph.getElementHandler(elements[0], page);
let is_session_expired = is_error || (typeof eh === 'object' && eh.length > 0);
logger.info(`Insr_1valb7miRhmKk5ekNkGvWFAS0JwCustomHandler -> check_session_expired_screen -> is_session_expired - ${is_session_expired}`);
return is_session_expired;
}
async is_login_page(page) {
logger.debug(`Insr_1valb7miRhmKk5ekNkGvWFAS0JwCustomHandler -> is_login_page -> started`);
const elements = ['input#loginEmail', 'input#loginPassword'];
let is_username = await this.ph.isElementExist(elements[0], page);
let is_password = await this.ph.isElementExist(elements[1], page);
logger.info(`Insr_1valb7miRhmKk5ekNkGvWFAS0JwCustomHandler -> is_login_page -> is_username - ${is_username}, is_password - ${is_password}`);
return (is_username || is_password);
}
async navigate_to_mfa_page(page) {
logger.debug(`Insr_1valb7miRhmKk5ekNkGvWFAS0JwCustomHandler -> navigate_to_mfa_page -> started`);
const elements = ['input#loginEmail', 'input#loginPassword'];
let session = global.session_mgr.get_session(this.session_id);
try {
await this.ph.waitForSelector(elements[0], page);
await this.ph.clearElementValue(elements[0], page);
await this.ph.fillElementValue(elements[0], session.credentials.username, page);
await this.ph.waitForSelector(elements[1], page);
await this.ph.clearElementValue(elements[1], page);
await this.ph.fillElementValue(elements[1], session.credentials.password, page);
await this.ph.pressEnter(elements[1], page);
await this.ph.once(page, 'load');
} catch (e) {
logger.warn(e);
}
await this.trigger_passcode(page);
return page;
}
async passcode_handler(passcode, page) { //https://account.thehartford.com/customer/#/login/mfaEnterOTP?appid=CSC
logger.debug(`Insr_1valb7miRhmKk5ekNkGvWFAS0JwCustomHandler -> passcode_handler -> ${this.session_id}`);
const elements = ['input#securityCode, input[arial-label="Code"], input[name*="Code"]'];
const errRegexList = ["Looks like that didn't work", 'Please-double check the code and try again']; //If your code has expired, you can click "I didn't get a code" to get another one
let session = global.session_mgr.get_session(this.session_id);
try {
await this.ph.waitForSelector(elements[0], page);
await this.ph.clearElementValue(elements[0], page);
await this.ph.fillElementValue(elements[0], passcode, page);
await this.ph.pressEnter(elements[0], page);
await this.ph.once(page, 'load');
await Promise.race([this.ph.waitForNavigation(page), this.ph.waitFor(5000)]);
} catch (e) {
logger.warn(e);
}
if (await this.is_login_page(page)) { //After entering wrong PASSCODE three times it will route to login page again.
logger.warn(await this.ph.getErrorText(page));
page = await this.navigate_to_mfa_page(page);
}
if (await this.ph.isElementExist(elements[0], page) || await this.ph.searchError(errRegexList, page) || await this.has_mfa(page)) {
logger.warn(await this.ph.getErrorText(page));
return session.event_emitter.emit('error', Controller.getError('mfa', 'unauthorized'));
}
if (await this.check_session_expired_screen(page)) {
logger.warn(await this.ph.getErrorText(page));
return session.event_emitter.emit('error', Controller.getError('mfa', 'retry'));
}
return session.event_emitter.emit(EVENTS.mfa.success, {
session_id: this.session_id
});
}
async handle_mfa(page, passcode = '') {
logger.debug(`Insr_1valb7miRhmKk5ekNkGvWFAS0JwCustomHandler -> handle_mfa -> Session ID: ${this.session_id}, Passcode Empty: ${!passcode}`);
let session = global.session_mgr.get_session(this.session_id);
let mfa_type = session.mfa.details.mfa_type;
logger.info(`Insr_1valb7miRhmKk5ekNkGvWFAS0JwCustomHandler -> handle_mfa -> Session ID: ${this.session_id} -> mfa_details: ${JSON.stringify(session.mfa.details)}`);
if (mfa_type === 'PASSCODE') {
return await this.passcode_handler(passcode, page);
}
return session.event_emitter.emit('error', Controller.getError('mfa', 'unauthorized'));
}
}
module.exports = Insr_1valb7miRhmKk5ekNkGvWFAS0JwCustomHandler;
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team
