用reCATPCHA响应本机 [英] React Native with reCATPCHA

查看:57
本文介绍了用reCATPCHA响应本机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的React本机应用程序中实现

我有一种理论,它不想合作,因为我在 WebView 中将其作为文件"运行,并且您不能将文件作为Google域中的一部分添加仪表盘.

是否可以通过任何方式在Google的reCAPTCHA仪表板中添加 file://权限或以任何方式伪造域,以便可以在该仪表板中添加该伪造的域.还是我完全迷路了,而问题又是什么?

解决方案

您可以通过在

I'm trying to implement the google reCAPTCHA in my react native app. I'm using a wrapped webview.

<WebView 
    javaScriptEnabled={true} 
    mixedContentMode={'always'} 
    style={{height: 200}} 
    source={{
        html: this.getWebviewContent()
    }}/>


getWebviewContent(){
    var originalForm = '<!DOCTYPE html><html><head><script src="https://www.google.com/recaptcha/api.js"></script></head><body><form action="[POST_URL]" method="post"><input type="hidden" value="[TITLE]"><input type="hidden" value="[DESCRIPTION]"><input type="hidden" value="[URL]"><div class="g-recaptcha" data-sitekey="<My key>"></div><input type="submit" value="Send"/></form></body></html>'
    var tmp =  originalForm
        .replace("[POST_URL]", "http://localhost:3000/v1/video")
        .replace("[TITLE]", this.state.form.title)
        .replace("[DESCRIPTION]", this.state.form.description)
        .replace("[URL]", this.state.form.url); 

    return tmp; 
}

If I render it, it gives me the following error:

I have a theory that it doesn't want to cooperate since I'm running it as a "file" in the WebView and that you cannot add files as part of the domain in the Google dashboard.

Is there any way of either added file:// permissions in the reCAPTCHA dashboard of Google or any way of faking a domain, so that I can add that faked domain in the dashboard. Or am I completely lost and the issue is something else?

解决方案

You can set a domain for your WebView by setting baseUrl in source prop:

<WebView 
    javaScriptEnabled={true} 
    mixedContentMode={'always'} 
    style={{height: 200}} 
    source={{
        html: this.getWebviewContent(),
        baseUrl: 'http://your-domain.com' // <-- SET YOUR DOMAIN HERE
    }}/>


getWebviewContent(){
    var originalForm = '<!DOCTYPE html><html><head><script src="https://www.google.com/recaptcha/api.js"></script></head><body><form action="[POST_URL]" method="post"><input type="hidden" value="[TITLE]"><input type="hidden" value="[DESCRIPTION]"><input type="hidden" value="[URL]"><div class="g-recaptcha" data-sitekey="<My key>"></div><input type="submit" value="Send"/></form></body></html>'
    var tmp =  originalForm
        .replace("[POST_URL]", "http://localhost:3000/v1/video")
        .replace("[TITLE]", this.state.form.title)
        .replace("[DESCRIPTION]", this.state.form.description)
        .replace("[URL]", this.state.form.url); 

    return tmp; 
}

这篇关于用reCATPCHA响应本机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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