1

下面给出的是使用 angular-oauth2-oidc 使用 AD FS 验证我的 Angular 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 中看到 access 和 id 令牌。

但是当我调用“oauthService.getAccessToken()”或“this.oauthService.getIdentityClaims()”时,结果是 null。

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

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

4

0 回答 0