oauthService.getAccessToken() 在 angular-oauth2-oidc 中返回 null

问题描述

下面给出的是使用 angular-oauth2-oidc 使用 AD FS 验证我的角度 SPA 的代码

  initializeOAuthService(): void {

    this.oauthService.configure({
      redirectUri: window.location.origin + '/app/search',requireHttps: true,scope: 'openid profile email',responseType: 'id_token token',oidc: true,clientId: environment.adfsClientId,loginUrl: environment.adfsUrl + '/oauth2/authorize',issuer: environment.adfsUrl,logoutUrl:
        environment.adfsUrl +
        '/ls/?wa=wsignoutcleanup1.0&wreply=' +
        location.protocol +
        '//' +
        location.hostname +
        (location.port ? ':' + location.port : ''),postlogoutRedirectUri:
        location.protocol +
        '//' +
        location.hostname +
        (location.port ? ':' + location.port : ''),});

    this.oauthService.tokenValidationHandler = new JwksValidationHandler();
    this.oauthService.setStorage(localStorage);

    if (!this.oauthService.hasValidAccesstoken()) {
      console.log('no access token available');
      this.oauthService
        .loaddiscoveryDocumentAndTryLogin()
        .then(() => {
          if (!this.oauthService.hasValidAccesstoken()) {
            this.oauthService.initImplicitFlow();
          }
        })
        .catch((error) => {
          console.log(error);
        });
    }

    // this.oauthService.setupAutomaticSilentRefresh();
  }

我可以成功登录应用程序,并且可以在 URL 中看到访问和 ID 令牌。

但是当我调用“oauthService.getAccesstoken()”或“this.oauthService.getIdentityClaims()”时,我得到了空值。

谁能告诉我我错过了什么?

注意:我从登录组件的构造函数调用了上述方法登录页面和 AD FS 重定向到的页面不同。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)