Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.7k views
in Technique[技术] by (71.8m points)

angular - reCAPTCHA Ionic/cordova on Android

i'm facing an issue with reCaptcha for Android on my Ionic app. I use https://github.com/DethAriel/ng-recaptcha in my form like this :

<ion-list no-lines>
   <ion-item no-padding>
      <ion-input [(ngModel)]="form.email" (ionChange)="checkButton()" name="email" type="email" placeholder="{{ 'pages.get_started.slide_1.input_1' | translate }}" clearInput="true"></ion-input>
   </ion-item>
   <ion-item no-padding>
      <ion-input [(ngModel)]="form.username" (ionChange)="checkButton()" name="username" type="text" placeholder="{{ 'pages.get_started.slide_1.input_2' | translate }}" clearInput="true"></ion-input>
   </ion-item>
   <ion-item no-padding>
      <ion-input [(ngModel)]="form.password" (ionChange)="checkButton()" name="password" type="password" placeholder="{{ 'pages.get_started.slide_1.input_3' | translate }}" clearInput="true"></ion-input>
   </ion-item>
   <ion-item no-padding>
      <re-captcha [(ngModel)]="form.captcha" (ionChange)="checkButton()" (resolved)="checkButton()" #captchaControl="ngModel" name="captcha" siteKey="{{ captchaKey }}" required></re-captcha>
   </ion-item>
</ion-list>

I use the correct public key with reCaptcha for Android. So normally it will check my package name. But i'm having a popup : Cannot contact reCAPTCHA service. Check your connection and try again. plus a Domain not valid for the sitekey. on reCaptcha view.

I had tried multiple package name in case it was that but no result. I'm testing this on my phone with no debug arguments so no localhost or things like this. It's working fine on browser platform with respective public key.

What can I do for resolve this ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I ran through the same problem and the solution in my case was to add the cordova webview plugin. This way, it's not needed the ReCaptcha for android, it will work with the reCaptcha for websites.

Uninstall it if you already have installed: cordova plugin rm cordova-plugin-ionic-webview

Install latest version: cordova plugin add cordova-plugin-ionic-webview@latest

I used the Ngx-Captcha version 5.0.4 to be able to use on ionic 3. Currently, I'm using the reCaptcha V3, but it works to version 2 too.

[IOS]

In order to reCaptcha work in IOS with the WebView, you need to add the following to the config.xml: <allow-navigation href="https://www.google.com/recaptcha/*" />

Don't forget to add 'localhost' domain in the reCaptcha console.

For more details on how to use the ngx-captcha, check this question: how can I install correctly ngx-recaptcha on my project?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...