wrobins / cordova-plugin-msal

Use the newest Microsoft MSAL library in your Cordova-based project!
Apache License 2.0
23 stars 63 forks source link

Plugin is not running when authorizationUserAgent is equal to BROWSER or DEFAULT. #111

Open jeimz143 opened 8 months ago

jeimz143 commented 8 months ago

Hi @wrobins , first of all as a student|newbie, i love your plugin and it really help me connect to my B2C project.

Currently i am having issue with the authorizationUserAgent field. If it is set to WEBVIEW, everything looks good but, if it was set to BROWSER or DEFAULT, nothing is happening like the Plugin is not running. i'm not sure if i'm missing some steps. currently, my project is running with Vue.js and capacitor JS 5.

The main reason why i needed to run the plugin via external BROWSER is that, Facebook login via Webview has been deprecated and it does not allow anymore to login via Webview it needs to be in browser. https://developers.facebook.com/docs/facebook-login/android/deprecating-webviews/

here is my code:

setup() {
    onMounted(async () => {
      let msal = window.cordova.plugins.msalPlugin;
      const options = {
        clientId: "<MY_CLIENT_ID>",
        authorizationUserAgent: "BROWSER",
        accountMode: "SINGLE",
        authorities: [
          {
            type: "B2C",
            authorityUrl:
              "https://MYB2C.b2clogin.com/tfp/MYB2C.onmicrosoft.com/<MY-POLICY-SIGN-UP-SIGN-IN>",
            default: true,
          },
        ],
        scopes: [
          "MyApp.Read",
        ],
        authorizationQueryStringParameters: [
          {
            param: "domain_hint",
            value: "<MY-DOMAIN-HINT>",
          },
        ],
      };
      await msal.msalInit(
        function () {
          msal.signInSilent(
            function (resp) {
              // resp is an object containing information about the signed in user, see below.
              // saveAuth(resp);
              console.log(resp);
            },
            function (err) {
              // err probably says "No accounts found" but maybe other debugging info
              // Don't show this to the user; just use it for debugging.
              // Here's where you either call the next prompt or wait for the user
              console.log(err);
              msal.signInInteractive(
                function (resp) {
                  // resp is an object containing information about the signed in user, see below.
                  // saveAuth(resp);
                  console.log(resp);
                },
                (err) => console.log(err)
              );
            }
          );
        },
        function (err) {
          console.log(err);
        },
        options
      );
    });
    return {};
  }

Thanks in Advance!