# Using idToken to access internal API

**URL:** <https://community.auth0.com/t/using-idtoken-to-access-internal-api/87256>\
**Category:** JWT.io\
**Created:** [July 20, 2022, 9:50am UTC](https://community.auth0.com/t/using-idtoken-to-access-internal-api/87256 "2022-07-20T09:50:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![tamlynfm](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/tamlynfm/32/28224_2.png) [@tamlynfm](https://community.auth0.com/u/tamlynfm)\
**Post date:** [July 20, 2022, 9:50am UTC](https://community.auth0.com/t/using-idtoken-to-access-internal-api/87256/1 "2022-07-20T09:50:06Z")

</div>

I have an Auth0 `Native` application, used by a React Native mobile app, for which Auth0 provides credentials with an encrypted `accessToken` and an `idToken`. I can use the access token to call the `/userinfo` endpoint. And I can decode the ID token to see the user’s details. The mobile app communicates with a backend over HTTP. I can send the ID token to the backend and verify it using JWKS, checking that the `iss` and `aud` claims are correct for the `Native` application.

All this works fine but I have two concerns:

1. I don’t know how to generate an ID token for testing purposes, to allow me to call my backend during development with cURL or Postman.
2. I have read in [multiple](https://auth0.com/blog/id-token-access-token-what-is-the-difference/#What-Is-an-ID-Token-NOT-Suitable-For-) [places](https://auth0.com/docs/secure/tokens#id-tokens) that ID tokens should not be used to call APIs – and yet this is exactly what I am doing.

Any help appreciated.

---

<div class="post-metadata">

**Author:** ![josiah\_devizia](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/josiah_devizia/32/33352_2.png) [@josiah\_devizia](https://community.auth0.com/u/josiah_devizia)\
**Post date:** [July 20, 2022, 8:17pm UTC](https://community.auth0.com/t/using-idtoken-to-access-internal-api/87256/3 "2022-07-20T20:17:55Z")

</div>

1. On my development tenant, I made an application that uses the implicit grant type and I pull the token from the search bar. Do not do this in a production environment.
2. The token you should be using to call APIs is the access token. The access token tells the API what the user is allowed to do. The id token says who the user is.

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [July 21, 2022, 2:35am UTC](https://community.auth0.com/t/using-idtoken-to-access-internal-api/87256/4 "2022-07-21T02:35:59Z")

</div>

Hello there @tamlynfm welcome to the community! Thanks for the input @josiah_devizia 🙂

That’s correct, you shouldn’t be using an ID Token to make calls to an API - The ID Token represent Authentication and not Authorization.

> [@tamlynfm](#):
>
> - I don’t know how to generate an ID token for testing purposes, to allow me to call my backend during development with cURL or Postman.

Are you able to elaborate on your test case a bit? Is there a reason you are using the ID Token rather than the Access Token received in the login flow? Again, you should be using an Access Token here.

---

<div class="post-metadata">

**Author:** ![tamlynfm](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/tamlynfm/32/28224_2.png) [@tamlynfm](https://community.auth0.com/u/tamlynfm)\
**Post date:** [July 21, 2022, 8:16am UTC](https://community.auth0.com/t/using-idtoken-to-access-internal-api/87256/5 "2022-07-21T08:16:08Z")

</div>

Thanks for your replies. Please bear with me because I really want to understand why it is insecure to use the ID token:

- isn’t the fact that my frontend and backend communicate over HTTP an implementation detail? If my app was fully server-rendered – or fully client side – there would be no API.

- [this page](https://auth0.com/docs/secure/tokens) in the docs states (emphasis added):

- My application doesn’t require roles or scopes: every user has the same permissions, but only over their own data. Therefore authentication is all that is needed.

---

<div class="post-metadata">

**Author:** ![tamlynfm](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/tamlynfm/32/28224_2.png) [@tamlynfm](https://community.auth0.com/u/tamlynfm)\
**Post date:** [July 21, 2022, 5:14pm UTC](https://community.auth0.com/t/using-idtoken-to-access-internal-api/87256/6 "2022-07-21T17:14:51Z")

</div>

I’ve got it working now with an access token. For anyone else who comes here:

- You need to create a separate `Application` and `API` in Auth0.
- Then in your mobile app, you set it up with the client ID of the `Application` but also pass the `Identifier` (not `Id`) of the `API` as the `audience`. For the [react-native-auth0](https://github.com/auth0/react-native-auth0) package I couldn’t find this documented anywhere and I had to trawl through the source code to find the correct way to do it:

```auto
auth0.webAuth
    .authorize({
      scope: 'openid profile email',
      audience: '<API Identifier>',
    })

```

- Now the `accessToken` is an unencrypted JWT rather than the opaque JWE that you get by default. But it still doesn’t have any useful information in.
- In order to get user details in the access token you have to create a `Rule` in Auth0. [Rules](https://auth0.com/docs/customize/rules/examples) are bits of custom JavaScript that run in Auth0 and modify your tokens before issue.

I would still really like to understand _why_ it’s not OK to use the ID token for authentication in an API.

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [July 21, 2022, 11:18pm UTC](https://community.auth0.com/t/using-idtoken-to-access-internal-api/87256/7 "2022-07-21T23:18:08Z")

</div>

Awesome @tamlynfm happy to hear everything is functioning as expected, and thanks for following up with the community 😄

> [@tamlynfm](#):
>
> I would still really like to understand _why_ it’s not OK to use the ID token for authentication in an API.

I dug into this a bit deeper and technically the use of ID Token may be acceptable if the API actually represents the backend of your app that is not a logically separate service from the frontend. Otherwise, if the API is considered a separate entity from security point of view then an Access Token should be used. Regardless, Auth0 recommends using an Access Token against any sort of API across the board.

Cheers!

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [August 5, 2022, 11:18pm UTC](https://community.auth0.com/t/using-idtoken-to-access-internal-api/87256/8 "2022-08-05T23:18:32Z")

</div>

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