Core
Write Plugins v1.x
1

You are currently looking at the documentation of a previous version of Kuzzle. We strongly recommend that you use the latest version. You can also use the version selector in the top menu.

strategies #

Dynamically adds or removes authentication strategies.


add #

Available since 1.2.0

Adds a new authentication strategy.

Users can be authenticated using that new strategy as soon as this method resolves.

If the strategy to be added already exists, the old one will be removed first, unless it has been registered by another plugin.

In a cluster environment, the new strategy is automatically added to all server nodes.

Arguments #

add(name, properties);

ArgumentsTypeDescription
name
string
Name of the new authentication strategy
properties
object
Strategy properties (see managing credentials)

Return #

The add function returns a promise.

The promise is rejected if:

  • the properties for that strategy are invalid or incomplete
  • the properties does not expose a known authenticator value
  • a strategy of the same name has already been registered by another plugin

Example #

const strategy = {
  config: {
    authenticator: 'StrategyConstructorName',
    authenticateOptions: {
      scope: []
    }
  },
  methods: {
    create: 'create',
    delete: 'delete',
    exists: 'exists',
    update: 'update',
    validate: 'validate',
    verify: 'verify'
  }
};

try {
  await context.accessors.strategies.add('someStrategy', strategy);
} catch (error) {
  // "error" is a KuzzleError object
}

remove #

Available since 1.2.0

Removes an authentication strategy, preventing new authentications from using it.

In a cluster environment, the new strategy is automatically removed from all server nodes.

Authentication tokens previously created using that strategy ARE NOT invalidated after using this method.

Arguments #

remove(name);

ArgumentsTypeDescription
name
string
Name of the authentication strategy to remove

Return #

The remove function returns a promise, resolved once the strategy has been successfully removed.

This promise is rejected if the strategy to remove does not exist, or if it is owned by another plugin.

Example #

try {
  context.accessors.strategies.remove('someStrategy');
} catch (error) {
  // "error" is a KuzzleError object
}