I'm developing a webapp using Phonegap/Cordova, and for authentication: Adal.js (Active Directory Authentication Library for JavaScript). Using DevExtreme Components to UI.
On the Browser Simulator it works fine, but when I generate .apk and install on android mobile device, doesn't works. The problem is Redirect Uri, in Azure Portal -> App Registrations, I configure reply url: https:localhost:port/index.html
, but in android app (in this case cordova app) I need to configure it to something like: file://android_asset/index.html
. But doesn't works.
Is there any way to make it work?
var microsoftAuthenticationParameters = {
clientId: "myClientID",
tenantId: "myTenantID",
popUp: true,
redirectUri: window.location.href + '/index.html',
endpoints: { "aisApiUri": "myClientID" },
cacheLocation: "localStorage"
}
function authenticate() {
authContext = new AuthenticationContext(microsoftAuthenticationParameters);
var isCallback = authContext.isCallback(window.location.hash);
if (isCallback) {
authContext.handleWindowCallback();
}
if (isCallback && !authContext.getLoginError()) {
window.location = authContext._getItem(authContext.CONSTANTS.STORAGE.LOGIN_REQUEST);
}
else {
authContext.getLoginError();
}
var user = authContext.getCachedUser();
if (user) {
userInfo = user.userName;
var username = userInfo.split("@");
}
else {
authContext.login();
}
}
ADAL is not designed to work in Cordova. However, there is a Cordova plugin that you can use for setting up AAD authentication. Reference: Azure ADAL Authentication for Cordova App Guidance Also, I would suggest that you check the steps mentioned in the below document for adding authentication to your Cordova Application. Add Authentication to the App
There are some good workarounds provided here on Stackoverflow for the very problem you described, and some helpful samples on Github as well. Setting a valid Azure AD uri for PhoneGap