1

I'm trying to integrate my Ionic/Capacitor app with Microsoft Authentication Library (Msal), and unfortunately I couldn't found any Capacitor plugin for that, only found this Cordova plugin with its Ionic wrapper.

So I've followed the instructions of how to use Cordova plugins with capacitor according with the instructions of the plugin itself, but unfortunately with no success.

The problem is in the cordova plugin not being executed:

cordova.exec(successCallback, errorCallback, 'MsalPlugin', 'msalInit', [JSON.stringify(options)]);

because cordova.js is not exist. Although I added the cordova.js and cordova_plugin.js in index.html, but still the cordova.js file is empty when use chrome://inspect.

Also cordova.js is exist in android\app\src\main\assets but it seems like it's an old version that is not containing the method androidExec() which is being called when try on another Ionic/Cordova app. But even this version not exist when run application on emulator.

The msal Cordova plugin added with commands: npm i --save cordova-plugin-msal and npm i --save ionic-msal-native

Platforms Android

package.json dependencies:

"dependencies": {
    "@angular/common": "~12.1.1",
    "@angular/compiler": "~12.1.1",
    "@angular/core": "~12.1.1",
    "@angular/forms": "~12.1.1",
    "@angular/platform-browser": "~12.1.1",
    "@angular/platform-browser-dynamic": "~12.1.1",
    "@angular/router": "~12.1.1",
    "@capacitor/android": "^3.1.2",
    "@capacitor/cli": "^3.1.2",
    "@capacitor/core": "^3.1.2",
    "@ionic/angular": "^5.5.2",
    "cordova-plugin-msal": "^2.5.0",
    "ionic-msal-native": "^0.1.0",
    "rxjs": "~6.6.0",
    "tslib": "^2.2.0",
    "zone.js": "~0.11.4"
  },

Capacitor Doctor

Latest Dependencies:

  @capacitor/cli: 3.1.2
  @capacitor/core: 3.1.2
  @capacitor/android: 3.1.2
  @capacitor/ios: 3.1.2

Installed Dependencies:

  @capacitor/ios: not installed
  @capacitor/core: 3.1.2
  @capacitor/cli: 3.1.2
  @capacitor/android: 3.1.2

[success] Android looking great! 

npm --version: 6.14.14 node --version: v14.17.4

was i missing something or made something wrong?

Mahmoud
  • 197
  • 1
  • 5
  • 16
  • I tried to add the `cordova.js` file inside `www` folder manually, then run the synch command `npx cap synch android`, but still got nothing – Mahmoud Aug 11 '21 at 09:32

1 Answers1

0

It looks like you are testing your app in the browser? Generally cordova plugins don't work/get loaded in the browser as they are meant to bridge the gap between native functionality and your javascript based frontend. Best would be to run your code in an emulator or on a real device to see your plugin in action.

You might also find some answers here Where do I find cordova.js?

George DW
  • 66
  • 3
  • No i'm not testing on browser, i'm just using the browser for inspecting, i'm testing on android AVD with android studio. – Mahmoud Aug 11 '21 at 09:01