火力地堡角的OAuth与谷歌电子邮件范围,权威性。$ authWithOAuthPopup VS ref.authWithOAuthPopup [英] Firebase Angular OAuth with Google email scope, auth.$authWithOAuthPopup vs ref.authWithOAuthPopup

查看:104
本文介绍了火力地堡角的OAuth与谷歌电子邮件范围,权威性。$ authWithOAuthPopup VS ref.authWithOAuthPopup的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我成功地运用火力地堡的角度图书馆权威性对Facebook和谷歌的用户,但我有麻烦检索用户的电子邮件使用firebaseAuth的$ authWithOAuthPopup时。

I'm successfully using Firebase's angular library to auth users against Facebook and Google, but I'm having troubling retrieving the user's email when using firebaseAuth's $authWithOAuthPopup.

这是我的登录功能。

var ref = new Firebase(FIREBASE_URL);
var auth = $firebaseAuth(ref);      
loginGoogle: function () {
    console.log('Logging in Google.');
    return auth.$authWithOAuthPopup('google', function(error, user){
      //TODO: Handle Failed login better
      console.log('Google login failed');
      console.log(error);
    },{
      scope: 'email'
    });
  };

这会弹出谷歌身份验证窗口,并成功登录。但是,在访问权限窗口,它不要求'邮件'范围的访问。

This will pop up the google auth window and log in successfully. But, in the access permissions window, it doesn't request the 'email' scope access.

如果我用ref.authWinOAuthPopup(...)而不是AUTH。$ authWithOAithPopup(...)它正确地请求的电子邮件烫发,并提供了经过验证信息

If I use ref.authWinOAuthPopup(...) instead of auth.$authWithOAithPopup(...) it does properly request the email perms, and delivers that info after auth.

我是不是做错了什么吗?或者说,它是一个错误Angularfire我应该报告?

Am I doing something wrong here? Or, is it an Angularfire bug that I should be reporting?

Angularfire v0.9.2。

Angularfire v0.9.2.

推荐答案

要更清楚,我想补充我的片段来展示如何将电子邮件的范围传递给谷歌的OAuth。

To be more clear, I'd like to add my snippets to show how to pass the e-mail scope to google oAuth.

正如你提到的,如果你使用的承诺做验证,而不是回调可以传递的电子邮件范围在auth的选项。呼叫作为第二个参数,然后将电子邮件地址将在有效负载中提供。

As you mentioned, if you're using the promise to do the authentication instead of the callback you can pass the option for the email scope to the auth. call as second parameter and then the e-mail address will be available in the payload.

请看看下面的代码片段:

Please have a look at the following snippet:

$scope.loginGoogle = function() {
    Auth.$authWithOAuthPopup("google", {scope: ['email']}).then(function(authData) {
        // handle authData in onAuth handler in app.js in run method with Auth.$onAuth(function(authData) { ... });
        console.log("Authenticated successfully with payload:", authData);
        $location.path(REDIRECT_ROUTE);
    })
    .catch(function(err) {
        $scope.err = errMessage(err);
    });
};

function errMessage(err) {
    var msg = "";
  //return angular.isObject(err) && err.code? err.code : err + '';
  switch (err.code) {
      case "INVALID_EMAIL":
      case "INVALID_PASSWORD":
      case "INVALID_USER":
        console.log("The specified user account email is invalid.");
            msg = "E-mail or password is invalid.";
        break;
    /*
      case "INVALID_PASSWORD":
        console.log("The specified user account password is incorrect.");
        break;
      case "INVALID_USER":
        console.log("The specified user account does not exist.");
        break;
      default:
        // password or email empty;
        console.log("Error logging user in:", err);*/
    };
    return msg;
}

angular.module('firebase.auth', ['firebase', 'firebase.utils'])
.factory('Auth', ['$firebaseAuth', 'fbutil', function($firebaseAuth, fbutil) {
    return $firebaseAuth(fbutil.ref());
 }]);

这篇关于火力地堡角的OAuth与谷歌电子邮件范围,权威性。$ authWithOAuthPopup VS ref.authWithOAuthPopup的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆