curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
source ~/.bashrc
nvm install --lts
sudo apt install ntpdate
#安装ntpdate
sudo ntpdate ntp1.aliyun.com
#与时间服务器同步时间
git clone https://github.com/alexwishes/google-auth.git
cd google-auth
npm install
chmod +x bin/*.sh
bin/start.sh
bin/start.sh 6
bin/stop.sh
http://localhost:3000/api/generateKey?account={自定义用户名}
{
"secret_key": "E39C8F89AC3A4BEEA212F01B7301507E",
"base32": "IUZTSQZYIY4DSQKDGNATIQSFIVATEMJSIYYDCQRXGMYDCNJQG5CQ====",
"qrcodeUrl": "http://qrcode.kaywa.com/img.php?s=8&d=otpauth%3A%2F%2Ftotp%2FtestUser%3Fsecret%3DIUZTSQZYIY4DSQKDGNATIQSFIVATEMJSIYYDCQRXGMYDCNJQG5CQ%3D%3D%3D%3D",
"qrcodeStr": "otpauth%3A%2F%2Ftotp%2FtestUser%3Fsecret%3DIUZTSQZYIY4DSQKDGNATIQSFIVATEMJSIYYDCQRXGMYDCNJQG5CQ%3D%3D%3D%3D"
}
其中secret_key为共享密钥,base32是secret_key的base32形式,qrcodeUrl提供直接生成的二维码,qrcodeStr为二维码实际内容
http://localhost:3000/api/verify?key=E39C8F89AC3A4BEEA212F01B7301507E&code=522176
{
"result": false,
"code": "522176",
"key": "E39C8F89AC3A4BEEA212F01B7301507E"
}
key就是1.1中的secret_key,code就是二次验证生成的code,result表示验证成功或者失败
所有支持google-authenticator的客户端都可以
IOS:https://itunes.apple.com/us/app/google-authenticator/id388497605?mt=8