RolesManager

management. RolesManager

RolesManager The role class provides a simple abstraction for performing CRUD operations on Auth0 RolesManager.

Constructor

new RolesManager(options)

Source:
Parameters:
Name Type Description
options Object

The client options.

Name Type Attributes Description
baseUrl String

The URL of the API.

headers Object <optional>

Headers to be included in all requests.

retry Object <optional>

Retry Policy Config

Members

(inner) auth0RestClient :external:RestClient

Provides an abstraction layer for performing CRUD operations on Auth0 RolesManagers.

Source:
Type:

(inner) clientOptions :Object

Options object for the Rest Client instance.

Source:
Type:
  • Object

Methods

addPermissions(data, cbopt) → {Promise|undefined}

Add permissions in a role

Source:
Parameters:
Name Type Attributes Description
params.id String

ID of the Role.

data Object

permissions data

Name Type Description
permissions String

Array of permissions

Name Type Description
permission_name String

Name of a permission

resource_server_identifier String

Identifier for a resource

cb function <optional>

Callback function.

Returns:
Type:
Promise | undefined
Example
var params =  { id :'ROLE_ID'};
var data = { "permissions" : [{"permission_name" :"do:something" ,"resource_server_identifier" :"test123" }]};

management.roles.addPermissions(params, data, function (err, user) {
  if (err) {
    // Handle error.
  }

  // permissions added.
});

assignRoles(params, data, cbopt) → {Promise|undefined}

Assign roles to a user

Source:
Parameters:
Name Type Attributes Description
params Object

params object

Name Type Description
id String

user_id

data String

data object containing list of role IDs

Name Type Description
roles String

Array of role IDs

cb function <optional>

Callback function.

Returns:
Type:
Promise | undefined
Example
var params =  { id : 'USER_ID';
var data = { "roles" : ["roleId1", "roleID2"]};

management.users.assignRoles(params, data, function (err, user) {
  if (err) {
    // Handle error.
  }

  // roles added.
});

assignUsers(data, cbopt) → {Promise|undefined}

Assign users to a role

Source:
Parameters:
Name Type Attributes Description
params.id String

ID of the Role.

data Object

permissions data

Name Type Description
permissions String

Array of permissions

Name Type Description
permission_name String

Name of a permission

resource_server_identifier String

Identifier for a resource

cb function <optional>

Callback function.

Returns:
Type:
Promise | undefined
Example
var params =  { id :'ROLE_ID'};
var data = { "users" : ["userId1","userId2"]};

management.roles.assignUsers(params, data, function (err, user) {
  if (err) {
    // Handle error.
  }

  // permissions added.
});

create(data, cbopt) → {Promise|undefined}

Create a new role.

Source:
Parameters:
Name Type Attributes Description
data Object

Role data object.

cb function <optional>

Callback function.

Returns:
Type:
Promise | undefined
Example
management.roles.create(data, function (err) {
  if (err) {
    // Handle error.
  }

  // Role created.
});

delete(params, cbopt) → {Promise|undefined}

Delete an existing role.

Source:
Parameters:
Name Type Attributes Description
params Object

Role parameters.

Name Type Description
id String

Role ID.

cb function <optional>

Callback function.

Returns:
Type:
Promise | undefined
Example
management.roles.delete({ id: ROLE_ID }, function (err) {
  if (err) {
    // Handle error.
  }

  // Role deleted.
});

get(params, cbopt) → {Promise|undefined}

Get an Auth0 role.

Source:
Parameters:
Name Type Attributes Description
params Object

Role parameters.

Name Type Description
id String

Role ID.

cb function <optional>

Callback function.

Returns:
Type:
Promise | undefined
Example
management.roles.get({ id: ROLE_ID }, function (err, role) {
  if (err) {
    // Handle error.
  }

  console.log(role);
});

getAll(paramsopt, cbopt) → {Promise|undefined}

Get all roles.

Source:
Parameters:
Name Type Attributes Description
params Object <optional>

Roles parameters.

Name Type Attributes Description
per_page Number <optional>

Number of results per page.

page Number <optional>

Page number, zero indexed.

cb function <optional>

Callback function.

Returns:
Type:
Promise | undefined
Example

This method takes an optional object as first argument that may be used to specify pagination settings. If pagination options are not present, the first page of a limited number of results will be returned.

// Pagination settings.
var params = {
  per_page: 10,
  page: 0
};

management.roles.getAll(params, function (err, roles) {
  console.log(roles.length);
});

getPermissionsInRole(emailopt, cbopt) → {Promise|undefined}

Get Permissions in a Role

Source:
Parameters:
Name Type Attributes Description
email String <optional>

Email address of user(s) to find

cb function <optional>

Callback function.

Returns:
Type:
Promise | undefined
Examples
var params = {id : 'ROLE_ID'}

This method takes a first argument as the roleId and returns the permissions within that role

management.roles.getPermissions( {id : 'ROLE_ID'}, function (err, permissions) {
  console.log(permissions);
});

getUsers(roleIdopt, cbopt) → {Promise|undefined}

Get Users in a Role

Source:
Parameters:
Name Type Attributes Description
roleId String <optional>

Id of the role

params.per_page Number <optional>

Number of results per page.

params.page Number <optional>

Page number, zero indexed.

cb function <optional>

Callback function.

Returns:
Type:
Promise | undefined
Examples
var params = {
  roleId: 'ROLE_ID'
  per_page: 50,
  page: 0
};

This method takes a roleId and returns all users within that role

management.roles.getUsers(params, function (err, users) {
  console.log(users);
});

removePermissions(data, cbopt) → {Promise|undefined}

Remove permissions from a role

Source:
Parameters:
Name Type Attributes Description
params.id String

ID of the Role.

data Object

permissions data

Name Type Description
permissions String

Array of permissions

Name Type Description
permission_name String

Name of a permission

resource_server_identifier String

Identifier for a resource

cb function <optional>

Callback function.

Returns:
Type:
Promise | undefined
Example
var params =  { id :'ROLE_ID'};
var data = { "permissions" : [{"permission_name" :"do:something" ,"resource_server_identifier" :"test123" }]};

management.roles.removePermissions(params, data, function (err, user) {
  if (err) {
    // Handle error.
  }

  // permissions added.
});

removeRoles(params, data, cbopt) → {Promise|undefined}

Remove roles from a user

Source:
Parameters:
Name Type Attributes Description
params Object

params object

Name Type Description
id String

user_id

data String

data object containing list of role IDs

Name Type Description
roles String

Array of role IDs

cb function <optional>

Callback function.

Returns:
Type:
Promise | undefined
Example
var params =  { id : 'USER_ID';
var data = { "roles" : ["roleId1", "roleID2"]};

management.users.removeRoles(params, data, function (err, user) {
  if (err) {
    // Handle error.
  }

  // roles removed.
});

update(params, data, cbopt) → {Promise|undefined}

Update an existing role.

Source:
Parameters:
Name Type Attributes Description
params Object

Role parameters.

Name Type Description
id String

Role ID.

data Object

Updated role data.

cb function <optional>

Callback function.

Returns:
Type:
Promise | undefined
Example
var data = { name: 'New name' };
var params = { id: ROLE_ID };

// Using auth0 instance.
management.updateRole(params, data, function (err, role) {
  if (err) {
    // Handle error.
  }

  console.log(role.name);  // 'New name'
});

// Using the roles manager directly.
management.roles.update(params, data, function (err, role) {
  if (err) {
    // Handle error.
  }

  console.log(role.name);  // 'New name'
});