【发布时间】:2018-12-06 17:05:25
【问题描述】:
我是 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 的参数“userId”的类型错误:预期的字符串,但得到了函数。
【问题讨论】:
-
我也有同样的问题。所以我开始赏金所以有人帮助你。
-
你能在stackblitz.com创建演示吗?
-
@KarnanMuthukumar 这不应该发生。您可以通过传递 userId(可选)参数值 null 来尝试吗? authContext.acquireTokenAsync('graph.windows.net', '[My-appID]', 'localhost:8000', null)
-
好的,让我们再试一次。感谢您的回复
-
我更新了你的代码。我得到了这种类型的错误。 AuthenticationContext.acquireTokenAsync 的参数“extraQueryParameters”的类型错误:预期的字符串,但得到了函数。
标签: angular typescript ionic-framework adal