Saurabh
Saurabh

Reputation: 73649

how to get email of authenticated user in angularjs using satellizer

I am creating a webapp in angularJs, and using satellizer for authentication. I am able to use to authenticate using google, but I couldn't figure out how to get email id of authenticated user somewhere in my UI code. I couldn't found any function also to get email id in documentation.

Upvotes: 3

Views: 1585

Answers (1)

Saurabh
Saurabh

Reputation: 73649

All I had to do was, hit googleapis using the access_token satelizer save in your browser's local memory, which returns user info, Following is the service for your reference:

angular.module('MyApp')
    .factory('Google', ['$resource', '$auth', Google]);

function Google($resource, $auth) {
    return $resource("https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=" + $auth.getToken(), {}, {})
}

You can just do following to get email id of logged in user:

var googleResponse = Google.get({}, function () {
    var email = googleResponse.email;
});

Upvotes: 1

Related Questions