【问题标题】:What data do I have to use to generate a QR code for Google Authenticator?我必须使用哪些数据来为 Google Authenticator 生成 QR 码?
【发布时间】:2014-03-23 13:33:02
【问题描述】:

我想在我们的应用程序中使用Google Authenticator 应用程序进行登录。

我正在使用speakeasy 生成身份验证的基础数据。它还可以吐出一个指向 Google 网站的 URL,该网站生成一个 QR 码,我可以使用 Google Authenticator 扫描它来设置方案。

我想自己生成二维码,主要是想在控制台使用qrcode-terminal显示出来。

我必须在 QR 码中编码哪些数据才能使其工作?

【问题讨论】:

    标签: node.js qr-code google-authenticator


    【解决方案1】:

    你必须编码的字符串是:

    otpauth://totp/ApplicationName?secret= + key.base32
    
    • ApplicationName 是您希望在 Google Authenticator 中显示的应用程序的名称。

    你的实现应该是这样的:

    var key = speakeasy.generate_key( {length : 20} );
    qrcode.generate( "otpauth://totp/foo?secret=" + key.base32, function( qrcode ) {
      console.log( qrcode );
    } );
    

    格式上还有official documentation

    【讨论】:

    • 当您想使用自定义时间段(长于或短于默认 30 秒)时,您将需要使用不同的 OTP 应用程序,例如 FreeOTP
    【解决方案2】:

    我必须在 QR 码中编码哪些数据才能使其工作?

    Google Authenticator 有一个wikiKeyUriFormat 有以下例子:

    为用户“alice@google.com”提供 TOTP 密钥,以便与 Example, Inc 提供的服务:

    otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example

    这个 Base32 编码的密钥“JBSWY3DPEHPK3PXP”的值是:

    byte[] key = { 'H', 'e', 'l', 'l', 'o', '!', (byte) 0xDE, (byte) 0xAD, (byte) 0xBE, (byte) 0xEF };

    在开头和结尾(与发行人)都使用公司名称(“示例”)很重要。详情请见ConflictingAccounts

    【讨论】:

    • 那是我链接到的同一篇文章
    • 哦,对不起。我错过了。您的答案似乎缺少文档中有关帐户冲突的部分。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-24
    • 1970-01-01
    • 1970-01-01
    • 2020-03-03
    • 2013-06-08
    • 1970-01-01
    相关资源
    最近更新 更多