# How to get a users id token inside of the Post User Registration Auth0 Action

**URL:** <https://community.auth0.com/t/how-to-get-a-users-id-token-inside-of-the-post-user-registration-auth0-action/67338>\
**Category:** Get Help\
**Tags:** jwt\
**Created:** [August 3, 2021, 11:07pm UTC](https://community.auth0.com/t/how-to-get-a-users-id-token-inside-of-the-post-user-registration-auth0-action/67338 "2021-08-03T23:07:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![joshuarichards001](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/joshuarichards001/32/12921_2.png) [@joshuarichards001](https://community.auth0.com/u/joshuarichards001)\
**Post date:** [August 3, 2021, 11:07pm UTC](https://community.auth0.com/t/how-to-get-a-users-id-token-inside-of-the-post-user-registration-auth0-action/67338/1 "2021-08-03T23:07:23Z")

</div>

Hey, In my backend I am using the Auth0 auth middleware that checks that each request has a valid token in its header.

I want to create a Post User Registration Auth0 Action that adds the user to my database by calling my createUser API.

To do this I need to also pass that token from the Action.

How would I go about doing this?

Cheers

```auto
exports.onExecutePostUserRegistration = async (event) => {
  const token = ???;
  const url = "http://localhost:8080/api/user/createUser";
  const res = await axios.post(url, {
    params: {
      user: event.user,
    },
    headers: {
      Authorization: "Bearer " + token,
    },
  });
};

```

---

<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:** [August 4, 2021, 3:56pm UTC](https://community.auth0.com/t/how-to-get-a-users-id-token-inside-of-the-post-user-registration-auth0-action/67338/3 "2021-08-04T15:56:44Z")

</div>

Hi @joshuarichards001,

Welcome to the Auth0 Community!

You should not be using the ID token as an authorization bearer token. You should be using an **access token**.

To get a token, you need to set up your Action as an application in the Dashboard. In this case, your Action will act as a machine to machine (M2M) application that makes requests to your API.

Then you can request an access token for your API with a client credentials grant.

It is very similar to the process outlined [here](https://community.auth0.com/t/how-do-i-call-my-api-from-a-rule/41309).

---

<div class="post-metadata">

**Author:** ![joshuarichards001](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/joshuarichards001/32/12921_2.png) [@joshuarichards001](https://community.auth0.com/u/joshuarichards001)\
**Post date:** [August 5, 2021, 2:01am UTC](https://community.auth0.com/t/how-to-get-a-users-id-token-inside-of-the-post-user-registration-auth0-action/67338/4 "2021-08-05T02:01:39Z")

</div>

Cheers Dan, that ended up working I think.

Another quick question, is there any way to run actions locally? I would like the possibility to execute that API endpoint ‘[http://localhost:8080/api/user/createUser](http://localhost:8080/api/user/createUser)’ from the action.

---

<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:** [August 5, 2021, 4:34pm UTC](https://community.auth0.com/t/how-to-get-a-users-id-token-inside-of-the-post-user-registration-auth0-action/67338/5 "2021-08-05T16:34:43Z")

</div>

You can’t run an action from your local machine.

---

<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:** [August 20, 2021, 4:35pm UTC](https://community.auth0.com/t/how-to-get-a-users-id-token-inside-of-the-post-user-registration-auth0-action/67338/6 "2021-08-20T16:35:34Z")

</div>

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