Last active
August 29, 2015 14:03
-
-
Save goldalworming/da5014492b7795d87e04 to your computer and use it in GitHub Desktop.
straightforward glus auth without any library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
framework.route('/login/gplus/', process_gplus,{timeout: 60000}); | |
function process_gplus() { | |
var self = this; | |
var auth = self.module('authorization'); | |
objgplus = { | |
client_id:'[yourclientid]', | |
client_secret:'[yourclientsecret]' | |
}; | |
if(self.get['error']){ | |
self.redirect('/'); | |
} | |
if(!self.get['code']){ | |
var code = ''; | |
}else{ | |
var code = self.get['code']; | |
var datapost = { | |
code:code, | |
client_id: objgplus.client_id, | |
client_secret: objgplus.client_secret, | |
redirect_uri:self.host('/login/gplus'), | |
grant_type:'authorization_code' | |
} | |
utils.request('https://accounts.google.com/o/oauth2/token', ['post'], datapost, function(err,response){ | |
if(err!=null){ | |
rc.quit(); | |
} | |
if(response){ | |
oResp = JSON.parse(response); | |
} | |
utils.request('https://www.googleapis.com/plus/v1/people/me?access_token='+oResp.access_token, ['get'], null, function(err2,usertxt){ | |
if(err!=null){ | |
rc.quit(); | |
} | |
if(response){ | |
userobj = JSON.parse(usertxt); | |
var user = { | |
id: Date.now(), | |
callname: userobj.displayName, | |
email:userobj.emails[0].value, | |
imageUrl : userobj.image.url, | |
gplusUlr : userobj.url, | |
gender : userobj.gender | |
}; | |
self.json(user); | |
} | |
}); | |
}); | |
} | |
if (code === '') { | |
url = '/login/gplus'; | |
if(self.get['red']){ | |
url = url+'?red='+self.get['red']; | |
} | |
const URL = 'https://accounts.google.com/o/oauth2/auth?response_type=code&state=%2Fprofile&redirect_uri={0}&scope=profile%20email&client_id={1}&type=web_server'; | |
redurl = URL.format(self.host(url),objgplus.client_id); | |
self.redirect(redurl); | |
return; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment