Web_Advance
search
Ctrlk
  • 本書簡介
  • Node.js 部分chevron-right
  • OS
  • Async Hook
  • TCP
  • HTTPchevron-right
  • HTTPSchevron-right
  • Crypto加密
  • 有關繼承
  • JS 基本chevron-right
  • 使用 Expresschevron-right
  • 使用 Nest.js
  • 使用MongoDBchevron-right
  • 使用MySQLchevron-right
  • 使用PostgreSQLchevron-right
  • 使用TypeORM
  • RethinkDB
  • CSS 深度探討chevron-right
  • Reactchevron-right
  • React routerchevron-right
  • Reduxchevron-right
  • React Nativechevron-right
  • JS 模組化
  • 使用 Webpack
  • 使用 Babel
  • JWT Token
  • ES6 ES7 ES8chevron-right
  • 模板引擎chevron-right
  • ESLint
  • 部屬到OpenShift
  • OpenStack
  • OAuthchevron-right
    • Twitter OAuth
    • Google authenticator
    • facebook oauthchevron-right
    • google oauth
  • Redis
  • 做一個簡單的markdown editor
  • Websocketchevron-right
  • Sublime 安裝套件
  • Google apichevron-right
  • Instagram API
  • Markdown 與 code pretty js
  • HTML5chevron-right
  • Google Cloud Platform (GCP)chevron-right
  • Vim 編輯器
  • 使用nginxchevron-right
  • Unix 實用指令chevron-right
  • Git 實用指令chevron-right
  • SSH 實用指令
  • 有關Fetch與axios與跨域請求
  • 圖片上傳相關chevron-right
  • JS 格式轉換
  • js trick
  • AWSchevron-right
  • 有關日期Date
  • VS code 編輯器chevron-right
  • CI with Gitlab&Jenkins
  • API 測試chevron-right
  • Javascript 實用Lib
  • 遠端寫程式
  • Quicktime錄影注意事項
  • Web開發進階Bug
  • Web壓力測試
  • LineBot
  • PM2部署
  • i18n
  • VPN
  • Protocol Buffers
  • Docker教學chevron-right
  • E2E Testingchevron-right
  • Unit Test (Jest & enzyme)chevron-right
  • Cassandrachevron-right
  • Distribute Webchevron-right
  • Cluster and Child_process
  • 打包應用程式
  • Javachevron-right
  • Debug 頁面
  • Proxy
  • Chrome extension
  • 消息系統chevron-right
  • 金流串接chevron-right
  • 有關Log
  • 設定 feature flag
  • Azurechevron-right
  • NodeBB 筆記
  • 瀏覽器快取與緩存(Etag, If-None-Match)
  • 瀏覽器快取與緩存(Expires, Last-modified, Cache-Control)
  • Node.js 第三方模組chevron-right
  • Kuberneteschevron-right
  • Ngrok 使用
  • Telegram MiniAPP 開發
  • Firebase 教學
  • 演算法筆記
  • 圖表chevron-right
  • 後端緩存 Cache
  • 資料一致性
  • Web 安全機制chevron-right
  • Vuechevron-right
  • 相關網路協議chevron-right
  • GitLab 與 Drone
  • SMTP、POP、IMAPchevron-right
  • IPC
  • 串流服務chevron-right
  • 其他資源
  • GraphQL
  • Typescript
  • UI 相關資源
  • FFmpeg
  • Unity 遊戲開發筆記
  • Influx DB
  • Windows 相關
  • DALL·E 3
  • Coap
  • Slack API
  • 資訊安全chevron-right
gitbookPowered by GitBook
block-quoteOn this pagechevron-down
githubEdit
  1. OAuth

Google authenticator

TOPT ( Time-based One-Time Passwords) 2FA

hashtag
定義在 RFC-6238

LogoRFC 6238: TOTP: Time-Based One-Time Password AlgorithmIETF Datatrackerchevron-right
LogoWhat is a Time-based One-time Password (TOTP)? | Twiliowww.twilio.comchevron-right
LogoKey Uri FormatGitHubchevron-right
https://rootprojects.org/authenticator/rootprojects.orgchevron-right
https://git.coolaj86.com/coolaj86/browser-authenticator.jsgit.coolaj86.comchevron-right

第三方 Node.js 模組:

LogoGitHub - speakeasyjs/speakeasy: **NOT MAINTAINED** Two-factor authentication for Node.js. One-time passcode generator (HOTP/TOTP) with support for Google Authenticator.GitHubchevron-right
LogoGitHub - yeojz/otplib: :key: One Time Password (OTP) / 2FA for Node.js and Browser - Supports HOTP, TOTP and Google AuthenticatorGitHubchevron-right
Authenticator API.com - An API for Google Authenticatorauthenticatorapi.comchevron-right

hashtag
程式範例

以下使用 speakeasy 模組,產生 secret 與 qrcode,之後 secret 要記住在後端

驗證

LogoGitHub - speakeasyjs/speakeasy: **NOT MAINTAINED** Two-factor authentication for Node.js. One-time passcode generator (HOTP/TOTP) with support for Google Authenticator.GitHubchevron-right

hashtag
演算法:

https://github.com/bellstrand/totp-generator/blob/master/index.jsarrow-up-right

PreviousTwitter OAuthchevron-leftNextfacebook oauthchevron-right

Last updated 2 years ago

  • 定義在 RFC-6238
  • 程式範例
  • 演算法:
const speakeasy = require("speakeasy");
const qrcode = require("qrcode");

const secret = speakeasy.generateSecret({ name: "eason@gmail.com" });

console.log(secret)

qrcode.toDataURL(secret.otpauth_url, function (err, url) {
  console.log(url);
});
const speakeasy = require("speakeasy");

const verifyResult = speakeasy.totp.verify({
  secret: "<剛才的 secret>",
  encoding: "ascii",
  token: "<手機 google authenticator app 掃碼 qrcode 後產生的六個號碼>"
})

console.log('verifyResult', verifyResult)