Nodejs auth0 ManagementClient.getUser() 401 unauthorized

SDK: nodejs auth0
SDK Version: 2.8.0
Platform Version: Node js 6.11.5

I’m trying to use the ManagmentClient.getUser function with a Machine to Machine application. The function works locally but not in my dev environment. Both local and dev use the exact same code and credentials

const auth0 = new ManagementClient({
    domain: config.AUTH_CLIENT_DOMAIN,
    clientId: config.AUTH_CLIENT_ID,
    clientSecret: config.AUTH_CLIENT_SECRET,
    scope: 'read:users update:users',
const authUser = function authUser(req, res, next) {
    auth0.getUser({ id: req.user.sub })
        .then((user) => {
            req.user.isAdmin = user.app_metadata.type.toLowerCase() === 'admin';
            req.user.isVendor = user.app_metadata.type.toLowerCase() === 'vendor';
            req.user.tenants = _.orderBy(user.app_metadata.tenantId);
            req.user.tenantId = req.user.tenants[req.query.tenant_index || 0];
   = `${user.user_metadata.firstname} ${user.user_metadata.lastname}`;
            return getProductIds(user.app_metadata.products);
        .then((products) => {
            req.user.products = products;
        .catch((err) => {
            console.log('Authentication failed ', err);

When I run this locally using the and the clientId and clientSecret from the above application the call to auth0.getUser() works.

When I run it from my dev environment I get a 401. I added the domain of my dev environment ( to Allowed Web Origins but this didn’t help. Here is part of the stack trace

name: ‘access_denied’,
message: ‘{“error”:“access_denied”,“error_description”:“Unauthorized”}’,
statusCode: 401,
{ method: ‘post’,
url: ‘’ },
{ Error: Unauthorized
at Request.callback (/usr/src/app/node_modules/superagent/lib/node/index.js:883:15)
at /usr/src/app/node_modules/superagent/lib/node/index.js:1126:20
at IncomingMessage. (/usr/src/app/node_modules/superagent/lib/node/parsers/json.js:22:7)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickDomainCallback (internal/process/next_tick.js:128:9)
status: 401,

Any help would be much appreciated