【问题标题】:QR-Code with google chart API - Invalid for google authenticator app带有谷歌图表 API 的二维码 - 对谷歌身份验证器应用无效
【发布时间】:2014-07-29 03:32:02
【问题描述】:

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

我生成了一个秘密 EBWFBWYCPPELHQS5,我可以手动将其添加到 Google Authenticator 应用程序中。

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

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

我生成 url 的代码如下所示:

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


    【解决方案1】:

    您需要URL Encode 发送到 Google Charts API 的数据。

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

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

    否则,API 认为& 之后的所有内容都是它的另一个参数,而不是要编码的数据。

    【讨论】:

    • 其实secret是第一个查询参数,所以%26&)实际上应该是%3F?)——后面的参数应该用%26分隔(&)。
    • @Terence Eden 是否有可能所有这些用于 OTP 的二维码都使用谷歌图表 API 来生成二维码?我的意思是我们可以制作自己的自托管东西吗?如果是,请您分享一些链接吗?
    猜你喜欢
    • 1970-01-01
    • 2022-11-08
    • 2012-07-23
    • 2020-09-26
    • 2010-10-16
    • 1970-01-01
    • 2018-08-09
    • 2019-11-05
    • 2012-09-20
    相关资源
    最近更新 更多