public function Users::addRoles in Auth0 Single Sign On 8.2
Add one or more roles to a specific user. Required scopes:
- "update:users"
- "read:roles"
@link https://auth0.com/docs/api/management/v2#!/Users/post_user_roles
Parameters
string $user_id User ID to add roles to.:
array $roles Array of roles to add.:
Return value
mixed
Throws
EmptyOrInvalidParameterException Thrown if the user_id parameter is empty or is not a string.
EmptyOrInvalidParameterException Thrown if the roles parameter is empty.
\Exception Thrown by the HTTP client when there is a problem with the API call.
File
- vendor/
auth0/ auth0-php/ src/ API/ Management/ Users.php, line 320
Class
- Users
- Class Users. Handles requests to the Users endpoint of the v2 Management API.
Namespace
Auth0\SDK\API\ManagementCode
public function addRoles($user_id, array $roles) {
$this
->checkEmptyOrInvalidString($user_id, 'user_id');
if (empty($roles)) {
throw new EmptyOrInvalidParameterException('roles');
}
$data = [
'roles' => $roles,
];
return $this->apiClient
->method('post')
->addPath('users', $user_id)
->addPath('roles')
->withBody(json_encode($data))
->call();
}