尝试为 Google Authenticator 插入 QR 码图像时出现 400 Bad Request [英] 400 Bad Request when attempting to insert QR code image for Google Authenticator

查看:21
本文介绍了尝试为 Google Authenticator 插入 QR 码图像时出现 400 Bad Request的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to set up two-factor authentication with Google Authenticator on my site. I'm able to generate working codes, but when I insert the image URL into the page, I get the following error in Chrome inspector:

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:

Client-side jQuery that inserts the image:

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

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

Which results in the following HTML on the page:

<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.我在这里遗漏了一些明显的东西吗?

The image can be opened in a new tab without a problem. The image is only successfully displayed in my page about 1/10 the time; the other times Chrome gives a 400. Am I missing something obvious here?

推荐答案

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

For me it worked to change https://www.google.com to https://chart.googleapis.com.

这篇关于尝试为 Google Authenticator 插入 QR 码图像时出现 400 Bad Request的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆