Retrieving LDAP properties in Action

Hi,

We are migrating our Auth0 Rule to an Action but we are struggling to retrieve information from users that connect through the LDAP enterprise connection.

We are trying to migrate the following rule:

function (user, context, callback) {
  const namespace = 'https://mycustomer/api/';
  context.accessToken[namespace + 'email'] = user.email;  
  context.idToken[namespace + 'email'] = user.email; 
  
  if (context.connectionStrategy === "ad") {
    context.accessToken.email = user.userPrincipalName;
    context.accessToken[namespace + 'email'] = user.userPrincipalName;
    context.idToken[namespace + 'email'] = user.userPrincipalName; 
    context.accessToken[namespace + 'groups'] = (user.groups || []).join(';');
    context.accessToken[namespace + 'userId'] = user.sAMAccountName;
  }
  
  callback(null, user, context);
}

We have created the following Action, but are stuck on the AD strategy part.

exports.onExecutePostLogin = async (event, api) => {
  if (event.authorization) {
    const namespace = 'https://mycustomer/api/';

    api.accessToken.setCustomClaim(`${namespace}/email`, event.user.email);
    api.idToken.setCustomClaim(`${namespace}/email`, event.user.email);

    if(event.connection.strategy === 'ad') {
      // What do to here?
    }
  }
};

How do we get the information like groups and userPrincipalName in our Action?

Thanks in advance.

1 Like

Hey there!

As this topic is related to Actions and Rules & Hooks are being deprecated soon in favor of Actions, I’m excited to let you know about our next Ask me Anything session in the Forum on Thursday, January 18 with the Rules, Hooks and Actions team on Rules & Hooks and why Actions matter! Submit your questions in the thread above and our esteemed product experts will provide written answers on January 18. Find out more about Rules & Hooks and why Actions matter! Can’t wait to see you there!

Learn more here!