Firebase + Ionic3 错误:disallowed_useragent [英] Firebase + Ionic3 Error: disallowed_useragent
问题描述
关于这个主题还有几个其他问题/答案,但他们没有将 Firebase 与 Ionic 一起使用.我刚刚切换到新的 Ionic View,现在,我在旧的 Ionic View 中的应用程序可以工作,而新的 Ionic View 给了我这个众所周知的错误:
<块引用>403 错误 - 这是一个错误.错误:disallowed_useragent 他的用户代理不允许向 Google 发出 OAuth 授权请求,因为它被归类为嵌入式用户代理(也称为网络视图).呸呸呸
在我的代码中,我注入了 Firebase AuthProvider 并使用 angularfire2 进行连接,它看起来像
private getProvider(from: string): AuthProvider {切换(从){案例推特":返回新的 firebase.auth.TwitterAuthProvider();case 'facebook': 返回新的 firebase.auth.FacebookAuthProvider();case 'github':返回新的 firebase.auth.GithubAuthProvider();case 'google':返回新的 firebase.auth.GoogleAuthProvider();}}登录(来自:字符串){this.afAuth.auth.signInWithPopup(this.getProvider(from))...
同样,这在浏览器或旧的 Ionic 中效果很好,但不适用于新的 Ionic 视图.我确实有一个相当大的带有通用 OAuth 连接的库,但我认为使用 Firebase 的一个重要原因是我们不再需要使用这些库并自己管理用户.
有没有办法通过 Ionic 在 iOS/Android 应用上进行 Firebase 身份验证?
您应该按照 这篇文章.我认为不支持 signInWithPopup
方法,您应该尝试使用 signInWithRedirect
代替.
通过将以下内容添加到我的 config.xml
中,我设法修复了 disallowed_useragent
错误:
There are a couple of other questions/answers on this topic, but they were not using Firebase with Ionic. I just switched to the new Ionic View and right now today, my app in the old Ionic View works while the new Ionic View gives me this well known error:
403 Error - Thats an error. Error: disallowed_useragent his user-agent is not permitted to make an OAuth authorization request to Google as it is classified as an embedded user-agent (also known as a web-view). blah blah blah
In my code I inject the Firebase AuthProvider and use angularfire2 to connect and it looks like
private getProvider(from: string): AuthProvider {
switch (from) {
case 'twitter': return new firebase.auth.TwitterAuthProvider();
case 'facebook': return new firebase.auth.FacebookAuthProvider();
case 'github': return new firebase.auth.GithubAuthProvider();
case 'google': return new firebase.auth.GoogleAuthProvider();
}
}
signIn(from: string) {
this.afAuth.auth.signInWithPopup(this.getProvider(from))
. . .
Again, this works great in the browser or old Ionic but not the new Ionic View. I do have a fairly big library with general OAuth connections, but I thought that one of the great reasons to use Firebase is that we would no longer have to use those libraries and manage users ourselves.
Is there a way to do the Firebase auth on an iOS/Android app via Ionic?
You should follow the instructions in this article. I don't think signInWithPopup
method is supported, you should try signInWithRedirect
instead.
I managed to fix the disallowed_useragent
error by adding the following to my config.xml
:
<preference name="OverrideUserAgent" value="Mozilla/5.0 Google" />
这篇关于Firebase + Ionic3 错误:disallowed_useragent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!