0
votes

I am trying to implement Microsoft SSO authentication in ionic 5.

Undefine occurs in the console when the code below is executed. Which part is the problem?

login(){
let authContext: AuthenticationContext = this.msAdal.createAuthenticationContext('https://login.windows.net/common');

authContext.acquireTokenAsync('https://graph.windows.net', 'clientID', 'http://localhost:8200')
  .then((authResponse: AuthenticationResult) => {
    console.log('Token is' , authResponse.accessToken);
    console.log('Token will expire on', authResponse.expiresOn);
  })
  .catch((e: any) => console.log('Authentication failed', e));

}

error => enter image description here

https://ionicframework.com/docs/v3/native/ms-adal/

1

1 Answers

0
votes
const browser = this_.iab.create("https://login.microsoftonline.com/" + tenant_id +
              "/oauth2/authorize?response_type=id_token&client_id=" + client_id
              +"&state=SomeState&nonce=SomeNonce"
              , '_blank', 'clearsessioncache=yes,clearcache=yes,toolbar=no,location=no,toolbarposition=top,hidenavigationbuttons=yes,toolbarcolor=#0072bb')
            browser.on("loadstart").subscribe(event => {

IAB is inappbrowser. Msal we had also tried to use when we needed this type of authentication for azure AD b2c. Similarly you have to do for your case.

There is enterprise level plugin available which cost around 8 lakhs INR.
So this is the work around. Tenant id and client id you will get when you register your app under applications in azure account.

So once the login is successful that load listener will listen to pages which IAB is visiting. And if found occurrence of #token_id(after sucesfull login).

Automatically the iab will close and ionic app page will resume or you can put some new route entry in that event listener.

May be for your case the base url might change. So try first visiting chrome with the url which opens your case login. And accordingly change.

MAKE IT WORK USING IAB AND NOT MSAL