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

Google authenticator

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

定義在 RFC-6238

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

第三方 Node.js 模組:

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

程式範例

以下使用 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.GitHub

演算法:

https://github.com/bellstrand/totp-generator/blob/master/index.js

PreviousTwitter OAuthNextfacebook oauth

Last updated 2 years ago

Was this helpful?

  • 定義在 RFC-6238
  • 程式範例
  • 演算法:

Was this helpful?

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)