Using a Post-login action, I’m trying convert user permissions into a scopes
field in the access token.
exports.onExecutePostLogin = async (event, api) => {
const ManagementClient = require('auth0').ManagementClient;
const management = new ManagementClient({
domain: event.secrets.domain,
clientId: event.secrets.clientId,
clientSecret: event.secrets.clientSecret
});
var params = {id: event.user.user_id};
try {
const { data: permissions } = await management.users.getPermissions(params);
console.log(`Permissions for user ${event.user.user_id} = ${JSON.stringify(permissions)}`);
permissions.forEach(function (obj) {
console.log(`Adding ${obj.permission_name} to accessToken scope`);
api.accessToken.addScope(obj.permission_name);
});
} catch (err) {
console.log(`Error getting permissions for user ${event.user.user_id}: ${err}`);
}
}
When the action executes the call to managment.users.getPermissions
errors out with
FetchError: The request failed and the interceptors did not return an alternative response\n
I can’t find any other helpful information. Anyone have ideas on what I might be doing wrong? Or perhaps point me in a direction that will provide additional information on what exactly is failing?
Thanks,
Mark