在office-js-helpers的帮助下验证和获取数据到word addin的问题=)

时间:2017-06-09 13:56:40

标签: javascript microsoft-graph office-js office-addins

尝试使用office-js-helpers而不是ADAL来验证和获取数据。我在stackoverflow上遵循了github.com/OfficeDev/office-js-helpers和其他类似问题的说明。

这是代码 - 首先来自Office-initialize:

 Office.initialize = function (reason) {

    if (OfficeHelpers.Authenticator.isAuthDialog()) {
        return;
    }

    authenticator = new OfficeHelpers.Authenticator();
    // Register Microsoft endpoint by overriding default values
    authenticator.endpoints.registerAzureADAuth(
        azureADClientID, //clientId
        // baseUrl,
        'xxxxxxxxxx.onmicrosoft.com',  // tenant
        {
        responseType: 'token',
        scope: 'user',
        redirectUrl: 'https://xxxxxxxxxx.azurewebsites.net/'
        } 
    );

连接到按钮的AJAX调用以检索信息:

     function getDataFromSelection() {

    authenticator
        .authenticate(OfficeHelpers.DefaultEndpoints.AzureAD)
        .then(function (token) {
            var url = "https://graph.microsoft.com/v1.0/me";

            var html = "<ul>";
            var response;
            console.log("token: ", token);
            // app.showNotification("token: ", JSON.stringify(token));
            $.ajax({
                // beforeSend: function (request) {
                //    request.setRequestHeader("Accept", "application/json");
                // },
                type: "GET",
                url: url,
                dataType: "json",
                headers: {
                    'Authorization': 'Bearer ' + token.access_token,
                }
            }).done(function (response) {

                html += getPropertyHtml("Namn", response.displayName);
                html += getPropertyHtml("Titel", response.jobTitle);
                html += getPropertyHtml("Avdelning", response.officeLocation);
                // html += getPropertyHtml("Telefon jobb", response.businessPhones);
                $("#results").html(html);    
            }).fail(function (response) {
                app.showNotification('Error: ' + JSON.stringify(error));
                app.showNotification('Inloggningen slutade att fungera!', 'Du får logga ut och prova att logga in igen'); //response.responseText
                }).always(function () {

                console.log("AJAX is done!!");
                }).then(function (response) {
                    postDataToContentControlers(response);
                })
        });


}

获取有关webbrowser的不同错误:

谷歌浏览器:

我点击按钮然后被要求批准打开一个新窗口。我开了它,然后打开dialogwindow并转到第一个login.microsoftonline.com和插件,然后关闭窗口。我得到数据但在控制台中我得到错误: postMessageError

当我按下按钮来填充名为postDataToContentControlers(response)的contentControls时,我已经包含了一个函数被激活;

必须点击它才能填充contencControls。首先,我得到了这个错误:

ContentControl._onAccess

似乎是异步问题?

解决:这很安静,很容易解决。刚刚将功能移到了 $(document.ready(function(){}

接下来的webbrowser - Egde。

这里我们得到与chrome exept相同的程序,它没有关闭对话框,我没有得到任何数据。

编辑:这仍然是一个问题,但在较旧的EDGE版本上,它不是问题。

Microsoft edge 20.10240.16384.0

在该版本上它实际关闭对话框并返回到addin,您现在已登录并检索数据。 由virtualBox运行,我有一个带有旧边缘的Windows10 =)

在桌面Word上,它按预期工作=)

ON Explorer 11与边缘类似的问题

是否有人遇到类似问题或认识到其中的一些问题? 希望得到一些答案 - 谢谢=)

我实际上正在使用特殊的登录页面重定向到该页面,然后关闭对话框。好还是不好?怎么办?

0 个答案:

没有答案