Skip to main content

Documentation Index

Fetch the complete documentation index at: https://auth0-fix-docs-5525.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

With Actions, you can handle more complicated cases than is possible with passwordless connections alone. For instance, you can add extra precautions to further ensure possession of an email address or device.

Require Multi-factor Authentication for users who are outside the corporate network

Let’s say you want to require multi-factor authentication (MFA) for any users who are accessing the application using a connection from outside your corporate network. Using an Action, you can check whether a user is authenticating using a passwordless method (sms, email) and if their session IP falls outside of the designated corporate network, prompt them for a second authentication factor.
You could also trigger this Action based on other criteria, such as whether the current IP matches the user’s IP allowlist or whether geolocating the user reveals they are in a different country from the one listed in their user profile.
To do this, create a Post-Login Action with the following code. Before deploying, add ipaddr.js as an npm dependency in the Action editor.
const ipaddr = require('ipaddr.js');

exports.onExecutePostLogin = async (event, api) => {
  const corp_network = "192.168.1.134/26";
  const current_ip = ipaddr.parse(event.request.ip);
  // is auth method passwordless and IP outside corp network?
  const passwordlessOutside = event.authentication.methods.find(
    (method) => (
      ((method.name === 'sms') || (method.name === 'email')) &&
      (!current_ip.match(ipaddr.parseCIDR(corp_network)))
    )
  );

  // if yes, then require MFA
  if (passwordlessOutside) {
    api.multifactor.enable('any', { allowRememberBrowser: false });
  }
};