Skip to content

Instantly share code, notes, and snippets.

@johnnyhalife
Created March 26, 2013 20:39
Show Gist options
  • Save johnnyhalife/5249029 to your computer and use it in GitHub Desktop.
Save johnnyhalife/5249029 to your computer and use it in GitHub Desktop.
var util = require('util-ext'),
oauth = require('oauth');
module.exports.link = function(req, res) {
var url = util.format("https://api.singly.com/oauth/authenticate?client_id=%s&redirect_uri=%s&scope=%s&service=%s",
process.env.SINGLY_APP_ID,
process.env.MURALLY_HOST + "/connect/success",
"https://www.google.com/m8/feeds",
req.params.service);
if(req.cookies['s.t'])
url += util.format("&access_token=%s", req.cookies['s.t']);
res.redirect(url);
};
module.exports.success = function(req, res) {
var closeScript = "<script>var a = {completed: true}; window.opener.window.postMessage(a, '*'); window.close();</script>";
if(req.cookies['s.t']) {
return res.send(closeScript);
}
var oauth2 = new oauth.OAuth2(process.env.SINGLY_APP_ID, process.env.SINGLY_APP_SECRET, 'https://api.singly.com');
oauth2.getOAuthAccessToken(req.query.code, {}, function(err, access_token) {
res.cookie("s.t", access_token);
res.send(closeScript);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment