This article provides an in-depth explanation of a particular Okta Expression Language expression that retrieves user group information, modifies the group names, and returns the result as a flat array. The Okta Expression Language is a versatile tool that enables administrators to manipulate and handle user and group data effectively.
- Okta Expression Language (OEL)
There may be a need to retrieve specific group data for a user, manipulate these data (like removing certain substrings from the group names), and ensure the output is a flat array (i.e., it has only one level). Okta Expression Language provides a way to achieve these outcomes.
The expression Arrays.flatten(String.replace(getFilteredGroups({"Group1_ID","Group2_ID"}, "group.name", 40), "SSO-", "") ) achieves the following:
-
getFilteredGroups({"Group1_ID","Group2_ID"}, "group.name", 40) retrieves the names of the first 40 groups that a user is a member of, among the specified groups ("Group1_ID" and "Group2_ID").
-
String.replace(getFilteredGroups({"Group1_ID","Group2_ID"}, "group.name", 40), "SSO-", "") takes the results of the getFilteredGroups function and removes any occurrence of SSO- in the group names.
-
Arrays.flatten(String.replace(getFilteredGroups({"Group1_ID","Group2_ID"}, "group.name", 40), "SSO-", "") ) ensures the output is a flat array, useful in cases where the String.replace function results in an array of arrays.
