User sign-in script
The following web script example is executed when a user logs into Sitecore Content Hub. It updates the user’s groups based on the provided claims.
This example uses the Everyone user group. Do not use it on your own Content Hub instance without customizing the script based on the names of your organization's user groups.
-
Ensure claims mapping configurations for sign-in are set up in the schema editor.
Script
Script explanation
This section steps through the script in execution order, explaining each part. The numbered items describe the sequence, not instructions to perform.
-
Ensure that user groups are updated for a user based on external claims if the authentication source is external.
-
Create a list of group names to collect group information from external claims. If no claims are available, add the default
Everyonegroup. -
Retrieve the IDs of the collected user groups using the
GetUserGroupIdsAsyncmethod. These IDs will be used to update the user's group relations. -
Retrieve the target user entity from the context, and the
UserGroupToUserrelation is loaded. This relation represents the user's membership in specific groups. -
Update the
UserGroupToUserrelation with the IDs of the collected groups, linking the user to the appropriate groups. -
Save the user entity, persisting the updated group memberships.
Setup
-
Create, publish, and enable the User sign-in script.
Disable a sign-in script
A sign-in script might lock users out if it contains runtime errors or inconsistent user validation. If this happens, disable the script by using the REST API or SDK to change M.Script.Enabled to false.
The following example disables a script using the web SDK: