<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-M74D8PB" height="0" width="0" style="display:none;visibility:hidden">
Loading
Skip to NavigationSkip to Main Content
0D54z00009qXf33CACOkta Classic EngineUniversal DirectoryAnswered2023-12-05T19:00:34.000Z2023-11-30T22:45:05.000Z2023-12-05T19:00:34.000Z

SreeR.28497 (Customer) asked a question.

Dynamically add users to groups

I have a requirement to have a Group that adds members automatically. We have test accounts (with the phrase test), admin accounts (-a in the phrase), etc that we don't want to add to the group. we have been using everyone group in the app assignment but app folks are complaining that there are too many of these unwanted accounts in the group consuming license in the aps. How can i do it? Is there a workflow?


  • TimL.58332 (Workflows)

    @SreeR.28497 (Customer)​  - I am not fully understanding the requirements of the use case.

     

    First, the default "Everyone" group is always going to show every single user in your Okta tenant. The only way to remove a user from "Everyone" is to Deactivate&Delete the user from your tenant.

     

    If you are talking about having a subset of users that are added to a custom group that meet some sort of conditions you would want to look into using a Group Rule and Okta Expression Language (OEL).

     

    Here is a simple example where every user that has a login that doesn't contain the sequence (-a) such as first.last-a@domain is added into a group:

     

    !String.stringContains(user.login, "-a")

     

    Keep in mind this example is going to look for that sequence anywhere in the string. So a hyphenated login such as john.smith-apple@domain or john.smith@login-appletech would also be found.

     

     

    Expand Post
    • SreeR.28497 (Customer)

      Thanks Tim
      I tried that but it didn’t work

      Here are my observations


      I first tried with “String.stringContains(user.login, "-a")” and did a preview by putting a Non -a account, and it says “Doesn’t match rule)

      But then when I put what you suggested “!String.stringContains(user.login, "-a")”, if I put -a it says matches rule, and I put a Non-a account as well it says it matches rule.



      Regards,
      sree
      Expand Post
      • TimL.58332 (Workflows)

        Hello Sree,

         

        The value reads as: !String.stringContains(user.login, "-a")

         

        Condition is met if string value "user.login" does not contain the sequence -a. I would expect it to put all non -a accounts into the group (My testing confirmed this). If you already had done the test without the ! not symbol and placed the -a users into the group then "Disabled, modified, enabled" the group rule after adding the ! not symbol it may take a bit of time for the originally added users to be removed that "matched" on the previous iteration of the rule. Each user add/removal is a single API call.

         

        The thing I didn't test is case sensitivity. For example I don't know if -A would match "-a" evaluation. I suspect it won't. To get around this you can do the following (which I just tested successfully)

         

        String.stringContains(String.toLowerCase(user.login), "-a")

         

        This placed my two test users into the group that have login values of:

         

        group.user-AA@domain.com

        group.user-a@domain.com

         

        Switching it to: !String.stringContains(String.toLowerCase(user.login), "-a")

         

        After waiting a bit added about 1000 users to the group and removed the 2 users listed above. Note: If you had 10k users it take 5+ minutes, 100k users could be hours, 1 million+ users could be days for the full add/remove process to the group finishes.

         

         

        Expand Post
      • SreeR.28497 (Customer)

        Tim, thanks a lot it worked for me.

        However it is adding deactivated users as well. Anyway we can exclude them?

        Thanks
        Sree
        Expand Post
This question is closed.
Loading
Dynamically add users to groups