2017-04-12 81 views
0

我已经为Word创建了Office Addin。当我尝试对Office 365进行身份验证时,我正在使用“Office.context.ui.displayDialogAsync”打开一个对话框。我的回调是成功的,对话框打开。对话框打开后,api调用'_dlg.addEventHandler(Office.EventType.DialogEventReceived,processMessage);'它返回错误代码'12003',这意味着需要https,但我的页面通过https提供。通过对话框从Office Addin对Office 365进行身份验证

不知道为什么我得到这个错误,如果我的网页通过https服务?

$scope.startLogin = function() { 
       showLoginPopup("/Auth.html").then(function successCallback(response) { 

        // authentication has succeeded but to get the authenication context for the 
        // user which is stored in localStorage we need to reload the page. 
        window.location.reload(); 
       }, function errorCallback(response) { 
        console.log(response); 
       }); 
      }; 



var _dlg; 
var _dlgDefer; 

var showLoginPopup = function (url) { 
       _dlgDefer = $q.defer(); 

       Office.context.ui.displayDialogAsync('https://' + location.hostname + url, { height: 40, width: 40}, function (result) { 
        console.log("dialog has initialized. wiring up events"); 
        _dlg = result.value; 
        console.log(result.value) 
        _dlg.addEventHandler(Office.EventType.DialogEventReceived, processMessage); 
       }); 

       return _dlgDefer.promise; 
      } 

function processMessage(arg) { 
       console.log(arg.error) 
       var msg = arg.message; 
       console.log("Message received in processMessage"); 
       if (msg && msg === "success") { 
        //we now have a valid auth token in the localStorage 
        _dlg.close(); 
        _dlgDefer.resolve(); 
       } else { 
        //something went wrong with authentication 
        _dlg.close(); 
        console.log("Authentication failed: " + arg.message); 
        _dlgDefer.reject(); 
       } 
      } 

回答

0

你的代码中的一些事情让我认为你可能会使用旧的例子。 Dialog API有一些变化。如果你还没有,请阅读Use the Dialog API in your Office Add-ins

12003并不意味着作为参数传递给displayDialogAsync()的原始页面是非HTTPS。相反,这意味着在最初打开HTTPS URL后,该对话已被重定向到非HTTPS地址。您需要查看Auth.html页面的脚本,并查看该对话框重定向到的URL。

我注意到的另一件事: 您的DialogEventReceived处理程序测试“success”为arg.message。 DialogEventReceived现在仅用于错误处理。通常,应使用messageParent()调用将成功传递到主机页面。您在主页上使用事件处理程序处理这些消息Dialog 消息已收到。

相关问题