# Management API not working from SPA

**URL:** <https://community.auth0.com/t/management-api-not-working-from-spa/69857>\
**Category:** Get Help\
**Tags:** auth0\
**Created:** [September 17, 2021, 2:08pm UTC](https://community.auth0.com/t/management-api-not-working-from-spa/69857 "2021-09-17T14:08:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mjanowski](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mjanowski/32/12764_2.png) [@mjanowski](https://community.auth0.com/u/mjanowski)\
**Post date:** [September 17, 2021, 2:08pm UTC](https://community.auth0.com/t/management-api-not-working-from-spa/69857/1 "2021-09-17T14:08:55Z")

</div>

I’m trying to update user information in a Vue app to enable the user to edit their profile.  
After getting a token with the correct audience and scopes I still get a 400 _Bad HTTP authentication header format_ error.

```auto
       var auth0Authentication = new auth0.Authentication({
          domain: options.domain,
          clientID: options.clientId,
        })

        return auth0Authentication.login({
          realm: 'Username-Password-Authentication',
          username: username,
          password: password,
          audience: 'https://' + options.domain + '/api/v2/',
        }, async (err, authResult) => {
          if (err) {
            this.error = err
            this.loading = false
            cb(err)
          } else {
            console.log('authResult', authResult)

            var decodedAccessToken = jwtDecode(authResult.accessToken)
            console.log('decodedAccessToken', decodedAccessToken)

            var auth0Management = new auth0.Management({
              domain: options.domain,
              token: decodedAccessToken.azp,
            })

            auth0Management.getUser(decodedAccessToken.sub, (err, user) => {
              console.log('err', err) // This is where I get an error
              console.log('user', user)
            })

            cb(true)
          }
        })

```

---

<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:** [September 17, 2021, 7:10pm UTC](https://community.auth0.com/t/management-api-not-working-from-spa/69857/3 "2021-09-17T19:10:52Z")

</div>

Hi @mjanowski,

Welcome to the Auth0 Community!

It looks like he might be running into a couple of issues here.

- [SPAs are limited in what scopes they can request for management API tokens.](https://auth0.com/docs/security/tokens/access-tokens/get-management-api-tokens-for-single-page-applications)
- you are only passing the `decodedAccessToken.azp` claim to the management API client, when you should be passing the original Access Token i.e. `authResult.accessToken`

---

<div class="post-metadata">

**Author:** ![mjanowski](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mjanowski/32/12764_2.png) [@mjanowski](https://community.auth0.com/u/mjanowski)\
**Post date:** [September 17, 2021, 7:31pm UTC](https://community.auth0.com/t/management-api-not-working-from-spa/69857/4 "2021-09-17T19:31:37Z")

</div>

Hi @dan.woda,

I think I did try using `authResult.accessToken` first but the `idToken` was missing from the response which led me to start trying other things.

I have since added these scopes: `scope: 'openid profile email address phone read:current_user update:current_user_metadata'` and now I get both the `idToken` and `accessToken` with the right permissions so it’s working!

One thing I would like, which seems to not be possible currently is to be able to update user fields like `name`, `given_name` and `family_name` using `patchUserAttributes()`. I’ve got around that by setting metadata and using a rule to populate those fields but that is not an ideal solution.

---

<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:** [September 17, 2021, 7:50pm UTC](https://community.auth0.com/t/management-api-not-working-from-spa/69857/5 "2021-09-17T19:50:07Z")

</div>

You are not able to update those attributes from a SPA. This is because a token with those permissions, on the client, could be grabbed by the user and used to update those attributes without you (the admin) knowing.

You must make requests to update the user’s core attributes from a secure client like a backend or API.

---

<div class="post-metadata">

**Author:** ![mjanowski](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mjanowski/32/12764_2.png) [@mjanowski](https://community.auth0.com/u/mjanowski)\
**Post date:** [September 18, 2021, 8:25am UTC](https://community.auth0.com/t/management-api-not-working-from-spa/69857/6 "2021-09-18T08:25:05Z")

</div>

But for some apps it makes sense for users to be able to update their own information. In my case I want the users to be able to edit their profile (names etc.) and I don’t want to have to build a backend for that.

---

<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:** [September 20, 2021, 3:19pm UTC](https://community.auth0.com/t/management-api-not-working-from-spa/69857/7 "2021-09-20T15:19:34Z")

</div>

Thanks for the added context. Currently, you will need to make that request from a secure backend.

---

<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:** [December 23, 2021, 4:59pm UTC](https://community.auth0.com/t/management-api-not-working-from-spa/69857/8 "2021-12-23T16:59:05Z")

</div>

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