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.email = user.email;
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];
req.user.name = `${user.user_metadata.firstname} ${user.user_metadata.lastname}`;
return getProductIds(user.app_metadata.products);
})
.then((products) => {
req.user.products = products;
next();
})
.catch((err) => {
console.log('Authentication failed ', err);
res.status(401).send('Unauthorized');
});
};
When I run this locally using the AUTH_CLIENT_DOMAIN=tenant.signin-xxx.com 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 (https://dev.shared.use1.aws.xxx.cloud) 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,
requestInfo:
{ method: ‘post’,
url: ‘https://tenant.signin-xxx.com/oauth/token’ },
originalError:
{ 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