我是Ionic的新手,我想使用Azure对用户进行身份验证。所以我在我的项目中使用MS ADAL Ionic Native。我在网上找不到任何合适的例子。这是我的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();
});
}
}
我遇到以下错误。
TypeError:AuthenticationContext.acquireTokenAsync:Expected String,但得到Function的参数“ userId”的类型错误。
答案 0 :(得分:2)
我已经解决了这个问题,我在下面发布了我的答案。如果有人遇到同样的问题,可以尝试一下。
在acquireTokenAsync函数中为userId和extraQueryParameters发送空字符串为我解决了这个问题。
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));