Seeking help to authenticate users on my Ionic application using an external service, and I need to utilize Cordova's InAppBrowser. The code functions correctly on Android, but on iOS, the "loadstop" event never triggers, preventing the browser from redirecting back to the application. My current code is as follows:
$rootScope.$on('$cordovaInAppBrowser:loadstop', function (e, event) {
console.log('inappbrowser loaded', event);
var regex = /* regex to determine if url is correct redirected url */
var res = regex.test(event.url);
alert('loaded: ' + event.url);
alert('regex result: ' + res);
if(res === true) {
$cordovaInAppBrowser.close();
}
});
if(okta) {
if (typeof window.localStorage.msRefreshToken === 'undefined') {
document.addEventListener('deviceready', function () {
$cordovaInAppBrowser.open('urlforExternalservicehere', '_blank', options);
}, false);
} else {
TokenStore.refreshAccessToken();
}
}
No alerts are displayed when running the code. Furthermore, after reaching the external service and entering the user's username, they are redirected to another URL where they must use a different set of credentials for authentication, resulting in a token being returned for app authentication.
In an ideal scenario mirroring Android behavior, the loadstop event should trigger three times on iOS, with the third time closing the in-app browser upon regex validation.
If additional code is needed to address this issue, please let me know!
Cordova Version: 4.2.0
Ionic: 1.4.5
iOS: 8 and 9
NgCordova used for Cordova functionality
UPDATE: While running the app on an emulator and reviewing the console logs, the following error is encountered:
Error: Module cordova-plugin-inappbrowser.inappbrowser does not exist., , Line: 1402
Despite having the plugin installed, it seems to be missing. Any suggestions for resolving this issue would be greatly appreciated. Thank you!