Skip to content

Instantly share code, notes, and snippets.

@saltukalakus
Created March 14, 2018 16:07
Show Gist options
  • Save saltukalakus/74026b039db34f97c06642e8a6f50048 to your computer and use it in GitHub Desktop.
Save saltukalakus/74026b039db34f97c06642e8a6f50048 to your computer and use it in GitHub Desktop.
function (user, context, callback) {
var deviceFingerPrint = getDeviceFingerPrint();
user.app_metadata = user.app_metadata || {};
if (user.app_metadata.lastLoginDeviceFingerPrint !== deviceFingerPrint) {
user.app_metadata.lastLoginDeviceFingerPrint = deviceFingerPrint;
context.multifactor = {
allowRememberBrowser: false,
provider: 'guardian'
};
auth0.users.updateAppMetadata(user.user_id, user.app_metadata)
.then( function() {
callback(null, user, context);
})
.catch( function(err) {
callback(err);
});
} else {
callback(null, user, context);
}
function getDeviceFingerPrint() {
var shasum = crypto.createHash('sha1');
shasum.update(context.request.userAgent);
shasum.update(context.request.ip);
return shasum.digest('hex');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment