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 couldn't 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.
Ionic Native is a TypeScript wrapper for Cordova/PhoneGap plugins that make adding any native functionality you need to your Ionic mobile app easy.
Ionic React is an open source UI and Native API project consisting of cross-platform UI components and native functionality for building iOS, Android, Electron and Progressive Web Apps using React and standard web technology.
I have got a work around for the issue, i'm posting my answer below. If anyone is facing the same issue they can try this.
Sending empty string for userId and extraQueryParameters in acquireTokenAsync function solved the issue for me.
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));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With