# M2M unauthorized error after deploy

**URL:** <https://community.auth0.com/t/m2m-unauthorized-error-after-deploy/58319>\
**Category:** Get Help\
**Tags:** m2m, management-api, auth0\
**Created:** [February 22, 2021, 10:32pm UTC](https://community.auth0.com/t/m2m-unauthorized-error-after-deploy/58319 "2021-02-22T22:32:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![luis.perezsanchez](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/luis.perezsanchez/32/27775_2.png) [@luis.perezsanchez](https://community.auth0.com/u/luis.perezsanchez)\
**Post date:** [February 22, 2021, 10:32pm UTC](https://community.auth0.com/t/m2m-unauthorized-error-after-deploy/58319/1 "2021-02-22T22:32:37Z")

</div>

Hello,  
I’m using M2M api from a Backend application to change user profile. This a snippet of the code I’m using:

```
   const authClient = new AuthenticationClient({
        domain: MY_DOMAIN,
        clientId: "My M2M Client ID",
        clientSecret: "My M2M Client Secret",
    });
    const token = await UserService.getAuth0AuthenticationClient().clientCredentialsGrant({
        audience: `https://${MY_DOMAIN}/api/v2/`,
    });
    const managementClient = new ManagementClient({
        domain: MY_DOMAIN,
        token: token.access_token,
    });
    await managementClient.updateUser({ id: userId }, { name: data.name });

```

When I tried this code from localhost all worked perfectly, however when I deployed this code, it does not work, given a 401 as soon as I ask for the clientCredentialGrant.

In theory the M2M application is configured to access the Management API, and the configuration it seems to work at least from localhost.

Has anybody has any idea of what is happening.

Thanks.

---

<div class="post-metadata">

**Author:** ![luis.perezsanchez](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/luis.perezsanchez/32/27775_2.png) [@luis.perezsanchez](https://community.auth0.com/u/luis.perezsanchez)\
**Post date:** [February 23, 2021, 9:40am UTC](https://community.auth0.com/t/m2m-unauthorized-error-after-deploy/58319/2 "2021-02-23T09:40:59Z")

</div>

Maybe I’m missing some configuration of the Application, that influences the gcloud deployment differently from my localhost.

But I still can’t find out what, so any help is welcomed.

Thanks

---

<div class="post-metadata">

**Author:** ![luis.perezsanchez](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/luis.perezsanchez/32/27775_2.png) [@luis.perezsanchez](https://community.auth0.com/u/luis.perezsanchez)\
**Post date:** [February 23, 2021, 12:52pm UTC](https://community.auth0.com/t/m2m-unauthorized-error-after-deploy/58319/3 "2021-02-23T12:52:08Z")

</div>

At the end it was a configuration error (that added \n to the secret)

---

<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:** [February 23, 2021, 1:55pm UTC](https://community.auth0.com/t/m2m-unauthorized-error-after-deploy/58319/4 "2021-02-23T13:55:00Z")

</div>

Glad you were able to figure this out and thanks for sharing with the rest of community!

---

<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:** [February 25, 2021, 10:32am UTC](https://community.auth0.com/t/m2m-unauthorized-error-after-deploy/58319/5 "2021-02-25T10:32:51Z")

</div>


