Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a way to retrieve the ID Token using a custom (non-default) audience #214

Closed
schnucks-pveeramach opened this issue Sep 10, 2021 · 2 comments
Labels
feature request A feature has been asked for or suggested by the community

Comments

@schnucks-pveeramach
Copy link

Problem

If access token is retrieved using a non default audience, the idTokenClaims$ observable emits an event with a null value because it internally appears to be always looking for id token using the default audience:

// This returns a null value when access token is retrieved as shown on the next line
this.authService.idTokenClaims$.pipe((take(1)))
  .subscribe((idToken) => {
    console.log('id token:', JSON.stringify(idToken));
  });

this.authService.getAccessTokenSilently({
      audience: 'non default audience',
      ignoreCache: true
    });

Ideal solution

The AuthService either exposes a way to retrieve the ID token for a given audience or the observable emits id tokens for any audience with some way to identify what audience it is for.

@schnucks-pveeramach schnucks-pveeramach added the feature request A feature has been asked for or suggested by the community label Sep 10, 2021
@schnucks-pveeramach
Copy link
Author

schnucks-pveeramach commented Sep 10, 2021

Now that 1.6.1 is available, the below snippet worked, because the injection token is exposed:

this.authService.getAccessTokenSilently({
      audience: 'non default audience',
      ignoreCache: true
    }).pipe(take(1))
      .subscribe((token) => {
        this.auth0Client.getIdTokenClaims({
          audience: 'non default audience'
        }).then((idToken) => console.log(idToken));
      });

where auth0Client is injected into the component using:
@Inject(Auth0ClientService) private auth0Client: Auth0Client

Maybe this is not a good approach or the intended use of the injection token but documenting the observation nevertheless.

@frederikprijck
Copy link
Member

Thanks for the update. I believe this is not an explicitly supported feature, but a side-effect of exposing the auth0Client, which I believe is a good idea for these kind of situations where you might need behavior of the underlying SDk that doesn't exist in the Angular SDK natively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request A feature has been asked for or suggested by the community
Projects
None yet
Development

No branches or pull requests

2 participants