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 Auth0 Angular SDK Quickstarts: Login 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:

Auth0-spa-js does not have a built in function to get the id_token. Please see this thread that discusses the situation: You can get the raw id token by passing a raw param.

https://github.com/auth0/auth0-spa-js/pull/54

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.

https://github.com/auth0-samples/auth0-angular-samples/tree/master/01-Login

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;
});
2 Likes