无法从Microsoft Office JavaScript加载项向Trello进行身份验证

时间:2016-03-29 15:08:21

标签: javascript ms-office office365 office-js trello

我正在使用Office JavaScript API编写Office加载项。我正在使用Visual Studio中的默认脚手架。

我想连接到Trello,所以要做的第一件事是验证。我正在使用Trello提供的client.js包装器(包括我的密钥)。

我在弹出窗口中成功获取了Trello对话框,我看到我从Trello那里得到了回复,它试图将消息发回到开启窗口,但我从未在开启窗口中获得回调。

更新:Office加载项自动使用Windows上的IE版本,在本例中为IE11。这可能是我的问题的原因。 (postMessage still broken on IE11?

更新2:来自Trello的示例,了解如何验证和列出卡片。适用于Chrome和Firefox,但IE 11和EDGE已损坏。 (http://jsfiddle.net/danlec/nNesx/)。

有关如何向Trello进行身份验证而不是使用client.js的任何想法?

Trello的回应:

  

<html><head><script> if(window.opener) { window.opener.postMessage("435b83db5a8f260acdccd4a33b617b4e5daaed3cc2eefcb7ffdbbb0975ba00fa", "https://localhost:44300") } </script></head></html>

来自项目的Home.html和Home.js代码。

/// <reference path="../App.js" />
/// <reference path=
(function () {
    "use strict";
    
    function onReady() {
        app.initialize();

        //$('#get-data-from-selection').click(getDataFromSelection);

        $('#get-data-from-trello').click(getDataFromTrello);

        $('#authenticate-with-trello').click(authenticateWithTrello);
    }

    // The initialize function must be run each time a new page is loaded
    Office.initialize = function (reason) {
        $(document).ready(onReady);
    };

    function authenticateWithTrello() {

        Trello.authorize(
            {
                type: 'popup',
                persist: true,
                success: function () {
                    app.showNotification('Successful authentication');
                },
                error: function () {
                    app.showNotification('Successful authentication');
                }
            }
            );

   }

    
    function getDataFromTrello() {
        Trello.get('/member/me/boards',
            function (successMsg) {
                app.showNotification(successMsg);
            },
            function (errorMsg) {
                app.showNotification(errorMsg.responseText);
            }
            );
    }




})();
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <title></title>
    <script src="../../Scripts/jquery-1.9.1.js" type="text/javascript"></script>

    <link href="../../Content/Office.css" rel="stylesheet" type="text/css" />
    <script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js" type="text/javascript"></script>

    <!-- To enable offline debugging using a local reference to Office.js, use:                        -->
    <!-- <script src="../../Scripts/Office/MicrosoftAjax.js" type="text/javascript"></script>  -->
    <!-- <script src="../../Scripts/Office/1/office.js" type="text/javascript"></script>  -->

    <script src="https://trello.com/1/client.js?key=a0b60a9317bf763fc35e2dd42c19ecbc"></script>

    <link href="../App.css" rel="stylesheet" type="text/css" />
    <script src="../App.js" type="text/javascript"></script>

    <link href="Home.css" rel="stylesheet" type="text/css" />
    <script src="Home.js" type="text/javascript"></script>
</head>
<body>
    <div id="content-header">
        <div class="padding">
            <h1>Trello Integration</h1>
        </div>
    </div>
    <div id="content-main">
        <div class="padding">
            <p><strong>Add home screen content here.</strong></p>
            <p>For example:</p>
            <button id="authenticate-with-trello">Authenticate with trello</button>
            <button id="get-data-from-trello">Get data from trello</button>

            <p style="margin-top: 50px;">
                <a target="_blank" href="https://go.microsoft.com/fwlink/?LinkId=276812">Find more samples online...</a>
            </p>
        </div>
    </div>

</body>
</html>

1 个答案:

答案 0 :(得分:2)

是的,IE不支持跨域,跨窗口postMessage。

Trello身份验证支持重定向。在最初尝试使用重定向时,它打开了一个新窗口,直到我意识到您需要在Office Add-in Manifest中声明域,以便在嵌入式窗口中显示它。

现在有效。有关详细信息,请参阅此帖子(http://tritiumconsulting.com/2016/04/01/authenticate-to-trello-in-ms-office-javascript-add-in/