3

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.

Saurabh
  • 71,488
  • 40
  • 181
  • 244
  • You should point scope which you want to get. for example: `$authProvider.google({ url: '/auth/google', scope: ['profile', 'email']});` – Errorpro Nov 04 '15 at 08:07
  • And so, you can get response from the service `$auth.login(user) .then(function(response) { // Could be your user returned from the server. })` – Errorpro Nov 04 '15 at 08:11
  • 1
    I think you have that response because you didn't change server side. I suggest you should return user from auth/google. Or you can invoke user/me immideately. It provides current user. https://github.com/sahat/satellizer/blob/master/examples/server/node/server.js – Errorpro Nov 04 '15 at 09:33
  • See my ans here http://stackoverflow.com/questions/34740186/how-to-get-email-from-facebook-through-guzzle-in-laravel – Niklesh Raut Jan 14 '16 at 10:31

1 Answers1

1

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;
});
Saurabh
  • 71,488
  • 40
  • 181
  • 244