【问题标题】:AngularFire Google OAuth not retrieving the user's emailAngularFire Google OAuth 未检索用户的电子邮件
【发布时间】:2015-05-29 02:16:51
【问题描述】:

我想使用 AngularFire 从 Google OAuth 获取电子邮件地址,但在弹出窗口中,它并没有要求电子邮件权限。

这是来自Firebase Google auth doc的代码

var ref = new Firebase("https://<your-firebase>.firebaseio.com");
ref.authWithOAuthPopup("google", function(error, authData) { /* Your Code */ }, {
  scope: "email"
});

它在我的 Angular 应用程序中有效,但我如何修复我的 Angular 代码来做同样的事情?

var ref = new Firebase("https://<your-firebase>.firebaseio.com");
var auth = $firebaseAuth(ref);
auth.$authWithOAuthPopup("google").then(function(authData) {
   /* Code */
}).catch(function(error) {
   console.error("Authentication failed:", error);
});

Link to the same problem with answer,但我没有得到答案以及如何解决它。

【问题讨论】:

  • 也来自同一个文档,供参考:authData.google.email 包含 Google 用户在其个人资料中列出的主要电子邮件地址。仅当有效的电子邮件地址可用且用户授予 G​​oogle 电子邮件权限时才返回。

标签: javascript angularjs firebase angularfire


【解决方案1】:

您是否尝试过传递选项?

var ref = new Firebase("https://<your-firebase>.firebaseio.com");
var auth = $firebaseAuth(ref);
auth.$authWithOAuthPopup("google", { scope: 'email' }).then(function(authData) {
   /* Code */
}).catch(function(error) {
   console.error("Authentication failed:", error);
});

正如 Kato 所说,文档也提供了该信息:link

【讨论】:

  • 似乎是正确的选择。在API docs 中也有注明。
  • 谢谢@Kato 我更新了我的答案以反映文档。
猜你喜欢
  • 1970-01-01
  • 2019-12-22
  • 1970-01-01
  • 2015-04-08
  • 2016-01-02
  • 2014-07-19
  • 1970-01-01
  • 2023-03-09
  • 2021-03-23
相关资源
最近更新 更多