# How can I automate the recovery of a user id token for automated tests?

**URL:** <https://community.auth0.com/t/how-can-i-automate-the-recovery-of-a-user-id-token-for-automated-tests/61161>\
**Category:** JWT.io\
**Tags:** test, login\
**Created:** [April 15, 2021, 1:51pm UTC](https://community.auth0.com/t/how-can-i-automate-the-recovery-of-a-user-id-token-for-automated-tests/61161 "2021-04-15T13:51:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![theod](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@theod](https://community.auth0.com/u/theod)\
**Post date:** [April 15, 2021, 1:51pm UTC](https://community.auth0.com/t/how-can-i-automate-the-recovery-of-a-user-id-token-for-automated-tests/61161/1 "2021-04-15T13:51:58Z")

</div>

Hello,

I am working on a project on which I authenticate my users on a front-end (authorization code with PKCE) . Then, I am sending to my back-end the id token in order to check the authentication and return some informations (if the authentication is successful).

In order to do automated tests (integrated on my CI), I would like to know if there is an method to fetch an id token from a test user.

I tried a first approach by :

- creating a auth0 tenant specific for test purposes
- creating one user
- fetch token with the endpoint oauth/token with the password authorization flow.  
Nevertheless the endpoint doesn’t look to be able to return an id token, only access token. (according to the [API documentation](https://auth0.com/docs/api/authentication#resource-owner-password))

Can you recommend a way to fetch automatically an id token and then test my API routes ?

I thank you a lot in advance,

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [April 15, 2021, 10:46pm UTC](https://community.auth0.com/t/how-can-i-automate-the-recovery-of-a-user-id-token-for-automated-tests/61161/3 "2021-04-15T22:46:19Z")

</div>

Hi @theod,

Welcome to the Community!

Did you try passing an `openid` scope with your request?

---

<div class="post-metadata">

**Author:** ![theod](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@theod](https://community.auth0.com/u/theod)\
**Post date:** [April 16, 2021, 8:11am UTC](https://community.auth0.com/t/how-can-i-automate-the-recovery-of-a-user-id-token-for-automated-tests/61161/4 "2021-04-16T08:11:00Z")

</div>

Hello @dan.woda ,  
Thanks a lot for the quick reply. Actually I tried to pass an openid scope in my request but only a access\_token is returned.

Here is the model of my request :

```auto
curl --request POST \
  --url 'https://YOUR_DOMAIN/oauth/token' \
  --header 'content-type: application/x-www-form-urlencoded' \
  --data 'grant_type=password&username=USERNAME&password=PASSWORD&audience=API_IDENTIFIER&scope=openid&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET"
 }'

```

and the response looks like :

```auto
{
   "access_token": "...",
   "scope":"openid profile email address phone read:current_user update:current_user_metadata delete:current_user_metadata create:current_user_metadata create:current_user_device_credentials delete:current_user_device_credentials update:current_user_identities","expires_in":2592000,"token_type":"Bearer"
}

```

This is in fact the behavior described in the section concerning this endpoint in the [API documentation](https://auth0.com/docs/api/authentication#resource-owner-password).

Is there something i am not doing correctly ?

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [April 16, 2021, 4:55pm UTC](https://community.auth0.com/t/how-can-i-automate-the-recovery-of-a-user-id-token-for-automated-tests/61161/5 "2021-04-16T16:55:04Z")

</div>

I just tested it and get can an ID token.

Here is my request export from postman, also tested in my terminal:

```auto
curl --location --request POST 'https://xxx.auth0.com/oauth/token' \
     --header 'Content-Type: application/x-www-form-urlencoded' \
     --data-urlencode 'grant_type=password' \
     --data-urlencode 'client_id=xxx' \
     --data-urlencode 'client_secret=xxx' \
     --data-urlencode 'username=xxx' \
     --data-urlencode 'password=xxx' \
     --data-urlencode 'scope=openid'

```

---

<div class="post-metadata">

**Author:** ![theod](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@theod](https://community.auth0.com/u/theod)\
**Post date:** [April 16, 2021, 5:30pm UTC](https://community.auth0.com/t/how-can-i-automate-the-recovery-of-a-user-id-token-for-automated-tests/61161/6 "2021-04-16T17:30:11Z")

</div>

You are right my mistake was to add an audience parameter.

Thank you so much for your support!

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [April 16, 2021, 6:44pm UTC](https://community.auth0.com/t/how-can-i-automate-the-recovery-of-a-user-id-token-for-automated-tests/61161/7 "2021-04-16T18:44:08Z")

</div>

Let us know if you have other questions.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [May 1, 2021, 6:45pm UTC](https://community.auth0.com/t/how-can-i-automate-the-recovery-of-a-user-id-token-for-automated-tests/61161/8 "2021-05-01T18:45:06Z")

</div>

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