令人惊讶的是,当这两种产品都是Google产品时,甚至更多-我可以找到no信息,了解如何将Recaptcha与Firebase集成在一起。可能吗如果没有,我该如何使用没有身份验证的Firebase应用程序来验证人员?
这是一篇很老的文章,但这是对像我这样的Google搜索者的解答。现在它是内置的,并且超级容易设置:
window.recaptchaVerifier = new firebase.auth.RecaptchaVerifier('recaptcha', {
'callback': (response) => {
// reCAPTCHA solved, allow signInWithPhoneNumber.
// ...
},
'expired-callback': () => {
// Response expired. Ask user to solve reCAPTCHA again.
// ...
}
})
window.recaptchaVerifier.render()
正如tuananh提到的,请确保您添加了<div id="recaptcha"></div>
。
我刚刚发布了一篇tutorial blog,内容涉及如何使用Firebase Hosting为网站提供内容和Cloud Function来验证从reCAPTCHA收到的响应,从而将reCAPTCHA集成到网站中。该函数本身看起来像这样,假设通过查询字符串接收到响应令牌:
const functions = require('firebase-functions')
const rp = require('request-promise')
exports.checkRecaptcha = functions.https.onRequest((req, res) => {
const response = req.query.response
console.log("recaptcha response", response)
rp({
uri: 'https://recaptcha.google.com/recaptcha/api/siteverify',
method: 'POST',
formData: {
secret: 'PASTE_YOUR_SECRET_CODE_HERE',
response: response
},
json: true
}).then(result => {
console.log("recaptcha result", result)
if (result.success) {
res.send("You're good to go, human.")
}
else {
res.send("Recaptcha verification failed. Are you a robot?")
}
}).catch(reason => {
console.log("Recaptcha request failure", reason)
res.send("Recaptcha request failed.")
})
})
有人在Firebase云功能中使用V3吗?我很难找到最新版本的Recaptcha的资源