【问题标题】:Getting Email address from Polymer firebase-auth element with Google Authentication使用 Google 身份验证从 Polymer firebase-auth 元素获取电子邮件地址
【发布时间】:2015-10-09 16:16:57
【问题描述】:

使用 Firebase Auth 我想从 Google 登录中获取电子邮件地址,因此我需要范围电子邮件。如何将其添加到 firebase-auth 元素?它在参数中吗?如果是这样,怎么做?一个例子会很棒。

为了帮助我的一位开发人员创建了一个具有登录名的 Polymer Element

https://github.com/HackITtoday/hi9-login/blob/master/hi9-login.html

谢谢

【问题讨论】:

标签: firebase polymer firebase-security firebasesimplelogin


【解决方案1】:

可以通过调用 <firebase-auth>less 个公共 API 之一来完成。

<firebase-auth
    id="auth"
    provider="{{provider}}"
    app-name="[[appName]]"
    signed-in="{{signedIn}}"
    user="{{user}}"
    on-error="onAuthError"></firebase-auth>

在元素的 Polymer 定义中...

// Currently supported providers are 'google', 'facebook', 'github', 'twitter'
loginUsingProvider: function(name) {
    var provider = this.$.auth._providerFromName(name);
    // Twitter simple login doesn't have scopes.
    if (name != 'twitter') {
        provider.addScope('email');
    }
    this.$.auth.signInWithPopup(provider)
        .then(function(response) {
            // success
        }, function(error) {
            // failure
        })
        .catch(function(exception) {
            // Exception 
        });
}

这是使用polymerfire 0.9.4 版完成的。使用bower install polymerfire检查您的版本。

【讨论】:

    【解决方案2】:

    根据文档here,有一个属性是一个名为user 的对象:

    登录时,此属性反映 firebase 用户身份验证对象。

    这应该包含您需要的信息。

    【讨论】:

    • 你会这么认为,但事实并非如此。它似乎错过了范围电子邮件。
    • 我遇到了同样的问题,看起来我们必须使用非聚合的 JS 身份验证方法来添加范围。 firebase.google.com/docs/auth/web/google-signin
    • 看看this codelab 可能会有所帮助
    猜你喜欢
    • 2020-06-20
    • 1970-01-01
    • 2019-05-01
    • 1970-01-01
    • 2017-05-08
    • 2017-10-03
    • 2023-03-18
    • 2019-11-18
    • 1970-01-01
    相关资源
    最近更新 更多