# Calling management API to update user meta data from SPA

**URL:** <https://community.auth0.com/t/calling-management-api-to-update-user-meta-data-from-spa/64600>\
**Category:** Get Help\
**Tags:** user\_metadata\
**Created:** [June 16, 2021, 3:43pm UTC](https://community.auth0.com/t/calling-management-api-to-update-user-meta-data-from-spa/64600 "2021-06-16T15:43:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![swardi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/swardi/32/24965_2.png) [@swardi](https://community.auth0.com/u/swardi)\
**Post date:** [June 16, 2021, 3:43pm UTC](https://community.auth0.com/t/calling-management-api-to-update-user-meta-data-from-spa/64600/1 "2021-06-16T15:43:07Z")

</div>

I have a specific use case in which our application wants to update user’s meta data from browser based SPA. I know management API can be used to update user meta data, but we cannot involve server in our case and want this update to be made via client side application. Is there a way to securely allow client side application to use management API for this?

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [June 16, 2021, 5:51pm UTC](https://community.auth0.com/t/calling-management-api-to-update-user-meta-data-from-spa/64600/3 "2021-06-16T17:51:29Z")

</div>

Hi @swardi,

Welcome to the Community!

It is possible to use the Management API in a SPA for a limited number of things. You will have to use your tenant’s Management API identifier ( **Auth0 dashboard \> Applications \> APIs** ) as the `audience` in your app, and you will need to request the `update:current_user_metadata` scope. For example, in react this would look like:

```auto
ReactDOM.render(
  <Auth0Provider
    domain={config.domain}
    clientId={config.clientId}
    redirectUri={window.location.origin}
    audience='https://YOUR_DOMAIN/api/v2'
    scope='update:current_user_metadata'
    onRedirectCallback={onRedirectCallback}
  >
    <App />
  </Auth0Provider>,
  document.getElementById("root")
);

```

Here are the docs for interacting with the Management API from a SPA:

> **[Get Management API Access Tokens for Single-Page Applications](https://auth0.com/docs/secure/tokens/access-tokens/get-management-api-tokens-for-single-page-applications)**
>
> Learn about available scopes and endpoints for Management API tokens for Single-page Applications (SPAs).

Note the 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.

---

<div class="post-metadata">

**Author:** ![swardi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/swardi/32/24965_2.png) [@swardi](https://community.auth0.com/u/swardi)\
**Post date:** [June 17, 2021, 9:40am UTC](https://community.auth0.com/t/calling-management-api-to-update-user-meta-data-from-spa/64600/4 "2021-06-17T09:40:17Z")

</div>

Thanks for sharing, I tried this and it works well with my passwordless flow too. But I found the security hole to be too big and we cannot use it. The meta data we are going to update is our own internal id which will be add in the JWT Token and will be used to identify user on our backend. Now can you please suggest me the best approach which is secure as well.

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [June 17, 2021, 11:20am UTC](https://community.auth0.com/t/calling-management-api-to-update-user-meta-data-from-spa/64600/5 "2021-06-17T11:20:20Z")

</div>

Glad to hear it is working for you!

An alternative approach would be to handle the calls to the Management API in your backend. You would [register your API](https://auth0.com/docs/get-started/set-up-apis) as a custom API and use its identifier as the `audience` in the SPA. You would then create a Machine-to-Machine application for your backend and authorize it to use the Management API. Your backend could use one of the [Auth0 SDKs](https://auth0.com/docs/quickstart/backend) to validate the Access Token and return data from the Management API for the SPA. That way any Access Tokens for the Management API are not exposed on the frontend. (M2M tokens from Auth0 APIs such as the Management API do not count toward the M2M token limit outlined on the pricing page).

> **[Create Machine-to-Machine Applications for Testing](https://auth0.com/docs/get-started/apis/create-m2m-app-test)**
>
> Learn how to register and authorize a test machine-to-machine application for calling Management API endpoints using Access Tokens.

---

<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:** [July 2, 2021, 11:21am UTC](https://community.auth0.com/t/calling-management-api-to-update-user-meta-data-from-spa/64600/6 "2021-07-02T11:21:00Z")

</div>

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