2017-04-12 58 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 消息已收到。

相關問題