0

I am trying to follow the guide on the documentation https://github.com/manfredsteyer/angular-oauth2-oidc.

I have the following config in my constructor for the service:

authCodeFlowConfig: AuthConfig = {
   issuer: 'https://demo.identityserver.io',
   redirectUri: window.location.origin + '/home',
   clientId: 'spa',
   responseType: 'code',
   scope: 'openid profile email offline_access api',
   showDebugInformation: true
 };

this.oauthService.configure(this.authCodeFlowConfig);

(i have also tried with a redirect url of index.html but that didnt seem to make a difference)

Logging in seems to work just fine i get the redirect to the page log in and get redirected home:

    this.oauthService.loadDiscoveryDocumentAndTryLogin().then((response) => {
      if (!this.oauthService.hasValidIdToken() || !this.oauthService.hasValidAccessToken()) {
         this.oauthService.initCodeFlow();
      }
    }).catch((err) => {
      console.log(err);
    });

However the following still returns false, false, null:

    const claims = this.oauthService.getIdentityClaims();
    console.log(this.oauthService.hasValidIdToken());
    console.log(this.oauthService.hasValidAccessToken());
    console.log(claims);

I have a code= in my url have no other changes to the service and everything seems to have logged me in. I'm expecting to have done something stupid or misunderstood what is going on but any advice would be helpful.

Damian Fox
  • 37
  • 1
  • 5
  • Dont know if this is relevant but this.oauthService.logOut(); doesnt seem to have any effect either and keeps me logged in so i dont get redirected to the login page again until my token expires. I feel like this could be a session storage issue. – Damian Fox May 08 '20 at 10:20

3 Answers3

0

Turns out i wasn't doing it correctly.

I wasn't calling the load discovery document in my constructor as i should have done.

If the page reloads i dont have the discovery document to check my token against and hence it is invalid.

Damian Fox
  • 37
  • 1
  • 5
0

I had same problem, I solved as show:

file config.ts:

import { AuthConfig } from 'angular-oauth2-oidc';

export const authCodeFlowConfig: AuthConfig = {
    issuer: 'https://accounts.----/auth/realms/---',
    redirectUri: window.location.origin + '/login',
    clientId: 'my-project',
    responseType: 'code',
    scope: 'openid profile email offline_access',
    showDebugInformation: true,
};

file login.ts:

ngOnInit(): void {
    this.oauthService.configure(authCodeFlowConfig);
    this.oauthService.tokenValidationHandler = new JwksValidationHandler();
    this.oauthService.setupAutomaticSilentRefresh();
    this.oauthService.loadDiscoveryDocumentAndTryLogin().then(() => {
      if (this.oauthService.hasValidAccessToken()) {
        // Load UserProfile to get the additional claims
        this.oauthService.loadUserProfile();
        this.router.navigateByUrl('/');
      } else {
        this.oauthService.initCodeFlow();
      }
    });
}
victorpacheco3107
  • 822
  • 3
  • 10
  • 32
0

We can write in Auth config settings : StopIssuer

  • 2
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 10 '22 at 04:02