Firebase身份验证无法从iPhone上的Facebook Messenger发送

时间:2019-02-20 00:15:21

标签: angular firebase firebase-authentication angularfire2 google-login

在Android上一切正常。但是使用iPhone时,通过facebook Messenger应用程序内浏览器打开我的网站时,它不会让用户登录。

使用AngularFireAuth时,我的代码如下:

glogin() {
    this.socialLogin(new auth.GoogleAuthProvider());
  }

socialLogin(provider) {
    this.afAuth.auth.signInWithPopup(provider)
      .then((user) => {
        this.loading = true;
        console.log('Sign in with google: ', user);
      }).catch(() => {
      // Todo - something went wrong
    });
  }

我通过fb Messenger打开链接,单击用google登录(在上面的代码示例中触发glogin()),它只是显示一个空白屏幕(但仍在我的测试网站上)。不会问我要使用哪个Gmail帐户登录。它转到的页面具有以下URL:

https://MY_PROJECT_ID.firebaseapp.com/__/auth/handler?state=AMbdmDm9Cks7LNtcBWVNFTRJ_NKOw2TwSuEG0EX1u0YGpffYFhUdpzuT9GDQgKgTJFv8tOHNefO31BZMv2QDY_6QOIh90u0nJ2DP-xkxh9znGp624dDfCPFixxSNMhh6FWnlDywktHfasAmKviDhYs5ECZlGqoZ1nakad9eclnoeBsc_roh8z8hSYpW0hBNsAm67z2QbVGOblbIP0yiced8fYyMalE4C4MhtJSWEPOpSa3Pj2fa1J4JBnQk7Iq9POHbfQdwcJ4n1p1kRbitSbZiExkGGZNUrRW7vXFI1gF2tlMoNzvTG_VO76498CYV_WTcIUSphOgKhLg&code=4/9wBIt9xh3e13xl0d8rfrxmuonTzApq_8VeBgeXQbtx4nwepp81OHP74865RaMTU0NN7SXoHebg4VWwLijmpkDvU&scope=openid+email+profile+https://www.googleapis.com/auth/userinfo.email+https://www.googleapis.com/auth/userinfo.profile&authuser=0&session_state=22688194c8db3806e3fd0cf4d8792ea29e98560d..e46b&prompt=none

在使用带有Firebase的Google登录本机SDK时,我的ts代码如下:

ngOnInit() {
    gapi.load('auth2', () => {
      gapi.auth2.init({client_id: 'MY-CLIENT-ID'});
    });
}

googleSignin() {
    let auth2 = gapi.auth2.getAuthInstance();
    auth2.signIn().then(data => {
      console.log('something worked', data);
      this.onSignIn(data);
    }).catch(err => {
      console.log('error: ', err);
    });
  }

onSignIn(googleUser) {
    console.log('Google Auth Response', googleUser);
    // We need to register an Observer on Firebase Auth to make sure auth is initialized.
    var unsubscribe = firebase.auth().onAuthStateChanged(function(firebaseUser) {
      unsubscribe();

        // Build Firebase credential with the Google ID token.
        var credential = firebase.auth.GoogleAuthProvider.credential(
          googleUser.getAuthResponse().id_token);
        // Sign in with credential from the Google user.
        firebase.auth().signInAndRetrieveDataWithCredential(credential).catch(function(error) {
          // Handle Errors here.
          var errorCode = error.code;
          var errorMessage = error.message;
          // The email of the user's account used.
          var email = error.email;
          // The firebase.auth.AuthCredential type that was used.
          var credential = error.credential;
          // ...
        });
    });
  }

我的html是:

<div class="g-signin2" data-onsuccess="onSignIn" (click)="googleSignin()"></div>

当我单击上面的按钮时,它会转到URL为以下的空白页: https://accounts.google.com/o/oauth2/auth?redirect_uri=storagerelay%3A%2F%2Fhttps%2FMY_PROJECT_ID.firebaseapp.com%3Fid%3Dauth84260&response_type=permission%20id_token&scope=email%20profile%20openid&openid.realm=&client_id=386310437429-kpslqalubgfj2bqg6n9fhhs1295ditsa.apps.googleusercontent.com&ss_domain=https%3A%2F%2FMY_PROJECT_ID.firebaseapp.com&fetch_basic_profile=true&gsiwebsdk=2

通过iPhone上的Facebook应用程序内浏览器打开时,如何登录才能工作?

0 个答案:

没有答案