Firebase和angularFire-从Google身份验证获取电子邮件使用$authWithOAuthPopup,但使用$authWithOAuthRedirect失败
下面的代码片段可以工作,除非用户的浏览器配置(例如带有Chrome的iOS)将其发送到$authWithOAuthRedirect块,否则它将失败 所谓失败,我的意思是$authWithOAuthRedirect方法可以工作,用户可以批准身份验证,但它无法将作用域正确发送到Google,并且不请求电子邮件访问Firebase和angularFire-从Google身份验证获取电子邮件使用$authWithOAuthPopup,但使用$authWithOAuthRedirect失败,firebase,angularfire,Firebase,Angularfire,下面的代码片段可以工作,除非用户的浏览器配置(例如带有Chrome的iOS)将其发送到$authWithOAuthRedirect块,否则它将失败 所谓失败,我的意思是$authWithOAuthRedirect方法可以工作,用户可以批准身份验证,但它无法将作用域正确发送到Google,并且不请求电子邮件访问 var provider = 'google'; var scope = {scope:'email'}; var auth = $firebaseAuth(FirebaseInstanc
var provider = 'google';
var scope = {scope:'email'};
var auth = $firebaseAuth(FirebaseInstance.firebase);
auth.$authWithOAuthPopup(provider, scope).then(function (authData, error) {
if (error && error.code === "TRANSPORT UNAVAILABLE") {
auth.$authWithOAuthRedirect(provider, function(error) {}, scope);
}
});
简化后,此代码将无法请求用户的电子邮件:
var provider = 'google';
var scope = {scope:'email'};
var auth = $firebaseAuth(FirebaseInstance.firebase);
auth.$authWithOAuthRedirect(provider, function(error) {}, scope);
谢谢你的帮助 我认为问题在于您使用的是非角度版本的语法:Firebase.authWithOAuthRedirect(provider[,callback,scope]) 您应该使用AngularFire版本: $firebaseAuth.$authWithOAuthRedirect(提供程序[,选项]) 此版本返回承诺,因此您的简化代码应如下所示:
var provider = 'google';
var scope = {scope:'email'};
var auth = $firebaseAuth(FirebaseInstance.firebase);
auth.$authWithOAuthRedirect(provider, scope).then(function (authObject) {
// Handle success
}, function (error) {
// Handle error
});
天哪,这起作用了。我在某个地方读到,我们不能期望$authWithOAuthRedirect提供承诺,所以我使用了回调版本。这就是问题所在。似乎我们无法在这些块中真正处理授权,而必须在其他地方处理
FirebaseInstance.firebase.onAuth(function(authData){…})
。“无法真正处理”。。。不知道那是什么意思。它很好用。但是,是的,onAuth()将更加有用,因为除了$authWith之外,还有其他因素。。。调用会影响身份验证状态(令牌过期、在初始页面加载时登录等)。因此,要查看身份验证状态,onAuth()将是合适的。