ionic-team / capacitor

Build cross-platform Native Progressive Web Apps for iOS, Android, and the Web ⚡️
https://capacitorjs.com
MIT License
11.31k stars 962 forks source link

[Bug]: Android ERR_CONNECTION_REFUSED when redirecting from external url back to https://localhost #7367

Open atremel opened 2 months ago

atremel commented 2 months ago

Capacitor Version

Latest Dependencies:

@capacitor/cli: 5.7.4 @capacitor/core: 5.7.4 @capacitor/android: 5.7.4 @capacitor/ios: 5.7.4

Installed Dependencies:

@capacitor/cli: 5.7.3 @capacitor/core: 5.7.3 @capacitor/android: 5.7.3 @capacitor/ios: 5.7.3

[success] Android looking great! 👌

Other API Details

npm --version -> 10.2.1
node --version -> v18.18.0

Platforms Affected

Current Behavior

The app is redirecting to an external auth service. From there the user is redirected 302 back to https://localhost, where the browser blocks the request saying ERR_CONNECTION_REFUSED:

image

HTTPS is encouraged: "we would strongly recommend that you change your androidScheme to use https."

capacitor.config.ts looks like this:

import { CapacitorConfig } from '@capacitor/cli';

const config: CapacitorConfig = {
  appId: 'com.somedomain.app',
  appName: 'App',
  webDir: 'dist/prod',
  server: {
    androidScheme: 'https',
    allowNavigation: [
      "login.somedomain.com"
    ]
  },
  plugins: {
    CapacitorHttp: {
      enabled: true,
    },
  },
};

export default config;

Expected Behavior

Redirect to https://localhost is successful.

Project Reproduction

https://github.com/atremel/redir

Additional Information

Real device has this issue, too.

atremel commented 1 month ago

Just posting an update - Ionic 6 now requires https by default:

image

Any updates on this issue? It really blocks us from migrating our native apps to Ionic / Capacitor...

Benno08 commented 2 weeks ago

We've got the same issue (with Capacitor 5/6). #5818 is about the same issue but was closed because set as duplicate of #4240 (by mistake to me, because is does not fix the issue at all as said by this comment https://github.com/ionic-team/capacitor/issues/4240#issuecomment-1249304440). Redirecting from an external URL to localhost on Android doesn't work. PR here about the same issue was not considered either: https://github.com/ionic-team/capacitor/pull/5872

Might be related to this one (with Capacitor 6 example) as well: https://github.com/ionic-team/capacitor/issues/7454