在 Office 加载项中登录 AAD 时出现 X-Frame-Option DENY 错误

X-Frame-Option DENY error when AAD sign-in in office add-in

我正在使用 Adal.js 构建 Office 加载项以实现 AAD 集成。我的加载项需要一些权限。

当我在 OneNote 中打开加载项并尝试从 adal.js 调用登录时,它请求 login.microsoftonline.com 并给出 X-Frame-Option Deny 错误。
我认为这是因为 iFrame 中的 office 加载项 运行,我该如何解决这个问题?

login.microsoftonline.com/common/oauth2/authorize?response_type=id_token&cl…nt-SKU=Js&x-client-Ver=1.0.13&nonce=ced03385-f1ca-4206-bb23-6c3e8338a0d2:1 Refused to display 'https://login.microsoftonline.com/common/oauth2/authorize?response_type=id_…ient-SKU=Js&x-client-Ver=1.0.13&nonce=ced03385-f1ca-4206-bb23-6c3e8338a0d2' in a frame because it set 'X-Frame-Options' to 'DENY'.

在 Office Web 加载项中使用 OAUTH 流程进行身份验证是已知的 issue.The 可以找到对问题的更好解释 here

Due to the popularity of clickjacking on the internet, it is common to prevent login pages from being display inside frames. The X-FRAME-Options meta tag in HTML makes it easy for providers to implement this safeguard on a widespread or domain/origin-specific basis. Pages that are not “frameable” will not load consistently in an Office add-in

因此需要依赖弹窗机制。总之,身份验证流程将在弹出窗口上进行,以避免 iFraming 问题。

上面的 link 有点过时,因为它声明弹出窗口是一个必要的邪恶。 Microsoft 意识到这个问题,最近提出 dialogAPI 来解决这个问题。

让我们回到我们的 Adal.js 问题。我认为您应该停止使用 adal.js,因为它不应该在我们的加载项 Web 上下文中使用。即使他们implemented a popup technique。他们不使用可用的 dialogAPI。

您应该在可用时尝试利用此 dialogAPI,否则您会遇到很多问题(停用的弹出窗口、安全区域等)。

您最好的选择是实现自己的流机制或使用 Office-js-helpers as explained in