功能getIdentityTokenDecrypted
給我很難。我想從decryptToken
SERVICE B返回承諾getToken
服務A,以檢索令牌。如何從函數返回承諾?
這裏是我所需要的步驟:
- 獲取
outlookService.mailbox.getUserIdentityTokenAsync
結果。 (給出加密令牌) - 通過
$http
路由/api/exchange/createAndValidateIdentityToken
解密令牌。此請求返回我在SERVICE A中需要的令牌。
我該如何獲得此工作?
/*** SERVICE A ***/
var service = {
/*...*/
token: getToken()
};
return service;
function getToken() {
var token;
serviceB.getIdentityTokenDecrypted()
.then(function successCallback(response) {
token = response.data.UniqueUserIdentification;
return token;
}, function errorCallback(response) {
return null;
});
}
/*** SERVICE B ***/
function getIdentityTokenDecrypted() {
var token = null;
var promise;
// This async call does not return a promise,
// I don't think I can chain after it.
outlookService.mailbox.getUserIdentityTokenAsync(function (res) {
token = res;
});
// That's why I use an interval
promise = $interval(function() {
if (token != null) {
$interval.cancel(promise);
return decryptToken();
}
}, 100);
function decryptToken() {
var location = window.location.href;
// I need to get the 'data' from the success
// of this request to retrieve the token
return $http({
method: "POST",
url: "/api/exchange/createAndValidateIdentityToken",
data: JSON.stringify({
userIdentityToken: token,
location: location
})
});
};
return promise;
};
有第一個參數是回調方法:https://msdn.microsoft.com/en-us/library/office/fp142236.aspx雖然它導致了同樣的問題,我不知道如何從此回調函數返回$ hhtp調用的承諾。 – Elfayer