带有 google 图表 API 的 QR 代码 - 对于 google 身份验证器应用程序无效

问题描述 投票:0回答:2

警告: 与第三方共享您的 TOTP 种子会破坏 TOTP 的多因素身份验证的基本假设 种子是秘密

我生成了一个秘密

EBWFBWYCPPELHQS5
,我可以将其手动添加到 Google 身份验证器应用程序中。

但是,如果我通过谷歌图表 API 从这个秘密生成 QR 码,我无法扫描 QR 码,应用程序告诉我 QR 码无效。 这将是上面秘密的二维码:

https://chart.googleapis.com/chart?chs=200x200&chld=M%7C0&cht=qr&chl=otpauth://totp/test@test&secret=EBWFBWYCPPELHQS5

我生成网址的代码如下所示:

public static String getQRBarcodeURL(String user, String host, String secret) {
    return "https://chart.googleapis.com/chart?" + getQRBarcodeURLQuery(user, host, secret);
}

public static String getQRBarcodeURLQuery(String user, String host, String secret) {
    return "chs=200x200&chld=M%7C0&cht=qr&chl=" +
            getQRBarcodeOtpAuthURL(user, host, secret);
}

public static String getQRBarcodeOtpAuthURL(String user, String host, String secret) {
    return String.format("otpauth://totp/%s@%s&secret=%s", user, host, secret);
}

我怎样才能让它工作

java authentication qr-code
2个回答
0
投票

您需要对发送到 Google Charts API 的数据进行 URL 编码。

&

字符应该是
%26
,如下所示:

https://chart.googleapis.com/chart?chs=200x200&chld=M%7C0&cht=qr&chl=otpauth://totp/test@test%26secret=EBWFBWYCPPELHQS5

否则,API 会认为

&

 之后的所有内容都是它的另一个参数,而不是要编码的数据。


0
投票
Google Charts TOTP QR 码服务这些天似乎返回 404。

© www.soinside.com 2019 - 2024. All rights reserved.