0.55.8 • Published 4 months ago

@startupjs/2fa-manager v0.55.8

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

2fa-manager

Component for using various two-factor authentication methods.

Installation

  yarn add @startupjs/2fa-manager

Connecting to startupjs

server

Add the following lines to server/index.js:

  import { initTwoFAManager } from '@startupjs/2fa-manager/server'

Add function to startupjsServer:

  initTwoFAManager(ee, {
    providers: [YOUR_PROVIDER1, YOUR_PROVIDER2]
  })

Creating custom providers

You can create your own providers using the Provider class from @startupjs/2fa-manager/Provider.

Class Provider(name, send, check) where:

  • name - string, provider name.
  • send() - function of sending a message with a code.
  • check(code) - function for checking the validity of the code.
    • code - the code to check.

Example

import { Provider } from '@startupjs/2fa-manager/Provider'

function init (ee, options) {
  return null
}

function send () {
  console.log('test code')
}

function check (token) {
  if (token === 'test code') {
    console.log('Right code')
  } else {
    console.log('Wrong code')
  }
}

export default new Provider('testProvider', init, send, check)

Now this Provider can be registered with initTwoFaManager and used by the name testProvider.

API

server

initTwoFaManager(ee, options)

  • ee - eventEmitter of server.
  • options - options object. Contains a list of providers:
    • providers - array of providers.

TwoFAManager

Singleton class that contains the following methods:

  • send(model, session, providerName) - calls the send method of the provider providerName.
  • check(model, session, token, providerName) - calls the check method of the provider providerName.
  • getProviders() - returns an array of the names of the registered providers.

client

ProvidersList2fa(providers, chooseProvider)

Component for displaying a list of registered providers. Accepts the following props:

  • providers - array of provider names
  • chooseProvider - function, returns the name of the selected provider
0.56.0-alpha.0

4 months ago

0.55.7

5 months ago

0.55.8

5 months ago

0.55.1

6 months ago

0.55.0-alpha.12

6 months ago

0.55.0-alpha.1

7 months ago

0.55.0

6 months ago

0.54.1

7 months ago

0.54.2

7 months ago

0.53.0

9 months ago

0.54.0

7 months ago

0.52.1

12 months ago

0.51.0

12 months ago

0.52.0

12 months ago

0.50.13

1 year ago

0.50.12

1 year ago

0.50.5

1 year ago

0.48.0

2 years ago

0.49.0

1 year ago

0.47.0

2 years ago

0.46.0

2 years ago

0.45.0

2 years ago

0.44.0

2 years ago

0.42.0

2 years ago

0.43.0

2 years ago

0.41.2

2 years ago

0.41.0

2 years ago

0.43.1

2 years ago

0.39.11

3 years ago

0.40.0

3 years ago

0.39.0

3 years ago

0.38.0

3 years ago

0.37.8

3 years ago

0.37.1

3 years ago

0.37.0

3 years ago

0.36.0

3 years ago

0.35.10

3 years ago

0.35.2

3 years ago