This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function(client, scope, audience, context, cb) { | |
const _ = require('lodash'); | |
let access_token = {}; | |
let requested_scopes = context.body.scope; | |
let jwt = require('jsonwebtoken'); | |
requested_scopes = (requested_scopes && requested_scopes.split(" ")) || []; | |
access_token.scope = _.intersection(requested_scopes, scope); | |
if (!context.body.identifier_token) { | |
return cb('No user identifier'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function performMfa(user, context, callback) { | |
let jwt = require('jsonwebtoken'); | |
let mfaEnrollmentStatus = user.app_metadata.MFAEnrolledStatus || ''; | |
//if(context.connection !== 'your connection name') return callback(null, user, context); | |
// run only for the specified clients | |
/* let CLIENTS_WITH_MFA = context.clientMetadata.clientid; | |
if (CLIENTS_WITH_MFA.indexOf(context.clientID) === -1) { | |
return callback(null, user, context); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function getTokenFromRulesConfig(user, context, callback) { | |
const m2mClientID = configuration.m2mCID; | |
const m2mClientSecret = configuration.m2mCSecret; | |
let auth0Domain = '<<your_tenant>>.auth0.com'; | |
const moment = require('moment-timezone'); | |
let axios = require('axios'); | |
const country = context.request.geoip.country_name; | |
const data = { | |
user_app_metadata: user.app_metadata, | |
email: user.email, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function(user, context, callback) { | |
// Modules | |
const request = require('request'); | |
// Options | |
const requestTokenOptions = { | |
method: 'POST', | |
uri: 'https://' + auth0.domain + '/oauth/token', | |
headers: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function(user, context, callback) { | |
let timeLimitMs = 1000; | |
let currentDate = new Date(); | |
let currentTimeMs = currentDate.getTime(); | |
let last_auth_time = new Date(context.authentication.methods.find((method) => method.name === 'pwd').timestamp); | |
let lastAuthTimeMs = last_auth_time.getTime(); | |
const isSilentAuth = currentTimeMs - lastAuthTimeMs > timeLimitMs ? true : false; | |
console.log("current time", currentTimeMs); | |
console.log("lastAuthTime", lastAuthTimeMs); |