Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- googleAuth: function(req, res) {
- if (_.isUndefined(req.param('googleToken'))) {
- return res.json({
- success: false,
- msg: 'Error! Please post your google token'
- });
- }
- var urlToRq = "https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=" + req.param('googleToken');
- // Get information about the google user with the specified access token.
- request.get({url: urlToRq}, function(err, response, body) {
- if(err) {
- return res.json({
- success: false,
- msg: 'Server Error'
- });
- }
- var receivedData = JSON.parse(body);
- var userId = receivedData.sub;
- var userEmail = receivedData.email;
- var emailVerified = receivedData.email_verified;
- var userName = receivedData.name;
- var userPicture = receivedData.picture;
- if (emailVerified == false) {
- return res.json({
- success: false,
- msg: 'Your email is not verified'
- });
- }
- else {
- // AUTHENTICATION VERIFIED, YOU CAN SAVE THE CONNECTED USER IN A SESSION, OR ADD HIM TO THE DATABASE AS A NEW ACCOUNT, OR CHECK IF HE HAS A PREVIOUS ACCOUNT OR WHATEVER YOU WANT...
- }
- });
- },
Add Comment
Please, Sign In to add comment