-
Notifications
You must be signed in to change notification settings - Fork 771
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Google recaptcha doesn't work with cordova projects #96
Comments
This seems to be a recent change - this used to work with localhost I'm pretty sure, even without localhost defined as one of the domains. UPDATE: This does not actually seem to be recent. The main problem is that file: is used as the protocol for cordova projects. See here for the clearest description of what's going on: https://groups.google.com/forum/#!topic/recaptcha/AuN2f7JrZTA |
Any update about this? |
@fermedina or any other poor soul who ends up here. I'll write this up a little better once it's production ready for my org, but to help in the mean time: You can use a web recaptcha on iOS using the Ionic Web View, provided your recaptcha includes For Android it's a little more difficult, because your app won't have a domain, I investigated doing similar in Android as Ionic's Web View does for iOS (serving the app locally) but this leads to further complications. More than it's worth. So, in lieu of a great solution I wrapped the Android Recaptcha code in a Cordova Plugin. You can find it here: cordova-plugin-recaptcha. To do this you need an Android Recaptcha key, so your server-side may also need to account for multiple recaptcha sources. We did this by passing a flag for android to switch between the iOS and Android secret keys when validating the recaptcha. In our own implementation in the cordova app, I then used cordova-plugin-device to check that the I can't guarantee it passes App Store Review as our app isn't yet in Prod, but it works as we need it to, validating recaptcha with our public-facing services for both android and iOS. If you go down this route and have any trouble with the plugin please let me know. At the moment it hot-loads an Angular 1.x service in the js code because this was what we needed in our solution, but I could happily take this out if it causes anyone more trouble than its worth. I can also publish to NPM if it's of benefit, we originally planned to publish to our org's NPM repo but cordova doesn't play well with organisation scoped packages so we've held off, we can quite happily publish as a plain old NPM package upon request. |
@jamescodesthings very thanks! your plugin is for Angular 1, right? I need this functionality for Angular 2 or higher. I don't know how to use your plugin in my template. |
No worries, it's a mixture of plain JS and Angular 1, but I kept to a fairly plain plugin format so that this wouldn't be too big a problem when I chuck it in an NG 2+ project. Bear with me, it's been a little while since I did this in NG 2+. In theory you can just use the plain JS version without too much hassle. You could create a service that then has access to the window object. From SO, something like:
Then just use the plain js from window:
In practice it depends a little on what your template is, do you have a public copy or an idea of how you're currently working? I could help fudge it on in. |
This sounds like it would make a pretty good blog post. I'm also updating the library to support Android app validation amongst other things on the |
Any updates on this? We are facing the same issue. And we need to use it in our project. |
For any still looking for the answer to this question, @jamescodesthings has a note in the documentation for cordova-plugin-recaptcha:
This addition got reCaptcha working for me in iOS. (reCaptcha was working out of the box on Android) |
this literally saved me, i looked for a few hours and this was the thing that was missing, thank you!! |
Hello @vicjohnson1213, I'm using Cordova too, have disabled the domain validation, still, getting the error |
Some updates on this? Thanks. |
@k-sai-kiranmayee I'm not sure about that one. Sounds more like an issue with the ReCaptcha configuration more than the Cordova setup. I wish I had more to help, but this Stack Overflow question has a few things you might want to try: https://stackoverflow.com/questions/30735694/recaptcha-error-invalid-domain-for-site-key |
Thank you @vicjohnson1213 for the quick response and suggestion :) Thank you! |
@k-sai-kiranmayee I doubt it's an issue with the |
@vicjohnson1213 Oh! Thank you, just a quick question, have you installed any plugin or other changes for this in cordova.xml or only And yes, tried your suggestion, have added only by adding localhost as domain, still the same :( And really thank you for your help and responses :) |
@k-sai-kiranmayee Yeah, I was using the angular2-reacaptcha package (this was an Ionic app, hence the angular). But I can't see anything else in our code that I think would have any effect. |
oh...Okay...I see that package is for the usage of ReCaptcha @vicjohnson1213 I'm using Vue, so used this vue-recaptcha-v3 and ours is a Cordova app built using Bitrise |
Hello, @vicjohnson1213 One more question please, which reCaptcha are you using? |
@k-sai-kiranmayee I think we're using invisible v2. |
oh, thank you @vicjohnson1213, so following this SafetyNet reCAPTCHA API? |
Hello, everyone! I have reCaptcha V3, and on my Cordova iOS app there is no window.grecaptcha object, means link to script is not even attached. I have somewhat following settings
still cant get it work on cordova iOS and Android. |
since cordova projects don't contain domain name the recaptcha throws
ERROR for site owner invalid domain for site key
The text was updated successfully, but these errors were encountered: