GithubHelp home page GithubHelp logo

Comments (22)

vicjohnson1213 avatar vicjohnson1213 commented on August 26, 2024 21

For any still looking for the answer to this question, @jamescodesthings has a note in the documentation for cordova-plugin-recaptcha:

Provided the reCAPTCHA's domains to check includes 'localhost' and your app's config.xml includes:

<allow-navigation href="https://www.google.com/recaptcha/*" />

This addition got reCaptcha working for me in iOS. (reCaptcha was working out of the box on Android)

from recaptcha.

amostsai avatar amostsai commented on August 26, 2024 10

please see https://stackoverflow.com/questions/41518787/recaptcha-integration-with-ionic-hybrid-app/45364099#45364099

from recaptcha.

k-sai-kiranmayee avatar k-sai-kiranmayee commented on August 26, 2024 4

Hello @vicjohnson1213, I'm using Cordova too, have disabled the domain validation, still, getting the error Error for site owner. Invalid domain for site key, tried this <allow-navigation href="https://www.google.com/recaptcha/*" /> (however didn't install the plugin)
As discussed/mentioned in various forums since Cordova doesn't contain a domain name, all the files are accessed using file://)
Any suggestions/help, please!

from recaptcha.

fermedina avatar fermedina commented on August 26, 2024 1

@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.

from recaptcha.

jamescodesthings avatar jamescodesthings commented on August 26, 2024 1

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:

import {provide} from '@angular/core';
bootstrap(..., [provide(Window, {useValue: window})]);

constructor(private window: Window) {
    // this.window
}

Then just use the plain js from window:

window.plugins.recaptcha.verify('site-key', success_callback, fail_callback);

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.

from recaptcha.

bluesliverx avatar bluesliverx commented on August 26, 2024

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

from recaptcha.

fermedina avatar fermedina commented on August 26, 2024

Any update about this?

from recaptcha.

jamescodesthings avatar jamescodesthings commented on August 26, 2024

@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 localhost as a whitelisted domain. The reason this works is the Ionic Web View uses a local server to help with CORS on iOS. So your app has a domain which is localhost:8080.

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 platform is iOS before serving the web recaptcha key with the site key for our web recaptcha. In the android version we check platform is android before making a call to the cordova plugin.

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.

from recaptcha.

rowan-m avatar rowan-m commented on August 26, 2024

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 v1.2 branch, so that may help. Let me know if there's something you need in the library here.

from recaptcha.

nombrekeff avatar nombrekeff commented on August 26, 2024

Any updates on this? We are facing the same issue. And we need to use it in our project.
We tried everything said in this post and a bunch of other things.

from recaptcha.

rr-phillips avatar rr-phillips commented on August 26, 2024

For any still looking for the answer to this question, @jamescodesthings has a note in the documentation for cordova-plugin-recaptcha:

Provided the reCAPTCHA's domains to check includes 'localhost' and your app's config.xml includes:

<allow-navigation href="https://www.google.com/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!!

from recaptcha.

filipencus avatar filipencus commented on August 26, 2024

Some updates on this? Thanks.

from recaptcha.

vicjohnson1213 avatar vicjohnson1213 commented on August 26, 2024

@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

from recaptcha.

k-sai-kiranmayee avatar k-sai-kiranmayee commented on August 26, 2024

Thank you @vicjohnson1213 for the quick response and suggestion :)
I have already seen that question, however, in my case, the domain check is already disabled :( and I'm still getting that issue in the Cordova native app (works fantastically in web and mobile browser)
In https://www.google.com/recaptcha/admin, at the time of registration, we must specify at least one domain, later have unchecked the below and saved it
image
So now there won't be any domain validation right?
Any more information as to this origin (file://), please

Thank you!

from recaptcha.

vicjohnson1213 avatar vicjohnson1213 commented on August 26, 2024

@k-sai-kiranmayee I doubt it's an issue with the file:// protocol since I haven't had any issues around that. Do you have localhost in your list of allowed domains? I'm not too sure exactly what that checkbox does, so it might be worth trying.

from recaptcha.

k-sai-kiranmayee avatar k-sai-kiranmayee commented on August 26, 2024

I doubt it's an issue with the file:// protocol since I haven't had any issues around that

@vicjohnson1213 Oh! Thank you, just a quick question, have you installed any plugin or other changes for this in cordova.xml or only <allow-navigation href="https://www.google.com/recaptcha/*" /> this is added?

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 :)

from recaptcha.

vicjohnson1213 avatar vicjohnson1213 commented on August 26, 2024

@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.

from recaptcha.

k-sai-kiranmayee avatar k-sai-kiranmayee commented on August 26, 2024

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
Thank you for the help till now, and please do tell me if you find anymore :)

from recaptcha.

k-sai-kiranmayee avatar k-sai-kiranmayee commented on August 26, 2024

Hello, @vicjohnson1213 One more question please, which reCaptcha are you using?

from recaptcha.

vicjohnson1213 avatar vicjohnson1213 commented on August 26, 2024

@k-sai-kiranmayee I think we're using invisible v2.

from recaptcha.

k-sai-kiranmayee avatar k-sai-kiranmayee commented on August 26, 2024

oh, thank you @vicjohnson1213, so following this SafetyNet reCAPTCHA API?

from recaptcha.

AzurDrive avatar AzurDrive commented on August 26, 2024

Hello, everyone!
Has someone been lucky to fully clearing this out?

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

*COMMON*
 <access origin="https://*.google.com/*"/>
 <allow-navigation href="*://localhost"/>
 <allow-navigation href="https://www.google.com/recaptcha/*" />
    
platform=ios
 <preference name="Hostname" value="myapp.local" /> (cordova-plugin-ionic-webview)
 <allow-navigation href="http://myapp.local/*" />
 <allow-navigation href="https://www.google.com/recaptcha/*" />
        
 and in my google recaptcha console i have _localhost and myapp.local_ declared

still cant get it work on cordova iOS and Android.
Help, anyone?

from recaptcha.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.