Firebase + Ionic + Cordova s​​ignInWithRedirect在Android上重定向到localhost

And*_*ani 5 android cordova firebase ionic-framework firebase-authentication

经过一系列更新,我最近重新构建了Ionic应用程序,并signInWithRedirect停止在Android上运行,并在登录后重定向到localhost:8080,而在iOS上还可以。

这是我的package.json

{
  ...
  "dependencies": {
    ...,
    "firebase": "5.4.2",
    "@angular/fire": "5.0.0",
    "@ionic-native/firebase": "4.12.2",
    "cordova-plugin-browsertab": "^0.2.0",
    "cordova-plugin-buildinfo": "2.0.2",
    "cordova-plugin-customurlscheme": "4.3.0",
    "cordova-plugin-firebase": "2.0.0",
    "cordova-plugin-ionic-webview": "2.1.4",
    "cordova-universal-links-plugin": "git+https://github.com/andyepx/cordova-universal-links-plugin.git#b91b58fb8a7ff9f2b2de83b4adceece13e9cf2a8",
  },
  ...
  "cordova": {
    "plugins": {
      ...
      "cordova-plugin-local-notification": {},
      "cordova-plugin-firebase": {},
      "cordova-plugin-browsertab": {},
      "cordova-universal-links-plugin": {}
    },
}
Run Code Online (Sandbox Code Playgroud)

cordova-universal-links-plugin我使用的版本是原始插件的分支,并针对Cordova 8进行了一些修复。

config.xml

<preference name="AndroidLaunchMode" value="singleTask" />

<universal-links>
        <host event="openAppEvent" name="app.my.com" scheme="https" />
        <host name="myapp.page.link" scheme="https" />
        <host name="myapp.app.goo.gl" scheme="https" />
        <host name="myapp.firebaseapp.com" scheme="https">
            <path url="/__/auth/callback" />
        </host>
</universal-links>
Run Code Online (Sandbox Code Playgroud)

还有我正在使用的登录代码段:

// this.firebaseLogin is an instance of AngularFireAuth

return this.firebaseLogin.auth.signInWithRedirect(new auth.GoogleAuthProvider())
      .then(() => {
        return this.firebaseLogin.auth.getRedirectResult()
          .then(x => authCallback(x))
      })
Run Code Online (Sandbox Code Playgroud)

我找不到此配置的问题,尤其是它在iOS上完美运行时...

Pau*_*sma 8

使用这些版本:

"cordova-android": "^8.0.0",
"cordova-plugin-browsertab": "0.2.0",
"cordova-plugin-buildinfo": "2.0.3",
"cordova-plugin-compat": "1.2.0",
"cordova-plugin-device": "2.0.3",
"cordova-plugin-inappbrowser": "3.1.0",
"cordova-plugin-whitelist": "1.3.4",
"cordova-universal-links-plugin-fix": "1.2.1",
"firebase": "^5.9.4",
"cordova-universal-links-plugin": "~1.2.1",
"@angular/fire": "^5.1.2"
Run Code Online (Sandbox Code Playgroud)

我能够通过将以下内容添加到我的中来解决这个问题config.xml

<allow-navigation href="http://*" />
<allow-navigation href="https://*" />
Run Code Online (Sandbox Code Playgroud)

然而,我得到了一个 403 错误:(disallowed_useragent类似于在这个 SO 问题中)我设法通过添加以下行来修复config.xml

<preference name="OverrideUserAgent" value="Mozilla/5.0 Google" />
Run Code Online (Sandbox Code Playgroud)


And*_*ani 3

经过进一步探索并遵循上面的 @bojeil 建议,结果发现它 cordova-plugin-ionic-webview@latest运行一个集成的网络服务器,http://localhost:8080该服务器与 Firebase SDK 查找 Cordova / 处理重定向的方式不兼容。

因此,目前可行的解决方案是使用 Firebase "cordova-plugin-ionic-webview": "1.2.1",并希望 Firebase 在即将推出的 JS SDK 版本中解决此问题。

我也在这里提出了这个问题https://github.com/firebase/firebase-js-sdk/issues/1244