制作 Authy 理解的 QR 码的参数
parameters to make a QR code that Authy understands
我即将介绍 2FA 并使用 QRcode.js 从密钥生成 QR 码以供 2FA 应用程序扫描。
$('#totpQR').empty();
new QRCode(document.getElementById('totpQR'),secretkey);
$('#totpQRContainer').css('display','inline');
$('#totpQR').attr('title', 'otpauth://totp/'+encodeURIComponent(username)
+ location.hostname.replace(/^(.*\.)?(\b[\w-]+\.[a-z]+)$/, '@?secret=')
+ secretkey
);
GoogleAuthenticator 和 Authy 似乎都很挑剔;他们拒绝说 "The QR code is invalid" 或类似的代码。当我使用正确的 QR reader 扫描相同的 QR 时,来自 URL(otpauth://totp/username@sitename.tld?secret=secretkey
或 otpauth://totp/sitename?secret=secretkey
或 otpauth://totp/username@sitename.tld?secret=secretkey&digits=6&issuer=SiteName&period=30
)的密钥是正确的。
用谷歌搜索这个问题没有结果。
任何人都可以告诉我应该使用什么参数来生成我的 QR 或者我必须进行实验吗?
我猜 URL 没有错误?
问题确实出在我的代码中:我是从密钥创建 QR,而不是从整个 URL:
$('#totpQR').empty();
var url='otpauth://totp/'+encodeURIComponent(username)
+ location.hostname.replace(/^(.*\.)?(\b[\w-]+\.[a-z]+)$/, '@?secret=')
+ secretkey
;
new QRCode(document.getElementById('totpQR'),url);
$('#totpQRContainer').css('display','inline');
$('#totpQR').attr('title',url);
我即将介绍 2FA 并使用 QRcode.js 从密钥生成 QR 码以供 2FA 应用程序扫描。
$('#totpQR').empty();
new QRCode(document.getElementById('totpQR'),secretkey);
$('#totpQRContainer').css('display','inline');
$('#totpQR').attr('title', 'otpauth://totp/'+encodeURIComponent(username)
+ location.hostname.replace(/^(.*\.)?(\b[\w-]+\.[a-z]+)$/, '@?secret=')
+ secretkey
);
GoogleAuthenticator 和 Authy 似乎都很挑剔;他们拒绝说 "The QR code is invalid" 或类似的代码。当我使用正确的 QR reader 扫描相同的 QR 时,来自 URL(otpauth://totp/username@sitename.tld?secret=secretkey
或 otpauth://totp/sitename?secret=secretkey
或 otpauth://totp/username@sitename.tld?secret=secretkey&digits=6&issuer=SiteName&period=30
)的密钥是正确的。
用谷歌搜索这个问题没有结果。
任何人都可以告诉我应该使用什么参数来生成我的 QR 或者我必须进行实验吗?
我猜 URL 没有错误?
问题确实出在我的代码中:我是从密钥创建 QR,而不是从整个 URL:
$('#totpQR').empty();
var url='otpauth://totp/'+encodeURIComponent(username)
+ location.hostname.replace(/^(.*\.)?(\b[\w-]+\.[a-z]+)$/, '@?secret=')
+ secretkey
;
new QRCode(document.getElementById('totpQR'),url);
$('#totpQRContainer').css('display','inline');
$('#totpQR').attr('title',url);