JSFiddle - React, Tailwind, and code Playground
JavaScript
var authority = "https://login.windows.net/mytenant.onmicrosoft.com",
redirectUri = "http://MyDirectorySearcherApp",
resourceUri = "https://graph.windows.net",
clientId = "HidingMyNativeClientAppId",
graphApiVersion = "2013-11-08",
webApiResourceUri = "https://mywebapi.azurewebsites.net";
var app = {
// Invoked when Cordova is fully loaded.
onDeviceReady: function () {
document.getElementById('search').addEventListener('click', app.search);
},
// Implements search operations.
search: function () {
document.getElementById('userlist').innerHTML = "";
app.authenticate(function (authresult) {
var searchText = document.getElementById('searchfield').value;
// Get data from Azure AD directory
app.requestData(authresult, searchText);
// Get data from Azure Web Api
app.requestWebApiData(authresult);
});
},
// Shows user authentication dialog if required.
authenticate: function (authCompletedCallback) {
app.context = new Microsoft.ADAL.AuthenticationContext(authority);
app.context.tokenCache.readItems().then(function (items) {
if (items.length > 0) {
authority = items[0].authority;
app.context = new Microsoft.ADAL.AuthenticationContext(authority);
}
// Attempt to authorize user silently
app.context.acquireTokenSilentAsync(resourceUri, clientId)
.then(authCompletedCallback, function () {
// We require user cridentials so triggers authentication dialog
app.context.acquireTokenAsync(resourceUri, clientId, redirectUri)
.then(authCompletedCallback, function (err) {
app.error("Failed to authenticate: " + err);
});
});
});
},
// Makes Api call to receive user list.
requestData: function (authResult,...