Core
Framework v2.x
2

add #

Adds a new authentication strategy.

Users can be authenticated using this 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: string, properties: any): Promise<void>

ArgumentsTypeDescription
name
string
Name of the new authentication strategy
properties
any
Strategy properties (Authentication Strategy)

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',
    search: 'search',
    update: 'update',
    validate: 'validate',
    verify: 'verify'
  }
};

await context.accessors.strategies.add('someStrategy', strategy);