繁体   English   中英

使用Puppeteer和Node JS进行Sharepoint身份验证

[英]Sharepoint authentication with Puppeteer and Node JS

我无法找到验证用户身份的方法。 当你手动启动Node JS Server时,这工作正常(是的,它的丑陋代码):

 if (data.URL.includes("https://share.url.com")) {
        await page.type('#userNameInput', 'user');
        await page.type('#passwordInput', 'pass');
        await page.click('#submitButton');

        await page.waitForNavigation({waitUntil: 'load'});
        await page.waitFor(6000);
    }

Sharepoint不知道我的用户数据,所以他们导航到登录页面,在那里我可以填写登录信息,然后移动到我要求的网站。 但在此期间有2个更改:1。此登录页面不再存在,如果找不到登录信息,我只是链接到一个页面,其中显示“抱歉,您无法访问此页面”。 第二个问题或变化是节点服务器由服务启动。

最后,我只需要以某种方式访问​​该页面,然后截取它的截图。 但是认证让我很麻烦。 我现在需要解决这个问题,但我不能考虑其他解决方案。

Puppeteer认证:

await page.authenticate({
    username: "user", 
    password: "pass"
});

这不起作用或使用此与auth标头也不起作用。

保存用户信誉。 在浏览器中(chrom(ium)):

我试图保存用户信誉。 对于浏览器中的页面,但这没有任何影响。

网址验证:

我尝试在URL中验证( https:// user:pass@share.url.com/bla/site.aspx ),但它不起作用。

我没有想法如何处理这个问题,你有什么建议我可以用其他方式尝试这个或者你看到我的代码或我的想法中的错误?

谢谢比尔盖茨

关于

保存用户信誉。 在浏览器中(chrom(ium)):

我有类似的情况 - 当我登录时,我想从Facebook做截图。为了实现它,我做了以下步骤:

1)创建临时用户数据目录

mkdir /tmp/puppeteer_test

2)使用这些参数运行Chrome

/usr/bin/google-chrome --user-data-dir=/tmp/puppeteer_test --password-store=basic

3)转到facebook.com,登录然后关闭浏览器

4)使用适当的参数运行puppeteer:

const browser = await puppeteer.launch({
  headless: false,
  executablePath: '/usr/bin/google-chrome',
  args: ['--user-data-dir=/tmp/puppeteer_test']
});
const page = await browser.newPage();
await page.goto('https://facebook.com', { waitUntil: 'networkidle2' });
await page.screenshot({path: 'facebook.png'});
await browser.close();

我正在为SharePoint做以下事情

const browser = await puppeteer.launch();
const page = await browser.newPage();

await page.setViewport({width: 1920, height: 1080});

// Open SharePoint page
console.log("Opening page");
await page.goto('https://mytenant.sharepoint.com/sites/mysite');
await page.waitForNavigation({ waitUntil: 'networkidle0' });
console.log("Page opened");

// Input username
console.log("Inputting username");
await page.type('#i0116', 'user@mytenant.com');
await page.click('#idSIButton9');
await page.waitForNavigation({ waitUntil: 'networkidle0' });
console.log("Username input completed");

// Input password
console.log("Inputting password");
await page.type('#i0118', 'password123');
await page.click('#idSIButton9');
await page.waitForNavigation({ waitUntil: 'networkidle0' });
console.log("Password input completed");

// Stay signed in
console.log("staying signed in");
await page.keyboard.press('Enter');
await page.waitForNavigation({ waitUntil: 'networkidle0' });
console.log("staying signed in completed");

// Wait, because rendering is picky
await page.waitFor(6000);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM