The function getIdentityTokenDecrypted is giving me a hard time. I'd like to return the promise from decryptToken SERVICE B to getToken SERVICE A, to retrieve the token.
Here are the steps I need :
- Get
outlookService.mailbox.getUserIdentityTokenAsyncresult. (Gives an encrypted token) - Decrypt token via
$httproute/api/exchange/createAndValidateIdentityToken. This request returns the token I need in SERVICE A.
How can I get this to work ?
/*** 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;
};