在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:
在使用带有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>
通过iPhone上的Facebook应用程序内浏览器打开时,如何登录才能工作?