如何在离子项目中使用 Ionic native - MS Adal?
How to use Ionic native - MS Adal in ionic project?
我是 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: Wrong type for parameter "userId" of AuthenticationContext.acquireTokenAsync:Expected String,but got Function.
我已经解决了这个问题,我在下面发布了我的答案。如果有人遇到同样的问题,他们可以试试这个。
在 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));
我是 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: Wrong type for parameter "userId" of AuthenticationContext.acquireTokenAsync:Expected String,but got Function.
我已经解决了这个问题,我在下面发布了我的答案。如果有人遇到同样的问题,他们可以试试这个。
在 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));