M2M unauthorized error after deploy

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.

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

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

1 Like

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