There is a website that uses two-factor authentication. On the login form there is a checkbox that, when checked, allows me to bypass the two-factor authentication step (for the current device) in the future after successfully logging in the first time. I was hoping to do this manually at first, and then use headless Chrome to automate logging in. I thought that by pointing puppeteer to my Chrome application and also pointing the userDataDir to my profile, it would allow puppeteer to access the site already logged in. But when I access the site with puppeteer, it still shows the two-factor authentication step.
Does anyone know what might be missing that would allow me to access the site without two-factor authentication? Just to clarify: Using Chrome manually and logging in does not display the two-factor authentication step, but using puppeteer does.
Note in the following code, #remember-me is the checkbox that allows me to skip the two-factor auth.
const puppeteer = require('puppeteer');
(async() => {
const browser = await puppeteer.launch({
executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
headless: true,
userDataDir: '/Users/xxxx/Library/Application Support/Google/Chrome'
});
const page = await browser.newPage();
await page.goto('https://portal.insperity.com', {waitUntil: 'networkidle2'});
await page.evaluate(() => {
document.querySelector('#username').value = 'username';
document.querySelector('#password').value = 'password';
document.querySelector('#remember-me').checked = true;
document.querySelector('#submit').click();
})
await page.waitFor(1000);
await page.screenshot({path: 'page2.png'});
await browser.close();
})();
Update: I tried changing the headless property to false and commenting out the await browser.close() line and executing the script. In the Chrome instance that launched, I noticed that I am not signed into Google or Stack Overflow. So it looks like my cookies are not being sent. What could be causing this or what am I missing?
For reference, here are specs of the software I am using:
if your web site uses cookies for authentication, you might be better of setting cookies and bypass two-factor authentication. but that means you would have to get the cookies from somewhere.
await page.goto('https://youhomepage.com');
let cookieObject ={
name:"JSESSIONID",
value:"9C8E6659B14C2963EDED73C16BB0868A",
Expires:"Tue, 19 Jan 2038 03:14:07 GMT"
}
await page.setCookie(cookieObject);
await page.waitFor(1000);
await page.goto('https://youhomepage.com');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With