From 60fe485e0591fe8d185d7b0596038fde1ca1fd4f Mon Sep 17 00:00:00 2001 From: Greg Date: Fri, 10 Dec 2021 12:14:31 -0800 Subject: [PATCH] feat: add loginUrlCredentials config (#110) allow an optional loginUrlCredentials config which provides basic authentication credentials when visiting loginUrl Co-authored-by: Greg Remiasz --- README.md | 1 + src/Plugins.js | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 79b4e0e..39b9878 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,7 @@ Options passed to the task include: | username | | | password | | | loginUrl | The URL for the login page that includes the social network buttons | https://www.example.com/login | +| loginUrlCredentials | Basic Authentication credentials for the `loginUrl` | `{username: user, password: demo}` | | args | string array which allows providing further arguments to puppeteer | `['--no-sandbox', '--disable-setuid-sandbox']` | | headless | Whether to run puppeteer in headless mode or not | true | | logs | Whether to log interaction with the loginUrl website & cookie data | false | diff --git a/src/Plugins.js b/src/Plugins.js index cddc22b..35f17f0 100644 --- a/src/Plugins.js +++ b/src/Plugins.js @@ -10,6 +10,7 @@ const fs = require('fs') * @param {options.username} string username * @param {options.password} string password * @param {options.loginUrl} string password + * @param {options.loginUrlCredentials} Object Basic Authentication credentials for the `loginUrl` * @param {options.args} array[string] string array which allows providing further arguments to puppeteer * @param {options.loginSelector} string a selector on the loginUrl page for the social provider button * @param {options.loginSelectorDelay} number delay a specific amount of time before clicking on the login button, defaults to 250ms. Pass a boolean false to avoid completely. @@ -199,7 +200,9 @@ async function baseLoginConnect( await page.setUserAgent( 'Mozilla/5.0 (Windows NT 10.0 Win64 x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36' ) - + if (options.loginUrlCredentials) { + await page.authenticate(options.loginUrlCredentials) + } await page.goto(options.loginUrl) await login({page, options})