Firebase + Ionic3 Error: disallowed_useragent

只谈情不闲聊 提交于 2019-12-23 09:29:53

问题


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?


回答1:


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



回答2:


try this

ionic cordova build android --minifycss --optimizejs --minifyjs

solved for me




回答3:


I highly suggest you to run this on the real device since Ionic view app has a lot of issues with native plugins and etc.

CLI

ionic cordova run android --prod --device

or

ionic cordova run ios --prod --device


来源:https://stackoverflow.com/questions/47237896/firebase-ionic3-error-disallowed-useragent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!