2

I've looked through a lot of similar issues, but none have seemed to work for me. Our app makes 2 API requests - the first to fetch an OAuth code to our API (works fine) and the other posts that code to the Rails API (which is failing).

I am posting to http://localhost:3000/api/v1/users/auth/openid_connect/callback

But getting net::ERR_CONNECTION_REFUSED. However, this works fine when running on iOS.

My config currently has:

<plugin name="cordova-plugin-whitelist" spec="1" />
<access origin="*" />
<allow-navigation href="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />

I've tried adding <allow-intent href="http://localhost:3000/api/v1/*" /> and <allow-intent href="http://127.0.0.1:3000/api/v1/*" /> and even the full openid_connect/callback URL but none seem to work.

In my index.html, I have

<meta http-equiv="Content-Security-Policy" content="default-src * 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; connect-src * 'unsafe-inline'">

Does the issue lie with how I am handling access origin in the config or do I have the Content-Security-Policy wrong?

sbatson5
  • 648
  • 11
  • 19
  • are you using mobile data for testing?is it working over wifi? – Gandhi Feb 07 '17 at 15:29
  • I'm running through an emulator and using the same API/data as my web app (from my Rails/Postgres app) – sbatson5 Feb 07 '17 at 15:31
  • Is it possible that you have a proxy set up that goes through to your backend? This, of course, wouldn't work on a device where that proxy isn't set up. That's how Ionic does it, excuse me if this is senseless. – Simon Visser Feb 07 '17 at 15:58
  • @sbatson could be a possible proxy issue if it dont work only in device, that's why I raised de question – Gandhi Feb 07 '17 at 17:20
  • Found this issue: http://stackoverflow.com/questions/27119227/cordova-angular-get-to-web-api-connection-refused Changing it from `localhost:3000` to `10.0.2.2:3000` seemed to fix. Will have to force Android to make requests through that domain in development. – sbatson5 Feb 07 '17 at 18:37
  • Changing the domain name like localhost to IP address, solved my problem so you got to change domain in server like nodejs like : app.listen(3000,'192.168.0.103'); and use the IP address in ajax call to the API. – Deepak Bhatta Aug 20 '17 at 15:50

1 Answers1

4

To close the issue, the error was that Android didn't seem to know how to handle localhost. Changing the domain to http://10.0.2.2 solved the problem.

sbatson5
  • 648
  • 11
  • 19