Firebase + Ionic + Cordova signInWithRedirect重定向到Android上的lo



经过一系列更新后,我最近重新构建了我的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": {}
},
}

我正在使用的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>

以及我正在使用的登录代码段:

// 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))
})

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

对于这些版本:

"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"

我能够通过向我的config.xml添加以下内容来解决此问题:

<allow-navigation href="http://*" />
<allow-navigation href="https://*" />

但是,我得到了一个 403 错误:disallowed_useragent(类似于这个 SO 问题(,我设法通过将以下行添加到config.xml来修复它:

<preference name="OverrideUserAgent" value="Mozilla/5.0 Google" />

经过进一步探索,并按照上面的建议@bojeil结果是cordova-plugin-ionic-webview@latest运行一个集成的网络服务器,http://localhost:8080与Firebase SDK查找Cordova/处理重定向的方式无关。

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

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

最新更新