The SDK provides a Users client to fetch users and user groups by name and also features some password management operations.
client variable in the following code examples refers to the
When using the Scripting SDK, this instance is created automatically and is named
When using the Web SDK, the variable name can be chosen freely, but is also called
client at instantiation in the docs.
Users and user groups are entities that can be used with the querying client and the entities client.
GetUserAsync method gets a user by username. The following example fetches the user entity of the superuser:
IEntity superuser = await client.Users.GetUserAsync("superuser");
Getting user groups
GetUserGroupAsync method gets a user group by name. The following example fetches the user group entity for the superusers group.
IEntity superusersGroup = await client.Users.GetUserGroupAsync("superusers");
Superusers have the privilege to set passwords of other users. Use the
SetPasswordAsync method To change the password on a specific user:
await client.Users.SetPasswordAsync(100, "securepassword");
The first argument is the id of the user (e.g. 100). The second argument is the new password.
Superusers also have the privilege to send 'password forgotten' e-mails to users. To do this, call the
ResetPasswordAsync method with the id of the user. An e-mail is sent containing a unique and secure link to a page where the user can change their password.
This feature only applies to users created and managed in Sitecore Content Hub. It should not be used on users that are created and managed by a Single sign-on provider (SSO).