5

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

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

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

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

4

2 回答 2

10

您必须编码的字符串是:

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 );
} );

还有关于格式的官方文档。

于 2014-02-21T20:30:25.330 回答
2

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

Google Authenticator 有一个wiki。KeyUriFormat具有以下示例:

为用户“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 };

在开头和结尾(与发行人一起)使用公司名称(“示例”)很重要。有关详细信息,请参阅冲突帐户

于 2014-03-25T07:29:06.773 回答