【发布时间】:2018-06-12 14:29:24
【问题描述】:
我目前正在尝试在我的 Angular 应用程序中实施 azure 广告身份验证。不幸的是,我遇到了一个我不明白的错误。在我的应用程序中,我调用了 angular-oauth2-oidc 包的 tryLogin 函数。在调用此函数之前,登录一直有效,因为它给了我以下错误:
ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'nonceStateSeparator' of null
TypeError: Cannot read property 'nonceStateSeparator' of null
at OAuthService.push../node_modules/angular-oauth2-oidc/esm5/angular-oauth2-oidc.js.OAuthService.tryLogin
登录功能似乎可以工作,因为它将令牌作为参数返回到应用程序的 url 中。
我的代码:
export class AppComponent implements OnInit {
title = 'test';
constructor(private oauthService: OAuthService) {
}
private async ConfigureAuth(): Promise<void> {
this.oauthService.loginUrl = 'loginurl';
this.oauthService.clientId = 'clientid';
this.oauthService.resource = 'resource';
this.oauthService.logoutUrl = 'logoutUrl';
this.oauthService.redirectUri = window.location.origin + '/';
this.oauthService.scope = 'openid';
this.oauthService.oidc = true;
this.oauthService.setStorage(sessionStorage);
}
async ngOnInit() {
console.log('Starting ngInit');
await this.ConfigureAuth();
console.log('Await passed ngInit');
this.oauthService.tryLogin({}); //ERROR here
console.log('TryLogin passed ngInit');
if(!this.oauthService.getAccessToken()) {
console.log('no accestoken - ngInit');
await this.oauthService.initImplicitFlow();
}
console.log(this.oauthService.getAccessToken());
console.log('Finished ngInit');
}
}
希望有人能帮我解决这个问题。
【问题讨论】:
标签: angular oauth-2.0 azure-active-directory