"run as" for AddUserToRole

I have a widget that posts to a web service, and if the web service call succeeds, I want to then call $core_v2_roleUsers.AddUserToRole to add the user to the role returned by the web service. The problem is that the user making the call doesn't have the ability to add themselves (it returns a permission error).

If I call the equivalent from my C# code, will that work? (Phrased another way, does my widget extension run with elevated privileges or does it run as the accessing user)

Is there a better, more idiomatic way to allow users to self-add to a role?

Parents Reply
  • From what I've seen this is correct.  Only possible workaround is via the use of Automations...you can execute the script as the user that triggers the automation or the service account which could bypass some security.  So if you can extract your logic from a traditional widget and make it work within an automation which is triggered by a platform event or on an interval it might work.

    For a work-around you could maybe make your web service call and if it is successful, update a bit on the user profile extended attributes.  Create an automation that runs on a user update event and check that flag - if it exists, you can add them to the group if you execute the automation as the service account then reset the flag.

Children