Wednesday, 11 July 2018

How to use Ionic native - MS Adal in ionic project?

I'm new to ionic and i want to authenticate the user using Azure. So i'm using MS Adal ionic native in my project. I could not find any proper example online. Here is my app.component.ts

import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { MSAdal, AuthenticationContext, AuthenticationResult } from '@ionic- 
native/ms-adal';

import { HomePage } from '../pages/home/home';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
  rootPage:any = HomePage;

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

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

  authContext.acquireTokenAsync('https://graph.windows.net', '[My-appID]', 'http://localhost:8000')
    .then((authResponse: AuthenticationResult) => {
       console.log('Token is' , authResponse.accessToken);
       console.log('Token will expire on', authResponse.expiresOn);
    })
    .catch((e: any) => 
    alert(e));
    statusBar.styleDefault();
    splashScreen.hide();
     });
   }
 }

I'm getting the following error.

TypeError: Wrong type for parameter "userId" of AuthenticationContext.acquireTokenAsync:Expected String,but got Function.



from How to use Ionic native - MS Adal in ionic project?

No comments:

Post a Comment