本文介绍了具有 Google 电子邮件范围的 Firebase Angular OAuth,auth.$authWithOAuthPopup 与 ref.authWithOAuthPopup的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我成功地使用 Firebase 的 angular 库对 Facebook 和 Google 的用户进行身份验证,但是在使用 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'
    });
  };

这会弹出google auth窗口并登录成功.但是,在访问权限窗口中,它不会请求电子邮件"范围访问.

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.

推荐答案

这就是我所做的并且对我有用

This is what I did and it worked for me

.config(function ($firebaseRefProvider) {$firebaseRefProvider.registerUrl('https://****.firebaseio.com/');})

然后在控制器中

loginWithGoogle: function(){
    var ref = $firebaseRef.default;
    ref.authWithOAuthPopup("google", function(error, authData) {

      if (error) {
        ...
      } else {
        console.log(authData.google.email);

      }
    },{scope: 'email'});
  }

这篇关于具有 Google 电子邮件范围的 Firebase Angular OAuth,auth.$authWithOAuthPopup 与 ref.authWithOAuthPopup的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 05:59