Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Auth0 rule to run an email reputation check via emailrep.io
function (user, context, callback) {
// skip if emailrep.io metadata is already there
if (user.app_metadata && user.app_metadata.emailrep) {
context.idToken['https://emailrep.io/reputation'] = user.app_metadata.emailrep.reputation;
context.idToken['https://emailrep.io/suspicious'] = user.app_metadata.emailrep.suspicious;
context.accessToken['https://emailrep.io/reputation'] = user.app_metadata.emailrep.reputation;
context.accessToken['https://emailrep.io/suspicious'] = user.app_metadata.emailrep.suspicious;
return callback(null, user, context);
}
request.get('https://emailrep.io/' + user.email, {
json: true
}, (error, response, body) => {
if (error || (response && response.statusCode !== 200)) {
// swallow emailrep.io api errors and just continue login
return callback(null, user, context);
}
// if we reach here, it means EmailRep returned info and we'll add it to the metadata
user.app_metadata = user.app_metadata || {};
user.app_metadata.emailrep = body;
auth0.users.updateAppMetadata(user.user_id, user.app_metadata);
context.idToken['https://emailrep.io/reputation'] = user.app_metadata.emailrep.reputation;
context.idToken['https://emailrep.io/suspicious'] = user.app_metadata.emailrep.suspicious;
context.accessToken['https://emailrep.io/reputation'] = user.app_metadata.emailrep.reputation;
context.accessToken['https://emailrep.io/suspicious'] = user.app_metadata.emailrep.suspicious;
return callback(null, user, context);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.