Permalink
Browse files

Add more services.

  • Loading branch information...
1 parent 3b6dc0e commit 2d6d023a0125ad1046bfd0e4744f850c0da1939b @llun committed Feb 27, 2013
Showing with 116 additions and 2 deletions.
  1. +20 −0 services/4sq.js
  2. +49 −0 services/flickr.js
  3. +20 −0 services/github.js
  4. +4 −0 services/index.js
  5. +20 −0 services/linkedin.js
  6. +2 −1 services/twitter.js
  7. +1 −1 views/admin.jade
View
@@ -0,0 +1,20 @@
+var util = require('util');
+
+var Service = require('./oauth2');
+
+var Foursquare = function (key, secret, url) {
+ Service.call(this, key, secret, url, 'https://api.foursquare.com/v2');
+}
+
+util.inherits(Foursquare, Service);
+
+Foursquare.prototype.authorizeUrl = function () {
+ var redirect = encodeURIComponent(this.url + '/admin/services/foursquare/callback');
+ var url = 'https://foursquare.com/oauth2/authenticate?client_id=' + this.key +
+ '&redirect_uri=' + redirect + '&response_type=code';
+
+ return url;
+}
+
+
+module.exports = Foursquare;
View
@@ -0,0 +1,49 @@
+var OAuth = require('oauth').OAuth;
+
+var Flickr = function (key, secret, url) {
+ this.key = key;
+ this.secret = secret;
+ this.url = url;
+
+ this.oauth = new OAuth(
+ 'http://www.flickr.com/services/oauth/request_token',
+ 'http://www.flickr.com/services/oauth/access_token',
+ key,
+ secret,
+ '1.0A',
+ null,
+ 'HMAC-SHA1');
+}
+
+Flickr.secrets = {};
+
+Flickr.prototype.authorize = function (req, res) {
+ var redirect = this.url + '/admin/services/facebook/callback';
+ this.oauth.getOAuthRequestToken({ oauth_callback: redirect },
+ function(error, oauth_token, oauth_token_secret, oauth_authorize_url, additionalParameters ) {
+ if(error) {
+ console.error( 'Error retrieving the OAuth Request Token: ' + JSON.stringify(error) );
+ res.redirect('/admin'); // Ignore the error upstream, treat as validation failure.
+ } else {
+ console.log ( 'Successfully retrieved the OAuth Request Token' );
+ Flickr.secrets[oauth_token] = oauth_token_secret;
+ res.redirect('http://www.flickr.com/services/oauth/authorize?oauth_token=' + oauth_token + '&perms=read');
+ }
+ });
+}
+
+Flickr.prototype.callback = function (req, cb) {
+ this.oauth.getOAuthAccessToken(req.query.oauth_token,
+ Flickr.secrets[req.query.oauth_token], req.query.oauth_verifier,
+ function (err, token, secret, user) {
+ if (err) {
+ cb(err);
+ }
+ else {
+ delete Flickr.secrets[req.query.oauth_token];
+ cb(null, token + '|' + secret);
+ }
+ });
+}
+
+module.exports = Flickr;
View
@@ -0,0 +1,20 @@
+var util = require('util');
+
+var Service = require('./oauth2');
+
+var Github = function (key, secret, url) {
+ Service.call(this, key, secret, url, 'https://api.github.com');
+}
+
+util.inherits(Github, Service);
+
+Github.prototype.authorizeUrl = function () {
+ var redirect = encodeURIComponent(this.url + '/admin/services/foursquare/callback');
+ var url = 'https://github.com/login/oauth/authorize?client_id=' + this.key +
+ '&redirect_uri=' + redirect;
+
+ return url;
+}
+
+
+module.exports = Github;
View
@@ -13,6 +13,10 @@ Service.facebook = require('./facebook');
Service.twitter = require('./twitter');
Service.instagram = require('./instagram');
Service.gplus = require('./gplus');
+Service.flickr = require('./flickr');
+Service.foursquare = require('./4sq');
+Service.github = require('./github');
+Service.linkedin = require('./linkedin');
/**
* Get service from database or create it if not found.
View
@@ -0,0 +1,20 @@
+var util = require('util');
+
+var Service = require('./oauth2');
+
+var Linkedin = function (key, secret, url) {
+ Service.call(this, key, secret, url, 'http://api.linkedin.com/v1');
+}
+
+util.inherits(Linkedin, Service);
+
+Linkedin.prototype.authorizeUrl = function () {
+ var redirect = encodeURIComponent(this.url + '/admin/services/foursquare/callback');
+ var url = 'https://www.linkedin.com/uas/oauth2/authorization?client_id=' + this.key +
+ '&redirect_uri=' + redirect + '&response_type=code&state=' + new Date().getTime();
+
+ return url;
+}
+
+
+module.exports = Linkedin;
View
@@ -23,7 +23,7 @@ Twitter.secrets = {};
Twitter.prototype.authorize = function (req, res) {
this.oauth.getOAuthRequestToken(function(error, oauth_token, oauth_token_secret, oauth_authorize_url, additionalParameters ) {
if(error) {
- console.err( 'Error retrieving the OAuth Request Token: ' + JSON.stringify(error) );
+ console.error( 'Error retrieving the OAuth Request Token: ' + JSON.stringify(error) );
res.redirect('/admin'); // Ignore the error upstream, treat as validation failure.
} else {
console.log ( 'Successfully retrieved the OAuth Request Token' );
@@ -41,6 +41,7 @@ Twitter.prototype.callback = function (req, cb) {
cb(err);
}
else {
+ delete Twitter.secrets[req.query.oauth_token];
cb(null, token + '|' + secret);
}
});
View
@@ -98,7 +98,7 @@ block content
option(value='gplus') Google Plus
option(value='flickr') Flickr
option(value='instagram') Instagram
- option(value='4sq') Foursquare
+ option(value='foursquare') Foursquare
option(value='github') Github
option(value='linkedin') LinkedIn
.control-group

0 comments on commit 2d6d023

Please sign in to comment.