angular-oauth2-oidc没有设置access_token

Ott*_*ley 5 openid oauth-2.0 azure-active-directory angular angular-oauth2-oidc

我遵循的是angular-oauth2-oidc库的入门指南,但是它存储的唯一内容是nonce值,access_token它不会出现在任何地方。

这是我的配置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
};
Run Code Online (Sandbox Code Playgroud)

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);
     }
}
Run Code Online (Sandbox Code Playgroud)

在我的login.component.ts我有:

export class LoginComponent {
    constructor(private oauthService: OAuthService) {}
    login(): void { this.oauthService.initImplicitFlow();}
}
Run Code Online (Sandbox Code Playgroud)

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

但是,当我转到localStorage时,唯一可以看到的就是nonce它的值,而不是它的值access_token。我已经尝试在控制台中打印它,并且收到了null

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

小智 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);
     }
    }
Run Code Online (Sandbox Code Playgroud)

尝试使用注释 tokenValidator