I'm following this Cordova & ADAL tutorial. I am able to successfully execute the directory search on my native app. I would like to extend the functionality of the app and add an azure web api resource and consume it in the same app.
I created the azure web api using the VS2015 template, published it to azure, added it as a web application in Azure Active Directory and gave my native application access to it in the "permissions to other applications" section within Azure AD.
I would now like to extend the example directory searcher app to also consume the api without having the user sign in again. From my research, I found that I could consume multiple resources using refresh tokens but I'm unable to figure out how to do this without signing the user in to Azure AD a second time to get a token for the web api resource.
Any examples or help would be much appreciated. Here is my jsFiddle to give you an idea of what I'm trying to do.
// Requests some data from an Azure Web API
requestWebApiData: function (authResult) {
var req = new XMLHttpRequest();
var url = webApiResourceUri + "/api/values";
req.open("GET", url, true);
req.setRequestHeader('Authorization', 'Bearer ' + authResult.accessToken);
req.onload = function (e) {
if (e.target.status >= 200 && e.target.status < 300) {
// This is where I'd like to get my data back from the Azure Web API
console.log(JSON.stringify(e.target.response));
return;
}
app.error('API Data request failed: ' + e.target.response);
};
req.onerror = function (e) {
app.error('API Data request failed: ' + e.error);
}
req.send();
},