gpt4 book ai didi

node.js - 尝试为 Google 身份验证器插入 QR 码图像时出现 400 Bad Request

转载 作者:搜寻专家 更新时间:2023-10-31 22:29:26 25 4
gpt4 key购买 nike

我正在尝试在我的网站上使用 Google 身份验证器设置双因素身份验证。我能够生成工作代码,但是当我将图像 URL 插入页面时,我在 Chrome 检查器中收到以下错误:

GET https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=otpauth://totp/MyLabel?secret=THESECRET 400 (Bad Request)

生成二维码的代码:

try
key = crypto.randomBytes(10).toString('hex')
catch error
console.log "error generating code: #{error}"
encoded = base32.encode(key)
label = encodeURIComponent "MyLabel"
uri = "otpauth://totp/#{label}?secret=#{encoded}"
url = "https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=#{uri}"

插入图像的客户端jQuery:

img = $("<img>").attr("src", url)
$("#qr_box").html("")
$("#qr_box").append(img)

这会在页面上生成以下 HTML:

<img src="https://www.google.com/chart?chs=200x200&amp;chld=M|0&amp;cht=qr&amp;chl=otpauth://totp/MyLabel?secret=THESECRET">

图像可以在新选项卡中打开而不会出现问题。该图像仅在大约 1/10 的时间内成功显示在我的页面中;其他时候 Chrome 给出了 400。我在这里遗漏了一些明显的东西吗?

最佳答案

对我来说,它改变了 https://www.google.com https://chart.googleapis.com .

关于node.js - 尝试为 Google 身份验证器插入 QR 码图像时出现 400 Bad Request,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17071368/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com