azure-web-app-service - 将 Azure AD 授权 token 从容器 Web 应用程序传递到嵌入式 (iFrame) 应用程序中

标签 azure-web-app-service adal iframe-app

我有:

  • 已配置 Azure 身份验证的 Web 应用程序(带有 adal.js 的 Javascript)
  • 作为 iFrame (Javascript) 嵌入到第一个应用程序中的第二个应用程序
  • 第二个应用程序必须能够使用部署到 Azure(可能部署到另一个域)的 Azure 身份验证调用另一个 WebAPI。

  • 问题:是否有可能获得 AAD 授权 token (从第一个(容器)应用程序到第二个应用程序?如果是,将不胜感激任何指南/示例。

    最佳答案

    我们可以使用 Window.postMessage 从本地通信两个窗口方法。下面是一个简单的示例,用于模拟从父页面获取 token 的过程。您可以根据安全考虑对其进行修改以验证域:

    ContainerPage1.Html

    <!DOCTYPE html>
    
    <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
        <iframe src="InnerPage.html"></iframe>
        <script>
            var token = "abc";
            window.addEventListener("message", receiveMessage, false);
    
            function receiveMessage(event) {
                if (event.data === "accquireToken")
                    event.source.postMessage(token,"*");
            }
    
        </script>
    </body>
    </html>
    

    内页.Html
    <!DOCTYPE html>
    
    <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
        <script>  
    
        window.addEventListener("message", receiveMessage, false);
    
        function receiveMessage(event) {
            alert(event.data)
        }
    
        function accquireToken() {
            window.parent.postMessage("accquireToken","*");
        }
    
        </script>
    
        <input id="Button1" type="button" value="Accquire Token" onclick="accquireToken()" />
    </body>
    </html>
    

    关于azure-web-app-service - 将 Azure AD 授权 token 从容器 Web 应用程序传递到嵌入式 (iFrame) 应用程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40269669/

    相关文章:

    azure - azure web 应用程序上的用户权限问题(应用程序池 - 身份)

    linux - 如何在 Azure Web App 中设置重写规则 - Linux

    azure - Windows azure : Install wordpress in subfolder

    azure - 如果未传递 userId,acquireTokenAsync 方法会抛出错误

    angular - 在单个授权请求中访问多个资源

    facebook - 从 facebook iframe 获取父页面 html 内容?

    c# - 日志记录仅在本地有效,但在部署到 Microsoft Azure 应用服务时无效

    java - 无法从 Office 365 门户打开我的应用程序。获取应用程序错误的未定义登录 URL

    javascript - Facebook 选项卡 (iFrame) : Use Facebook's JavaScript absoluteTop to keep a div at the top of te page all the time

    javascript - 在 iframe 中将参数传递给 ember