Skip to content

Instantly share code, notes, and snippets.

@cympfh
Created December 22, 2013 11:14
Show Gist options
  • Save cympfh/8081011 to your computer and use it in GitHub Desktop.
Save cympfh/8081011 to your computer and use it in GitHub Desktop.
var oauth = new (require('oauth').OAuth)(
'https://api.twitter.com/oauth/request_token',
'https://api.twitter.com/oauth/access_token',
'qnNRwjeo8zFjhIDfgG1F6Q', // CONSUMER_KEY (replace)
'JtKRv1e9QIEG6mKvWl0g4ygGVGzWclgfd7GaSBEGtg', // CONSUMER_SECRET (replace)
'1.0',
'http://127.0.0.1:3000/signin/twitter', // callback URL
'HMAC-SHA1'
);
app.get('/signin/twitter', function(req, res) {
var oauth_token = req.query.oauth_token;
var oauth_verifier = req.query.oauth_verifier;
if (oauth_token && oauth_verifier) {
console.log("##", oauth_token, oauth_verifier);
oauth.getOAuthAccessToken(
oauth_token, null, oauth_verifier,
function(error, oauth_access_token, oauth_access_token_secret, results) {
if (error) {
res.send(error, 500);
} else {
// req.session.user = results.screen_name;
console.log("@@@", oauth_access_token, oauth_access_token_secret);
res.end(oauth_access_token + " " + oauth_access_token_secret);
// res.redirect('/');
}
}
);
} else {
oauth.getOAuthRequestToken(function(error, oauth_token, oauth_token_secret, results) {
if (error) {
res.send(error, 500);
} else {
req.session = {
oauth_token: oauth_token,
oauth_token_secret: oauth_token_secret,
request_token_results: results
};
res.redirect('https://api.twitter.com/oauth/authorize?oauth_token=' + oauth_token);
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment