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