Jes*_*tte 3 firebase angularfire
以下代码段有效,除非用户的浏览器配置(例如iOS与Chrome)将其发送到$ authWithOAuthRedirect块 - 然后失败.
如果失败,我的意思是$ authWithOAuthRedirect方法有效,用户可以批准身份验证,但无法将范围正确发送给Google,也不会请求电子邮件访问.
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);
}
});
Run Code Online (Sandbox Code Playgroud)
简化后,此代码将无法请求用户的电子邮件:
var provider = 'google';
var scope = {scope:'email'};
var auth = $firebaseAuth(FirebaseInstance.firebase);
auth.$authWithOAuthRedirect(provider, function(error) {}, scope);
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助!
我认为问题在于您使用的是非角度版本的语法:Firebase.authWithOAuthRedirect(provider [,callback,scope])
你应该使用AngularFire版本:$ firebaseAuth.$ authWithOAuthRedirect(provider [,options])
此版本返回一个承诺,因此您的简化代码应如下所示:
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
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
733 次 |
| 最近记录: |