Truncate SMAL attribute value

Hi,

Currently, I’m using Auth0 as an IdP for login via SAML. The client requires that the email address should be truncated to only 30 Char… is there a way to truncate email address or any function to get the substring of email.

{
“mappings”: {
“email”: “http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress”,\
}
}

Hi Snehal,

Welcome to the Auth0 community,

You can create a rule to truncate the email address and assign it to a new field, e.g. called email_truncated, then map the email_truncated field to SAML claims.

Here is the detailed steps:

  1. Create a new rule named truncate email address by following this document.
  2. Use the following code as reference for the rule truncate email address:
function truncate_email_address(user, context, callback) {
  function truncate_email(email) {
    // implement the code of truncating email to 30 charactors
  }
  if (context.clientID === "YOUR_SAML_CLIENT_ID") {
    user.email_truncated = truncate_email(user.email);
  }
  callback(null, user, context);
}
  1. Update the mappings of SAML
{
  “mappings”: {
  “email_truncated”: “http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress”,
  // you can also map the original email as a reference
  “email”: “http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress_untruncated”
  }
}

With the above changes, in the SAML response, you should have the truncated email in the http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress attribute, and the untruncated email in the http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress_untruncated attribute.

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.