Ionic Native : Authentication with MS ADAL


#1

Hello,
I’m trying to useMS ADAL in my app to authenticate users with Office365, but I really don’t understand what to do…
Is there any tutorial out there ?

Thank you


#2

I have also trouble to use MS ADAL did you find any solution for this. Did you worked success please share me your code.Any help greatly appreciated.


#3

Hello @muthu2696, you can just copy the code of the documentation and replace with your own credentials. I didn’t find an other solution than to use Azure Graph

You have to create a new application and then get the ID etc.

Can you provide your code so we can see what is not working ? Thank you


#4

Hello ferdinandferdinandfe,

Refered website,

Iam using ionic 3 iam installed following things,

ionic cordova plugin add cordova-plugin-ms-adal
npm install --save @ionic-native/ms-adal

app.module.ts

import { MSAdal } from '@ionic-native/ms-adal';

 providers: [   
    MSAdal,
]

app.component.ts file,

import { MSAdal, AuthenticationContext, AuthenticationResult } from '@ionic-native/ms-adal';

  constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen,     private msAdal: MSAdal
  ) {
    platform.ready().then(() => {

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

      authContext.acquireTokenAsync('https://graph.windows.net', '2c3c3de8-e5b1-4bc9-8fb3-d2ca421bb9cb', 'http://localhost:8080/')
        .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);   
        });         
      statusBar.styleDefault();
      splashScreen.hide();
    });
  }

Here i am modified sample client Id. But when i am running i am used actual client id.I am always facing error like this,


#6

Hello muthu,

Actually you should use it like this.

If you wish to use it like you show on your example, add userId: string = '' and add it at the end of

authContext.acquireTokenAsync('https://graph.windows.net', '2c3c3de8-e5b1-4bc9-8fb3-d2ca421bb9cb', 'http://localhost:8080/')

Tell me if it helps


#7

Ok thanks for your reply i try once and let me know.


#8

I tried it’s shown error like this,

any help and idea about this?. I am facing this error last one week for this.


#9

I’ve seen this and it is related to the acquireTokenAsync call parameters. It doesn’t accept undefined parameters, it must be null or an empty string - Surprise! :slight_smile: Double check the params for acquireTokenAsync and make sure you provide null or empty string for the optional parameters.