authenticator vs otplib vs speakeasy
認証ライブラリ
authenticatorotplibspeakeasy類似パッケージ:

認証ライブラリ

認証ライブラリは、ユーザーの認証とセキュリティを強化するためのツールです。これらのライブラリは、特に二要素認証(2FA)やワンタイムパスワード(OTP)を生成するために使用され、ユーザーのアカウントを保護するための重要な機能を提供します。これにより、悪意のある攻撃からユーザーのデータを守ることができます。

npmのダウンロードトレンド

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
authenticator0---8年前(MIT or Apache-2.0)
otplib02,225524 kB124日前MIT
speakeasy02,755-6710年前MIT

機能比較: authenticator vs otplib vs speakeasy

使いやすさ

  • authenticator:

    Authenticatorは、シンプルなAPIを提供しており、迅速に実装できます。特に、モバイルアプリケーションでの利用に適しており、開発者が簡単に導入できるように設計されています。

  • otplib:

    otplibは、OTPの生成と検証に特化しており、使いやすいAPIを提供しますが、カスタマイズ性が高いため、少し学習が必要です。

  • speakeasy:

    Speakeasyは、直感的なAPIを持ち、Node.js環境での統合が容易です。特にサーバーサイドでの利用において、迅速に導入できる点が魅力です。

機能の柔軟性

  • authenticator:

    Authenticatorは、基本的な認証機能を提供しますが、カスタマイズの余地は少ないです。シンプルなニーズには適していますが、複雑な要件には向いていません。

  • otplib:

    otplibは、RFC 6238に準拠しており、さまざまなカスタマイズオプションを提供します。特に、異なるアルゴリズムやシード値を使用する必要がある場合に便利です。

  • speakeasy:

    Speakeasyは、OTPの生成や検証において、シンプルさと柔軟性を兼ね備えています。特に、サーバーサイドでの利用において、簡単にカスタマイズできます。

セキュリティ機能

  • authenticator:

    Authenticatorは、基本的なセキュリティ機能を提供しますが、特に高度なセキュリティ機能は備えていません。シンプルなアプリケーションには適していますが、より強力なセキュリティが必要な場合には他の選択肢を検討するべきです。

  • otplib:

    otplibは、セキュリティに重点を置いており、OTPの生成において強力なアルゴリズムを使用しています。特に、セキュリティが重要なアプリケーションに適しています。

  • speakeasy:

    Speakeasyは、セキュリティ機能が強化されており、OTPの生成と検証において高い信頼性を提供します。特に、サーバーサイドアプリケーションにおいて、セキュリティが重要な要素となる場合に適しています。

ドキュメントとサポート

  • authenticator:

    Authenticatorは、基本的なドキュメントが提供されていますが、詳細なサポートは限られています。シンプルなニーズには対応できますが、複雑な問題に対してはサポートが不足する可能性があります。

  • otplib:

    otplibは、詳細なドキュメントがあり、コミュニティサポートも充実しています。特に、カスタマイズが必要な場合には、役立つ情報が多くあります。

  • speakeasy:

    Speakeasyは、良好なドキュメントとサポートを提供しており、特にNode.js環境での利用において、開発者がスムーズに導入できるように設計されています。

パフォーマンス

  • authenticator:

    Authenticatorは、シンプルな実装により、パフォーマンスは良好ですが、複雑な処理には向いていません。基本的な認証機能を必要とする場合には適しています。

  • otplib:

    otplibは、効率的なOTP生成を実現しており、大規模なユーザーに対しても高いパフォーマンスを発揮します。特に、スケーラブルなアプリケーションに適しています。

  • speakeasy:

    Speakeasyは、サーバーサイドでのOTP生成において高いパフォーマンスを提供します。特に、リアルタイムでの認証が必要な場合に適しています。

選び方: authenticator vs otplib vs speakeasy

  • authenticator:

    Authenticatorは、シンプルで使いやすいAPIを提供し、特にモバイルアプリケーションでの使用に適しています。迅速に実装したい場合や、基本的な認証機能を必要とする場合に選択するべきです。

  • otplib:

    otplibは、OTPの生成と検証に特化したライブラリで、RFC 6238に準拠しています。カスタマイズ性が高く、特に複雑な認証システムを構築したい場合に適しています。

  • speakeasy:

    Speakeasyは、シンプルで直感的なAPIを持ち、Node.jsアプリケーションに統合するのが容易です。特に、サーバーサイドでのOTP生成や検証が必要な場合に選ぶべきです。

authenticator のREADME

Node.js Authenticator

| Sponsored by ppl

Two- and Multi- Factor Authenication (2FA / MFA) for node.js

There are a number of apps that various websites use to give you 6-digit codes to increase security when you log in:

There are many Services that Support MFA, including Google, Microsoft, Facebook, and Digital Ocean for starters.

This module uses notp which implements TOTP (RFC 6238) (the Authenticator standard), which is based on HOTP (RFC 4226) to provide codes that are exactly compatible with all other Authenticator apps and services that use them.

Browser & Commandline Authenticator

You may also be interested in

Install

node.js api

npm install authenticator --save

command line

npm install authenticator-cli --global

Usage

node.js api

'use strict';

var authenticator = require('authenticator');

var formattedKey = authenticator.generateKey();
// "acqo ua72 d3yf a4e5 uorx ztkh j2xl 3wiz"

var formattedToken = authenticator.generateToken(formattedKey);
// "957 124"

authenticator.verifyToken(formattedKey, formattedToken);
// { delta: 0 }

authenticator.verifyToken(formattedKey, '000 000');
// null

authenticator.generateTotpUri(formattedKey, "john.doe@email.com", "ACME Co", 'SHA1', 6, 30);
//
// otpauth://totp/ACME%20Co:john.doe@email.com?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ&issuer=ACME%20Co&algorithm=SHA1&digits=6&period=30

command line

# see help
authenticator --help

# generate a key and display qr code
authenticator --qr

API

generateKey()                               // generates a 32-character (160-bit) base32 key

generateToken(formattedKey)                 // generates a 6-digit (20-bit) decimal time-based token

verifyToken(formattedKey, formattedToken)   // validates a time-based token within a +/- 30 second (90 seconds) window
                                            // returns `null` on failure or an object such as `{ delta: 0 }` on success

                                            // generates an `OTPAUTH://` scheme URI for QR Code generation.
generateTotpUri(formattedKey, accountName, issuer, algorithm, digits, period)

OTPAuth Scheme

Note that ISSUER is specified twice for backwards / forwards compatibility.

QR Code

See https://davidshimjs.github.io/qrcodejs/ and https://github.com/soldair/node-qrcode.

Example use with qrcode.js in the browser:

'use strict';

var el = document.querySelector('.js-qrcode-canvas');
var link = "otpauth://totp/{{NAME}}?secret={{KEY}}";
var name = "Your Service";
                                              // remove spaces, hyphens, equals, whatever
var key = "acqo ua72 d3yf a4e5 uorx ztkh j2xl 3wiz".replace(/\W/g, '').toLowerCase();

var qr = new QRCode(el, {
  text: link.replace(/{{NAME}}/g, name).replace(/{{KEY}}/g, key)
});

Formatting

All non-alphanumeric characters are ignored, so you could just as well use hyphens or periods or whatever suites your use case.

These are just as valid:

  • "acqo ua72 d3yf a4e5 - uorx ztkh j2xl 3wiz"
  • "98.24.63"

0, 1, 8, and 9 also not used (so that base32). To further avoid confusion with O, o, L, l, I, B, and g you may wish to display lowercase instead of uppercase.

TODO: should this library replace 0 with o, 1 with l (or I?), 8 with b, 9 with g, and so on?

90-second Window

The window is set to +/- 1, meaning each token is valid for a total of 90 seconds (-30 seconds, +0 seconds, and +30 seconds) to account for time drift (which should be very rare for mobile devices) and humans who are handicapped or otherwise struggle with quick fine motor skills (like my grandma).

Why not SpeakEasy?

It doesn't use native node crypto and there are open security issues which have been left unaddressed.