From 0b504c9f85fa9b7a6bf686d40793b66251c1b57f Mon Sep 17 00:00:00 2001 From: Shaun Pack Date: Thu, 24 May 2012 00:27:37 -0400 Subject: [PATCH 01/14] added smarterer oauth --- lib/modules/smarterer.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 lib/modules/smarterer.js diff --git a/lib/modules/smarterer.js b/lib/modules/smarterer.js new file mode 100644 index 00000000..78716faf --- /dev/null +++ b/lib/modules/smarterer.js @@ -0,0 +1,30 @@ +var oauthModule = require('./oauth2') + , querystring= require('querystring'); + +var smarterer = module.exports = +oauthModule.submodule('smarterer') + .oauthHost('https://smarterer.com') + .apiHost('https://smarterer.com') + + .entryPath('/auth/smarterer') + .callbackPath('/auth/smarterer/callback') + + .authQueryParam('callback_url', function() { + return this._myHostname + this._callbackPath; + }) + + .accessTokenParam('grant_type', 'authorization_code') + + + .fetchOAuthUser( function (accessToken) { + var p = this.Promise(); + this.oauth.get(this.apiHost() + '/api/badges', accessToken, function (err, data) { + if (err) return p.fail(err.error_message); + var oauthUser = JSON.parse(data); + p.fulfill(oauthUser); + }) + return p; + }) + .convertErr( function (data) { + return new Error(data.error_message); + }); From be51e02260cb4350be4073f8301bba26de156bab Mon Sep 17 00:00:00 2001 From: emile baizel Date: Tue, 5 Jun 2012 18:31:38 -0700 Subject: [PATCH 02/14] password was not being deleted. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ce8e5406..2fd5da77 100644 --- a/README.md +++ b/README.md @@ -794,7 +794,7 @@ everyauth.password var promise = this.Promise() , password = newUserAttrs.password; - delete newUserAttrs[password]; // Don't store password + delete newUserAttrs.password; // Don't store password newUserAttrs.salt = bcrypt.genSaltSync(10); newUserAttrs.hash = bcrypt.hashSync(password, salt); From 40ef8aa52ce8ad7b71dacfe23a0f00b753f4e6f7 Mon Sep 17 00:00:00 2001 From: jacksonp Date: Sun, 10 Jun 2012 17:49:56 +0200 Subject: [PATCH 03/14] Changed example scope for Google OAuth2 to one that works. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ce8e5406..9ee5f58c 100644 --- a/README.md +++ b/README.md @@ -1065,10 +1065,10 @@ var everyauth = require('everyauth') everyauth.google .appId('YOUR CLIENT ID HERE') .appSecret('YOUR CLIENT SECRET HERE') - .scope('https://www.google.com/m8/feeds') // What you want access to + .scope('https://www.googleapis.com/auth/userinfo.profile') // What you want access to .handleAuthCallbackError( function (req, res) { // If a user denies your app, Google will redirect the user to - // /auth/facebook/callback?error=access_denied + // /auth/google/callback?error=access_denied // This configurable route handler defines how you want to respond to // that. // If you do not configure this, everyauth renders a default fallback From 9794626facab6e828dc6d4d504aa4fcd8f5e1feb Mon Sep 17 00:00:00 2001 From: Shaun Pack Date: Tue, 12 Jun 2012 20:04:17 -0400 Subject: [PATCH 04/14] added smarterer to README --- README.md | 2 ++ media/smarterer.ico | Bin 0 -> 1406 bytes 2 files changed, 2 insertions(+) create mode 100644 media/smarterer.ico diff --git a/README.md b/README.md index 1810a343..73404186 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,8 @@ So far, `everyauth` enables you to login via: Winfred Nadeau Mendeley Eduard Baun + Smarterer + kaizenpack Box.net diff --git a/media/smarterer.ico b/media/smarterer.ico new file mode 100644 index 0000000000000000000000000000000000000000..d676b1f3252daa9e4cfb4ff9e609559714eb929f GIT binary patch literal 1406 zcmZQzU<5(|0R}M0U}azs1F|%L7$l?s#Ec9aKoZP=&`4}YBXNfGXjg^|AijC+BE#mj zix_ThH)L=&5@Xl`WIs8R!|?sXWrqL%{{z*y0M%Sz$OO_K-aKT8@-<^HQDJ9z|6n;o zLs<&L<+Z{LpFVzIxOd2p;r1SThG<_?hO;LQGQG0Rb>jW>IE=u;k=41qAfCl(|HJC5n)ooR*djvpypi5D4&# z=xS*R3k!2FYlHYqe4;=O2nfoFaB(TKfaJhHLzP=XRa~AG#ut^40s<}=SD1rc8VGpA zU;>=nAikn5gwLu2mX>DY5mXZv*5Q;_1jzyc8#|W{CoiuI5`gm*B#}gAWYoEo6d(dB eK%k%ua<2q0h^;Owp# Date: Wed, 13 Jun 2012 07:34:10 -0400 Subject: [PATCH 05/14] added full detail section --- README.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/README.md b/README.md index 73404186..9b53c594 100644 --- a/README.md +++ b/README.md @@ -2197,6 +2197,40 @@ connect( ).listen(3000); ``` +### Smarterer + +You will need to register for an app id [here](http://www.smarterer.com/). Implementation details follow the same pattern as with other +oauth2 implementations. + +```javascript + +var everyauth = require('everyauth') + , connect = require('connect'); + +everyauth.smarterer + .appId('YOUR APP ID') + .appSecret('YOUR APP SECRET') + .findOrCreateUser(function(session, accessToken, accessTokenSecret, userData) { + // find or create user logic goes here + // userData.userName will contain the smarterer username for the authenticated user + // userData.badges will contain the scores on quizes + }) + .redirectPath('/'); + + var routes = function (app) { + // Define your routes here + }; + + connect( + connect.bodyParser() + , connect.cookieParser() + , connect.session({secret: 'whodunnit'}) + , everyauth.middleware() + , connect.router(routes); + ).listen(3000); +``` + + ### Box.net ```javascript From f792d7a5a4258bec7a81e0585b4ba528b27bf790 Mon Sep 17 00:00:00 2001 From: Shaun Pack Date: Wed, 13 Jun 2012 07:35:19 -0400 Subject: [PATCH 06/14] fixed indentation issue --- README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 9b53c594..733d3f51 100644 --- a/README.md +++ b/README.md @@ -2217,17 +2217,17 @@ everyauth.smarterer }) .redirectPath('/'); - var routes = function (app) { - // Define your routes here - }; +var routes = function (app) { + // Define your routes here +}; - connect( - connect.bodyParser() - , connect.cookieParser() - , connect.session({secret: 'whodunnit'}) - , everyauth.middleware() - , connect.router(routes); - ).listen(3000); +connect( + connect.bodyParser() + , connect.cookieParser() + , connect.session({secret: 'whodunnit'}) + , everyauth.middleware() + , connect.router(routes); +).listen(3000); ``` From be7c423a68bd5f75fed2ca2445c563e5506017ac Mon Sep 17 00:00:00 2001 From: hostalerye Date: Wed, 13 Jun 2012 13:42:54 +0200 Subject: [PATCH 07/14] Now using Github api v3 --- lib/modules/github.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/modules/github.js b/lib/modules/github.js index 927a9861..15390ee6 100644 --- a/lib/modules/github.js +++ b/lib/modules/github.js @@ -7,7 +7,7 @@ oauthModule.submodule('github') }) .oauthHost('https://github.com') - .apiHost('https://github.com/api/v2/json') + .apiHost('https://api.github.com') .authPath('/login/oauth/authorize') .accessTokenPath('/login/oauth/access_token') @@ -21,9 +21,9 @@ oauthModule.submodule('github') .fetchOAuthUser( function (accessToken) { var p = this.Promise(); - this.oauth.get(this.apiHost() + '/user/show', accessToken, function (err, data) { + this.oauth.get(this.apiHost() + '/user', accessToken, function (err, data) { if (err) return p.fail(err); - var oauthUser = JSON.parse(data).user; + var oauthUser = JSON.parse(data); p.fulfill(oauthUser); }) return p; From e1bf2084743298476e793c2d927cb6b892078541 Mon Sep 17 00:00:00 2001 From: genuisereal Date: Wed, 20 Jun 2012 11:53:55 +0300 Subject: [PATCH 08/14] 1) Openid sendToAuthenticationUri step did not provide correct Promise object reference to use inside this.relyingParty.authenticate callback function. Also call back function did not fulfill promise and step itself did not return promise reference. 2) this.redirect in this.relyingParty.authenticate callback function thrown exception because this in the context did not have redirect method. Thus self was defined in outer context and self.redirect invoked. --- lib/modules/openid.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/modules/openid.js b/lib/modules/openid.js index 6f083fd8..d6fe7db2 100644 --- a/lib/modules/openid.js +++ b/lib/modules/openid.js @@ -50,11 +50,16 @@ everyModule.submodule('openid') if (!this._myHostname || this._alwaysDetectHostname) { this.myHostname(extractHostname(req)); } - + + var self = this + var p = this.Promise(); + this.relyingParty.authenticate(req.query[this.openidURLField()], false, function(err,authenticationUrl){ if(err) return p.fail(err); - this.redirect(res, authenticationUrl); + p.fulfill(authenticationUrl) + self.redirect(res, authenticationUrl); }); + return p; }) .getSession( function(req) { return req.session; From bd8a8e899e57b53072bc2ba762c3259bb7172817 Mon Sep 17 00:00:00 2001 From: genuisereal Date: Wed, 20 Jun 2012 12:10:56 +0300 Subject: [PATCH 09/14] minor styling --- lib/modules/openid.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/modules/openid.js b/lib/modules/openid.js index d6fe7db2..0c2f80bf 100644 --- a/lib/modules/openid.js +++ b/lib/modules/openid.js @@ -51,7 +51,7 @@ everyModule.submodule('openid') this.myHostname(extractHostname(req)); } - var self = this + var self = this; var p = this.Promise(); this.relyingParty.authenticate(req.query[this.openidURLField()], false, function(err,authenticationUrl){ From bea944ba1dda7e485170d7ff2bc86d9342963255 Mon Sep 17 00:00:00 2001 From: genuisereal Date: Wed, 20 Jun 2012 18:49:55 +0300 Subject: [PATCH 10/14] Fix: after testing with non working openid provider new error issue apperared. which led to the conclusion that added Promise does not solve the problem as long as if we analyze the initialization of the step it clearly says that no promoses are expected to be returned. Thus condition `if(err) return p.fail(err);` seems now incorrect. And must be removed. --- lib/modules/openid.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/modules/openid.js b/lib/modules/openid.js index 0c2f80bf..ead03afc 100644 --- a/lib/modules/openid.js +++ b/lib/modules/openid.js @@ -1,7 +1,9 @@ var everyModule = require('./everymodule') , oid = require('openid') , url = require('url') - , extractHostname = require('../utils').extractHostname; + , extractHostname = require('../utils').extractHostname + , util + var openid = module.exports = everyModule.submodule('openid') @@ -52,14 +54,11 @@ everyModule.submodule('openid') } var self = this; - var p = this.Promise(); this.relyingParty.authenticate(req.query[this.openidURLField()], false, function(err,authenticationUrl){ - if(err) return p.fail(err); - p.fulfill(authenticationUrl) + if(err) return; self.redirect(res, authenticationUrl); }); - return p; }) .getSession( function(req) { return req.session; From 3b894d6e906d657cc4361b5e826ffd5237fb6a55 Mon Sep 17 00:00:00 2001 From: genuisereal Date: Wed, 20 Jun 2012 18:52:08 +0300 Subject: [PATCH 11/14] Minor fix --- lib/modules/openid.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/modules/openid.js b/lib/modules/openid.js index ead03afc..788b4cb9 100644 --- a/lib/modules/openid.js +++ b/lib/modules/openid.js @@ -1,8 +1,7 @@ var everyModule = require('./everymodule') , oid = require('openid') , url = require('url') - , extractHostname = require('../utils').extractHostname - , util + , extractHostname = require('../utils').extractHostname; var openid = module.exports = From 06ea58dd9de5b49eb0c0df14165fa7967392e207 Mon Sep 17 00:00:00 2001 From: genuisereal Date: Wed, 20 Jun 2012 18:55:28 +0300 Subject: [PATCH 12/14] Minor fix --- lib/modules/openid.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/modules/openid.js b/lib/modules/openid.js index 788b4cb9..7567719a 100644 --- a/lib/modules/openid.js +++ b/lib/modules/openid.js @@ -2,7 +2,6 @@ var everyModule = require('./everymodule') , oid = require('openid') , url = require('url') , extractHostname = require('../utils').extractHostname; - var openid = module.exports = everyModule.submodule('openid') From 3d60247f590e2e712960f7cb84186fe3c8c1be25 Mon Sep 17 00:00:00 2001 From: genuisereal Date: Thu, 21 Jun 2012 17:11:25 +0300 Subject: [PATCH 13/14] Fix: correct error handling implemented Finally working solution is found. `sendToAuthenticationUri` now correctly return fulfilled promise in normal case and fails if error. --- lib/modules/openid.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/modules/openid.js b/lib/modules/openid.js index 7567719a..68aaeae9 100644 --- a/lib/modules/openid.js +++ b/lib/modules/openid.js @@ -44,7 +44,7 @@ everyModule.submodule('openid') .step('sendResponse') .accepts('res') .promises(null) - .sendToAuthenticationUri(function(req,res) { + .sendToAuthenticationUri(function(req,res,next) { // Automatic hostname detection + assignment if (!this._myHostname || this._alwaysDetectHostname) { @@ -52,11 +52,16 @@ everyModule.submodule('openid') } var self = this; + var p = this.Promise(); this.relyingParty.authenticate(req.query[this.openidURLField()], false, function(err,authenticationUrl){ - if(err) return; + if(err) return p.fail(err); + self.redirect(res, authenticationUrl); }); + + p.fulfill(); + return p; }) .getSession( function(req) { return req.session; From e3dba2741c0a9dd6bbc6131036d801dd9e0b37a6 Mon Sep 17 00:00:00 2001 From: genuisereal Date: Thu, 21 Jun 2012 17:13:44 +0300 Subject: [PATCH 14/14] Fix: extra parameter removed --- lib/modules/openid.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/modules/openid.js b/lib/modules/openid.js index 68aaeae9..65d89c69 100644 --- a/lib/modules/openid.js +++ b/lib/modules/openid.js @@ -44,7 +44,7 @@ everyModule.submodule('openid') .step('sendResponse') .accepts('res') .promises(null) - .sendToAuthenticationUri(function(req,res,next) { + .sendToAuthenticationUri(function(req,res) { // Automatic hostname detection + assignment if (!this._myHostname || this._alwaysDetectHostname) {