# As a backend developer I want to obtain a JWT automatically by providing my username and password

**URL:** <https://community.auth0.com/t/as-a-backend-developer-i-want-to-obtain-a-jwt-automatically-by-providing-my-username-and-password/124931>\
**Category:** Get Help\
**Tags:** users, management-api\
**Created:** [January 16, 2024, 7:49pm UTC](https://community.auth0.com/t/as-a-backend-developer-i-want-to-obtain-a-jwt-automatically-by-providing-my-username-and-password/124931 "2024-01-16T19:49:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![creyD](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/creyd/32/50891_2.png) [@creyD](https://community.auth0.com/u/creyD)\
**Post date:** [January 16, 2024, 7:49pm UTC](https://community.auth0.com/t/as-a-backend-developer-i-want-to-obtain-a-jwt-automatically-by-providing-my-username-and-password/124931/1 "2024-01-16T19:49:59Z")

</div>

In our company we use Auth0 for authentication of the frontend and backend. The backend normally just gets a JWT from the frontend to operate. A couple of calls need an access token for the API by the backend but this is obtained automatically, so that we can update the user for example. Now as a backend developer, it is really complicated to obtain a JWT for testing. You either need to use the generic one from the Auth0 dashboard (which fails on all of the management API calls) or you need to get the token manually i.e. by logging into the frontend and then having the JWT displayed there. How can we do this more efficiently? I was thinking of setting env variables for the backend devs, where they provide username and password and get a JWT for testing when they start the server, this doesn’t work however.

---

<div class="post-metadata">

**Author:** ![mraible](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mraible/32/32776_2.png) [@mraible](https://community.auth0.com/u/mraible)\
**Post date:** [January 16, 2024, 10:11pm UTC](https://community.auth0.com/t/as-a-backend-developer-i-want-to-obtain-a-jwt-automatically-by-providing-my-username-and-password/124931/2 "2024-01-16T22:11:46Z")

</div>

You can use the [Auth0 CLI](https://github.com/auth0/auth0-cli) to generate access tokens:

```auto
auth0 test token -a https://<your-auth0-domain>/api/v2/ -s openid

```

---

<div class="post-metadata">

**Author:** ![creyD](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/creyd/32/50891_2.png) [@creyD](https://community.auth0.com/u/creyD)\
**Post date:** [January 17, 2024, 10:04am UTC](https://community.auth0.com/t/as-a-backend-developer-i-want-to-obtain-a-jwt-automatically-by-providing-my-username-and-password/124931/3 "2024-01-17T10:04:38Z")

</div>

Thanks for the response! However this doesn’t solve my problem. This only gives me the same generic token that I can access via the auth0 dashboard. The authentication works fine with that, but as soon as I want to update the user\_metadata via the management API it says `Object didn't pass validation for format user-id: XXX@clients` because it seems this is a generic token. I need exactly this token, but for a specific user.

Note: I had to change the audience to my actual API audience, otherwise it would say Audience doesn’t match.

---

<div class="post-metadata">

**Author:** ![mraible](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mraible/32/32776_2.png) [@mraible](https://community.auth0.com/u/mraible)\
**Post date:** [January 17, 2024, 10:30am UTC](https://community.auth0.com/t/as-a-backend-developer-i-want-to-obtain-a-jwt-automatically-by-providing-my-username-and-password/124931/4 "2024-01-17T10:30:43Z")

</div>

I think this happens when you authenticate as a machine, but I could be wrong. Did you try authenticating as a user?

---

<div class="post-metadata">

**Author:** ![creyD](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/creyd/32/50891_2.png) [@creyD](https://community.auth0.com/u/creyD)\
**Post date:** [January 17, 2024, 10:36am UTC](https://community.auth0.com/t/as-a-backend-developer-i-want-to-obtain-a-jwt-automatically-by-providing-my-username-and-password/124931/5 "2024-01-17T10:36:20Z")

</div>

No it seems that you are absolutely correct. I used the machine-to-machine application that was supplied by auth0, but I should have used the frontend application with the command you provided. Thanks a lot!

---

<div class="post-metadata">

**Author:** ![creyD](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/creyd/32/50891_2.png) [@creyD](https://community.auth0.com/u/creyD)\
**Post date:** [January 17, 2024, 10:38am UTC](https://community.auth0.com/t/as-a-backend-developer-i-want-to-obtain-a-jwt-automatically-by-providing-my-username-and-password/124931/6 "2024-01-17T10:38:57Z")

</div>

Is there a way to achieve this via the HTTP API and not the command? I would like to improve the developer experience, so that not every backend developer has to call this command all the time, but that we can generate the access in the background and automatically apply the token for the user account. I imagine that they would set a user and password env variable and then we automatically generate a token every time they need one.

---

<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:** [January 31, 2024, 10:39am UTC](https://community.auth0.com/t/as-a-backend-developer-i-want-to-obtain-a-jwt-automatically-by-providing-my-username-and-password/124931/7 "2024-01-31T10:39:29Z")

</div>

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