身份验证无头铬在Azure功能中发射

发布于 2025-01-30 15:25:36 字数 644 浏览 3 评论 0原文

在我们的项目中,我们构建了一个Azure功能,该功能以无头模式启动PuppeTeer,转到我们的网页,并在页面上进行屏幕截图,然后将其发送给PDF报告。在本地工作并部署到Azure。那是POC。现在,我们正在进入生产并引入身份验证(Azure AD B2C,单人租户),将通过APIM等运行每个HTTP请求等。

现在发生了什么

  • 我们的功能应用程序已在AD中注册为守护程序并收到访问令牌。
  • 此访问令牌已插入puppeteer(page.setextrahttpheaders)的“携带者”授权标题中,
  • 无头浏览器不会得到认证,我们收到的屏幕截图是登录屏幕(azure sso)

发生的事情我们需要发生什么。

  • 我们需要 COLDINCE 我们的前端用来对用户进行身份验证,无头浏览器应获得身份验证并允许渲染页面

我想出的解决方案到目前为止,将MSAL反应的逻辑复制到Puppeteer的会话存储中,以便当MSAL反应检查持续的会话时,它将找到并允许无头铬。我尚未实现它。我很好奇社区中的任何人都有建立类似的东西的经验。

In our project we've built an Azure Function which launches Puppeteer in headless mode, goes to our webpage and takes a screenshot of the page which is then emailed out as pdf report. Works locally and deployed to Azure. That was the POC though. Now, we're moving to production and introduced authentication (Azure AD B2C, single tenant), will run each http request via APIM etc.

What happens now:

  • our Function app was registered in AD as a daemon and receives an access token.
  • this access token is inserted into 'Bearer ' Authorization header in Puppeteer (page.setExtraHTTPHeaders)
  • headless browser does not get authenticated and screenshot we receive is of the login screen (Azure SSO)

What needs to happen

  • we need to convince the react-msal library our FrontEnd is using to authenticate users, that the headless browser should get authenticated and allowed to render the page

The solution I've come up with so far is to replicate msal-react's logic of saving session information into Puppeteer's session storage, so that when msal-react checks for persisted session it will find it and allow headless chromium in. I'm yet to implement it. I'm curious if anyone in the community has experience building something similar.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文