# Access Management Api from React

**URL:** <https://community.auth0.com/t/access-management-api-from-react/71067>\
**Category:** Get Help\
**Created:** [October 10, 2021, 11:46am UTC](https://community.auth0.com/t/access-management-api-from-react/71067 "2021-10-10T11:46:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Insighting](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/insighting/32/12814_2.png) [@Insighting](https://community.auth0.com/u/Insighting)\
**Post date:** [October 10, 2021, 11:46am UTC](https://community.auth0.com/t/access-management-api-from-react/71067/1 "2021-10-10T11:46:40Z")

</div>

I understand that the userinfo endpoint is available from SPA applications with a user’s token, and the management API endpoints are not.  
Is there a way to create and access some user base metadata from SPA ? Also how Auth0 recognize that the request came from SPA ? Is there a way to pass it ?

---

<div class="post-metadata">

**Author:** ![Ale](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ale/32/50860_2.png) [@Ale](https://community.auth0.com/u/Ale)\
**Post date:** [October 11, 2021, 12:08am UTC](https://community.auth0.com/t/access-management-api-from-react/71067/2 "2021-10-11T00:08:17Z")

</div>

Hey @Insighting ,

**Warning** : Auth0 does not recommend putting Management API Tokens on the frontend that allow users to change user metadata. This can allow users to manipulate their own metadata in a way that could be detrimental to the functioning of the applications. It also allows a customer to do a DoS attack against someone’s management API by just spamming it and hitting rate limits.

Now and to answer your question, yes, you can hit Management API endpoints from a SPA application. However, since single-page applications (SPAs) are public clients and cannot securely store sensitive information (such as a **Client Secret** ), they must retrieve Management API Tokens from the frontend, unlike other [application types](https://auth0.com/docs/configure/applications). This means that Management API Tokens for SPAs have certain limitations. Specifically, they are issued in the context of the user who is currently signed in to Auth0 which limits updates to only the logged-in user’s data. Although this restricts the use of the Management API, it can still be used to perform actions related to updating the logged-in user’s user profile.

With a Management API Token issued for a SPA, you can access the following scopes (and hence endpoints):

| **Scope for Current User** | **Endpoint** |
| --- | --- |
| `read:current_user` | [GET /api/v2/users/{id}](https://auth0.com/docs/api/management/v2#!/Users/get_users_by_id) and [GET /api/v2/users/{id}/enrollments](https://auth0.com/docs/api/management/v2#!/Users/get_enrollments) |
| `update:current_user_identities` | [POST/api/v2/users/{id}/identities](https://auth0.com/docs/api/management/v2#!/Users/post_identities) and [DELETE /api/v2/users/{id}/identities/{provider}/{user\_id}](https://auth0.com/docs/api/management/v2#!/Users/delete_user_identity_by_user_id) |
| `update:current_user_metadata` | [PATCH /api/v2/users/{id}](https://auth0.com/docs/api/management/v2#!/Users/patch_users_by_id) |
| `create:current_user_metadata` | [PATCH /api/v2/users/{id}](https://auth0.com/docs/api/management/v2#!/Users/patch_users_by_id) |
| `delete:current_user_metadata` | [DELETE /api/v2/users/{id}/multifactor/{provider}](https://auth0.com/docs/api/management/v2#!/Users/delete_multifactor_by_provider) |
| `create:current_user_device_credentials` | [POST /api/v2/device-credentials](https://auth0.com/docs/api/management/v2#!/Device_Credentials/post_device_credentials) |
| `delete:current_user_device_credentials` | [DELETE /api/v2/device-credentials/{id}](https://auth0.com/docs/api/management/v2#!/Device_Credentials/delete_device_credentials_by_id) |

Source: [Get Management API Access Tokens for Single-Page Applications](https://auth0.com/docs/security/tokens/access-tokens/get-management-api-tokens-for-single-page-applications)

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [October 11, 2021, 7:52am UTC](https://community.auth0.com/t/access-management-api-from-react/71067/3 "2021-10-11T07:52:31Z")

</div>

Thanks for helping on this one @Ale !

---

<div class="post-metadata">

**Author:** ![Insighting](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/insighting/32/12814_2.png) [@Insighting](https://community.auth0.com/u/Insighting)\
**Post date:** [October 13, 2021, 7:29am UTC](https://community.auth0.com/t/access-management-api-from-react/71067/4 "2021-10-13T07:29:15Z")

</div>

Thank you Ale !

I still get 403 error every time I am trying to reach the api/v2/…

```auto
const accessToken = await getAccessTokenSilently({
          audience: `https://${domain}/api/v2/`,
          // scope: "read:current_user",
        });

        const userDetailsByIdUrl = `https://${domain}/userinfo`;

        axios
          .get(userDetailsByIdUrl, {
            headers: {
              Authorization: `Bearer ${accessToken}`,
            },
          })
          .then((response) => {
            console.log(response.data);
          })
          .catch((error) => {
            console.log("ERROR API RESPONSE => ", error);
          });
      } catch (e) {
        console.log(e.message);
      }
    };

```

This will work but will retrieve the same user object I get from useAuth.

If I am trying to fetch something like these:

```auto
GET /api/v2/users/{id} 
GET /api/v2/users/

```

I will get an error

---

<div class="post-metadata">

**Author:** ![Ale](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ale/32/50860_2.png) [@Ale](https://community.auth0.com/u/Ale)\
**Post date:** [October 13, 2021, 2:59pm UTC](https://community.auth0.com/t/access-management-api-from-react/71067/5 "2021-10-13T14:59:39Z")

</div>

So, you mentioned you are calling a couple of endpoints:

> GET /api/v2/users/

No, this will **not** work. If you take a look at the table I included in my previous response and which is documented on [Get Management API Access Tokens for Single-Page Applications](https://auth0.com/docs/security/tokens/access-tokens/get-management-api-tokens-for-single-page-applications), you cannot call `GET /api/v2/users/` with an Access Token that was issued from a SPA. It is not included in the table. Please note that `GET /api/v2/users/` is not the same as `GET /api/v2/users/{id}`.

> GET /api/v2/users/{id}

Now, this one should work as long as the ID parameter is the one of the current user. i.e. you can only retrieve information about yourself. This is why you need the `read:current_user` scope for this endpoint as documented in the table and the documentation above. If you are actually trying to access the current user’s data but are receiving a 403 error, then the reason will probably be that the Access Token does not contain the needed scopes, such as `read:current_user`.

All this means you cannot access information about other users when you are using an Access Token issued from a SPA. You can only access data about the current user.

You can’t request a full-scoped Access Token for the Management API from a SPA because SPAs are considered [Public Applications](https://auth0.com/docs/applications/concepts/app-types-confidential-public#public-applications). If you want to access any other user’s data (different from the current user), you cannot request the Access Token from your SPA. You must do it from a backend system of your choice instead: [Get Management API Access Tokens for Production](https://auth0.com/docs/security/tokens/access-tokens/get-management-api-access-tokens-for-production) such as an M2M application.

How to implement the above and still use your SPA? Well, don’t pass the Management API Access Token to the SPA because as mentioned, your SPA is a public application. Instead:

1. Proxy the Management API request from the SPA through your backend/API.
2. Your backend then communicates via M2M / Client Credentials Exchange with the Auth0 Management API.
3. Your SPA communicates via your backend so you might need to create the required endpoint on your backend, take the query, and make the query call to the Auth0 Management API. Then, your backend passes on the response to your SPA.

I hope all this makes more sense now.

---

<div class="post-metadata">

**Author:** ![Insighting](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/insighting/32/12814_2.png) [@Insighting](https://community.auth0.com/u/Insighting)\
**Post date:** [October 18, 2021, 10:52am UTC](https://community.auth0.com/t/access-management-api-from-react/71067/6 "2021-10-18T10:52:31Z")

</div>

Thank you so much for the well-explained comment Ale. It is much clearer now and I will contact support if I face any other issue implementing that.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [October 18, 2021, 12:14pm UTC](https://community.auth0.com/t/access-management-api-from-react/71067/7 "2021-10-18T12:14:19Z")

</div>

We are here for you!

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [October 28, 2021, 1:00pm UTC](https://community.auth0.com/t/access-management-api-from-react/71067/8 "2021-10-28T13:00:47Z")

</div>


