angular-oauth2-oidc未设置access_token

时间:2018-01-15 16:55:22

标签: angular oauth-2.0 azure-active-directory openid angular-oauth2-oidc

我正在关注angular-oauth2-oidc库的入门指南,但它存储的唯一内容是nonce值,access_token不会出现在任何地方。< / p>

这是AuthConfig的配置。

export const AUTHCONFIG: AuthConfig = {
    loginUrl: 'https://login.microsoftonline.com/xxxxxxxx/oauth2/authorize',
    redirectUri: window.location.origin + '/', //localhost:4200/
    clientId: 'the id of my angular app registered in azure',
    resource: 'the id of my web api in nodejs also registered',
    oidc: true,
    requireHttps: false // this is for testing in localhost
};

我的app.component.ts有以下内容:

export class AppComponent {
     constructor(private oauthService: OAuthService) {this.loadConfig()}
     loadConfig(): void {
         this.ouathService.configure(AUTHCONFIG);
         this.ouathService.tokenValidationHandler
                          = new JwksValidationHandler();
         this.ouathService.token.setStorage(localStorage);
     }
}

login.component.ts我有:

export class LoginComponent {
    constructor(private oauthService: OAuthService) {}
    login(): void { this.oauthService.initImplicitFlow();}
}

用户在此处重定向后,我可以在URL中看到access_token等的参数。

但是当我去localStorage时,我唯一能看到的是nonce及其值,而不是access_token。我已经尝试在控制台中打印它,然后收到null

这是我回来的网址:http://localhost:4200/#access_token=thetoken&etcparams

1 个答案:

答案 0 :(得分:0)

@Otto Cheley,您不需要添加JWK验证器。

    export class AppComponent {
     constructor(private oauthService: OAuthService) {this.loadConfig()}
     loadConfig(): void {
         this.ouathService.configure(AUTHCONFIG);
        // this.ouathService.tokenValidationHandler = new JwksValidationHandler();
         this.ouathService.token.setStorage(localStorage);
     }
    }

尝试评论tokenValidator