问题描述
我试图建立双因素认证与谷歌身份验证我的网站上。我能够生成工作codeS,但是当我插入图像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)
在code生成QR code:
The code to generate the QR code:
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&chld=M|0&cht=qr&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?
推荐答案
对于我来说,努力改变的 的到的 的
For me it worked to change https://www.google.com to https://chart.googleapis.com.
这篇关于400错误的请求时试图插入QR code图像谷歌的Authenticator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!