2

below given is the code for authenticating my angular SPA using AD FS using angular-oauth2-oidc

  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();
  }

I can log in to the application successfully and I can see the access and id tokens in the URL.

but when I call "oauthService.getAccessToken()" or "this.oauthService.getIdentityClaims()" I am getting null as result.

Can anyone tell me what I am missing?

Note: I have called the above method from the login component's constructor. The login page and page to which the AD FS redirected are different.

Sanal M
  • 187
  • 4
  • 17
  • Can you help us reproduce the issue fully? The code you posted nowhere does `oauthService.getAccessToken()` so we can't really simulate what you're seeing. Likely the problem is in code we don't see. - Alternatively you could [compare against my sample](https://github.com/jeroenheijmans/sample-angular-oauth2-oidc-with-auth-guards) and see if there's a difference? That sample can show access and id tokens just fine. – Jeroen Nov 20 '21 at 19:05

0 Answers0