SDK
SDK Javascript v7.x
2

createRestrictedUser #

Creates a new user in Kuzzle, with a preset list of security profiles.

The list of security profiles attributed to restricted users is fixed, and must be configured in the Kuzzle configuration file.

This method allows users with limited rights to create other accounts, but blocks them from creating accounts with unwanted privileges (e.g. an anonymous user creating his own account).


createRestrictedUser(body, [kuid], [options]);

PropertyTypeDescription
body
object
User content & credentials
kuid
string
User kuid. If not provided, a random kuid is automatically generated
options
object
Query options

body #

The body property must contain two objects:

  • content: User additional information. Can be left empty.
  • credentials: Describe how the new user can be authenticated. This object must contain one or more properties, named after the target authentication strategy to use. Each one of these properties are objects containing the credentials information, corresponding to that authentication strategy.

Example:

{
  content: {
    firstName: 'John',
    lastName: 'Doe'
  },
  credentials: {
    local: {
      username: 'jdoe',
      password: 'password'
    }
  }
}

options #

PropertyType
(default)
Description
queuable
boolean

(true)
If true, queues the request during downtime, until connected to Kuzzle again
refresh
boolean

(false)
If set to wait_for, Kuzzle will not respond until the user is indexed
timeout
number

(-1)
Time (in ms) during which a request will still be waited to be resolved. Set it -1 if you want to wait indefinitely
triggerEvents
boolean

(false)
If set to true, will trigger events even if using Embeded SDK. You should always ensure that your events/pipes does not create an infinite loop.
Available since Kuzzle 2.31.0

Resolves #

A User object containing information about the newly created user.

Usage #

try {
  const response = await kuzzle.security.createRestrictedUser({
    content: {
      fullName: 'John Doe'
    },
    credentials: {
      local: {
        username: 'jdoe',
        password: 'foobar'
      }
    }
  }, 'jdoe');
  console.log(response);
  /*
  User {
    _id: 'jdoe',
    content:,
      { profileIds: [ 'default' ],
        fullName: 'John Doe',
        _kuzzle_info:
          { author: '-1',
            createdAt: 1561379086534,
            udpatedAt: null,
            updater: null } } }
   */
  console.log('User successfully created');
} catch (e) {
  console.error(e);
}