我们在发送reCAPTCHA令牌进行评估时遇到错误。
令牌是在客户端上使用
重新获取企业.xsf框架
并且应该从我们的后端发送到谷歌。
这是实例化客户端的代码:
private func activateReCAPTCHA() {
_Concurrency.Task {
if #available(iOS 14.0, *) {
let (recaptchaClient, error) = await Recaptcha.getClient(Resources.recaptchaKey)
if let error {
print("RecaptchaClient creation error: \(String(describing: error.errorMessage)).")
error.reportToExternalServices()
} else if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
appDelegate.recaptchaClient = recaptchaClient
print("RecaptchaClient created.")
} else {
print("RecaptchaClient creation error: AppDelegate not available.")
}
sleep(0)
}
}
}
这是请求和接收令牌的代码:
extension RecaptchaClient {
static var client: RecaptchaClient? {
if #available(iOS 14.0, *) {
return (UIApplication.shared.delegate as? AppDelegate)?.recaptchaClient
} else {
return nil
}
}
}
private func fetchReCAPTCHAToken() {
guard let recaptchaClient = RecaptchaClient.client else {
print("fetchReCAPTCHAToken: RecaptchaClient not found")
return
}
if #available(iOS 14.0, *) {
Task {
let (token, error) = await recaptchaClient.execute(RecaptchaAction(action: .login))
if let token = token {
print("fetchReCAPTCHAToken: \(token.recaptchaToken)")
} else {
print("fetchReCAPTCHAToken: \(String(describing: error?.errorMessage))")
}
sleep(0)
}
}
}
到目前为止一切都很好。
为了模拟后端,我创建了一个cURL脚本,该脚本发送以下json,并从xCode控制台粘贴生成的令牌:
{
"event": {
"token": "...",
"siteKey": "...",
"expectedAction": "login"
}
}
方法是POST,URL的结构如下:
https://recaptchaenterprise.googleapis.com/v1/projects/.../assessments?key=..
。
答复:
{
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"status": "INVALID_ARGUMENT"
}
}
我们对邮差也做了同样的事情,得到了同样的结果。
这可能是什么原因?
----更新----
我们最终通过以下操作得到了有效的响应:
-
登录谷歌云控制台
-
从CLI中,运行指向以下地址的cURL:
”https://recaptchaenterprise.googleapis.com/v1/projects/.../assessments?access_token=$(gcloud auth-print访问令牌)“
与以前的尝试相比,唯一的区别是CLI脚本使用OAUTH2 access_token=而不是key=。
因此,我们得出结论,问题可能出在key=论点中。我们用于key=参数的值是
秘密密钥
其具有以下描述:
使用此密钥在您的网站和reCAPTCHA之间进行通信
.这个问题仍然对任何有线索的人开放。