module.exports = function (user, context, cb) { const ManagementClient = require("auth0@2.23.0").ManagementClient; const auth0 = new ManagementClient({ domain: context.connection.tenant + '.eu.auth0.com', clientId: context.webtask.secrets.delete_refresh_token_client_id, clientSecret: context.webtask.secrets.delete_refresh_token_client_secret, scope: 'read:device_credentials delete:device_credentials' }); const getRefreshTokens = type => auth0.deviceCredentials.getAll({ user_id: user.id, type: type }); const deleteRefreshToken = id => auth0.deviceCredentials.delete({ id: id }) .then(() => console.log("Deleted " + id)); const deleteAllRefreshTokensOfType = type => Promise.resolve() .then(() => console.log(">>> Deleting " + type)) .then(() => getRefreshTokens(type)) .then(tokens => { console.log("Got tokens: " + tokens.length); return tokens; }) .then(tokens => tokens.map(x => deleteRefreshToken(x.id))) .then(deletePromises => Promise.all(deletePromises)) .then(() => console.log("done")); Promise.resolve() .then(() => deleteAllRefreshTokensOfType("refresh_token")) .then(() => deleteAllRefreshTokensOfType("rotating_refresh_token")) .catch(e => console.log(e)) .then(() => cb()); };