Skip to content

Instantly share code, notes, and snippets.

@sashimizakana
Created December 3, 2014 05:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sashimizakana/35df977ccaa44eba083b to your computer and use it in GitHub Desktop.
Save sashimizakana/35df977ccaa44eba083b to your computer and use it in GitHub Desktop.
nodeでAWSとかのTOTP方式のMFAを利用するやつ
/**
* nodeでAWSとかのTOTP方式のMFAを利用するやつ。
*
* node-zxingはJavaのクラスパスが:で区切られてるのでそのままだとWindowsでは使えず
* thirty-twoはVer0.02じゃないと失敗する場合がある
*/
var qr = require('node-zxing')();
var notp = require('notp');
var base32 = require('thirty-two');
qr.decode("qr.png",function(err,out){
var key = base32.decode(out.split(/=/)[1]);
var token = notp.totp.gen(key);
console.log(token);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment