Getting Email address from Polymer firebase-auth element with Google Authentication

551 Views Asked by At

Using Firebase Auth I want to get the email address from a Google login so I need the scope email. How can I add that to the firebase-auth element? Is it in params? If so, how? An example would be great.

To help one of my devs created a Polymer Element which has the login

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

Thanks

2

There are 2 best solutions below

3
Ben Thomas On

According to the docs here there is a property that is an Object called user which:

When logged in, this property reflects the firebase user auth object.

This should contain the information you require.

0
Jacob Phillips On

It can be done by calling one of <firebase-auth>'s less public APIs.

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

Inside an element's Polymer definition...

// 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 
        });
}

This was done using polymerfire version 0.9.4. Check your versions by using bower install polymerfire).