iframe 中的 Azure AD MSAL

Azure AD MSAL in iframe

我有一个受 azure ad 保护并使用 msal 的网站,我想在 iframe 中访问它,但它看起来不起作用。有没有办法让它工作?是否与重定向 url 或其他问题有关?

您需要在身份验证配置中指定以允许在 IFrame 中重定向 https://azuread.github.io/microsoft-authentication-library-for-js/ref/modules/_azure_msal_browser.html

您无法在 iframe 中对用户进行身份验证,这意味着您无法使用重定向 API 与身份提供商进行用户交互。

您可以从创建自己的客户页面开始,允许用户输入凭据,然后对用户进行身份验证。当用户输入他们的凭据并点击登录时,服务器将 return OK(如果 email/password 正确)。之后,您应该将令牌保存在本地存储中,然后设置 isAuthenticated = true.

如果您使用的是授权代码流程,那么您应该在外部真实页面而不是在iframe 中进行身份验证。然后,您将必须在通过身份验证后登录。这个概念是您必须完全重定向到 azure ad 中的 Auth 页面,而不是 iframe。

You can achieve single sign-on between iframed and parent apps with the same-origin and with cross-origin if you pass an account hint from the parent app to the iframed app.

了解更多here