How do I get my access token

I am using your steps to “Integrate my app” for Angular. Using that method, how do I get the access_token?

I tried setting scope to “openid profile email” in the call client.loginWithRedirect. I don’t what observable I should subscribe to to get this information.

Thanks for all your help

Hi @bitsmaker,

Welcome to the Auth0 Community Forum!

Are you using Auth0.js or auth0-spa-js?

Let me know,
Dan

Hi Dan!

Thanks for your prompt response. Please note that I am using auth0-spa-js.

Is there a way to get all of access_token, id_token and expires_in as well?

@bitsmaker,

Take a look at this for the access token:

and this for idToken claims:

If you are not requesting an access token for a custom API, then the token will be opaque and the expiry will be 24 hours.

Hope this helps,
Dan

Dan,
I was able to make the necessary calls, thanks for your guidance. I wanted to confirm that getTokenSilently returns the access_token and getIdTokenClaims returns a JSON where the key exp contains the expiration. I did not see a key call id_token. Not sure where to get that from.

On a side note could your company please update the example at https://auth0.com/docs/quickstart/spa/angular2 to include the following functions in auth.service.ts

getTokenSilently$() : Observable {
return this.auth0Client$.pipe(
concatMap((client: Auth0Client) => from(client.getTokenSilently({
scope: “openid”,
audience: “”
}))),
);
}

getIdTokenClaims$() : Observable {
return this.auth0Client$.pipe(
concatMap((client: Auth0Client) => from(client.getIdTokenClaims())),
);
}

Please confirm the above items for me. Thanks again for your help

Hey @bitsmaker,

As you can see in the following example in the doc for the library, getTokenSilently is used for getting the access token:

https://auth0.github.io/auth0-spa-js/#2---calling-an-api

Auth0-spa-js does not have a built in function to get the id_token. Please see this thread that discusses the situation:

As for the example, can you please submit it as a PR to the respective repo, the managing team will have a better understanding of the needs of the particular framework, and we try to keep the repo specific discussions organized on GitHub.

Thanks,
Dan

Thanks, Dan, will do. You may close this one

1 Like

Let us know if there is anything else we can do.

Thanks,
Dan

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.

Update: The raw id token is now available via this method:

$('#getIdTokenClaims').click(async () => {
  const claims = await auth0.getIdTokenClaims();
  // if you need the raw id_token, you can access it
  // using the __raw property
  const id_token = claims.__raw;
});