Der*_*ler 4 qr-code node.js google-authenticator
我想在我们的应用程序中使用Google身份验证器应用程序进行登录.
我正在使用speakeasy来生成用于身份验证的基础数据.它还可以向生成QR代码的Google网站吐出一个URL,我可以使用Google身份验证器扫描该代码来设置该方案.
我想自己生成QR码,主要是因为我想使用qrcode-terminal在控制台中显示它.
我需要在QR码中编码哪些数据才能使其正常工作?
您必须编码的字符串是:
otpauth://totp/ApplicationName?secret= + key.base32
Run Code Online (Sandbox Code Playgroud)
ApplicationName 是您要在Google身份验证器中显示的应用程序的名称.您的实现看起来像这样:
var key = speakeasy.generate_key( {length : 20} );
qrcode.generate( "otpauth://totp/foo?secret=" + key.base32, function( qrcode ) {
console.log( qrcode );
} );
Run Code Online (Sandbox Code Playgroud)
还有关于该格式的官方文档.