From 19f043583d8d7159e6ca7a842b20e33ea6ff0a76 Mon Sep 17 00:00:00 2001 From: Mike Bannister Date: Thu, 2 Aug 2012 01:53:31 -0400 Subject: [PATCH] moved common server side oauth setup code to accounts-oauth-helpers --- .../accounts-oauth1-helper/oauth1_server.js | 21 +-------------- .../accounts-oauth2-helper/oauth2_server.js | 26 ++----------------- 2 files changed, 3 insertions(+), 44 deletions(-) diff --git a/packages/accounts-oauth1-helper/oauth1_server.js b/packages/accounts-oauth1-helper/oauth1_server.js index 818d712dfc..4cf6ea0082 100644 --- a/packages/accounts-oauth1-helper/oauth1_server.js +++ b/packages/accounts-oauth1-helper/oauth1_server.js @@ -3,26 +3,7 @@ Meteor.accounts.oauth1._services = {}; - // Listen to calls to `login` with an oauth option set - Meteor.accounts.registerLoginHandler(function (options) { - if (!options.oauth || options.oauth.version !== 1) - return undefined; // don't handle - - var result = Meteor.accounts.oauth1._loginResultForState[options.oauth.state]; - if (result === undefined) // not using `!result` since can be null - // We weren't notified of the user authorizing the login. - return null; - else - return result; - }); - - // When we get an incoming OAuth http request we complete the oauth - // handshake, account and token setup before responding. The - // results are stored in this map which is then read when the login - // method is called. Maps state --> return value of `login` - // - // XXX we should periodically clear old entries - Meteor.accounts.oauth1._loginResultForState = {}; + Meteor.accounts.oauth._setup({oauthVersion: 1}); // connect middleware Meteor.accounts.oauth1._handleRequest = function (req, res, next) { diff --git a/packages/accounts-oauth2-helper/oauth2_server.js b/packages/accounts-oauth2-helper/oauth2_server.js index 169631e87d..620c2d0aa9 100644 --- a/packages/accounts-oauth2-helper/oauth2_server.js +++ b/packages/accounts-oauth2-helper/oauth2_server.js @@ -3,33 +3,11 @@ Meteor.accounts.oauth2._services = {}; - // Listen to calls to `login` with an oauth option set - Meteor.accounts.registerLoginHandler(function (options) { - if (!options.oauth || options.oauth.version !== 2) - return undefined; // don't handle - - var result = Meteor.accounts.oauth2._loginResultForState[options.oauth.state]; - if (result === undefined) // not using `!result` since can be null - // We weren't notified of the user authorizing the login. - return null; - else if (result instanceof Error) - // We tried to login, but there was a fatal error. Report it back - // to the user. - throw result; - else - return result; - }); - - // When we get an incoming OAuth http request we complete the oauth - // handshake, account and token setup before responding. The - // results are stored in this map which is then read when the login - // method is called. Maps state --> return value of `login` - // - // XXX we should periodically clear old entries - Meteor.accounts.oauth2._loginResultForState = {}; + Meteor.accounts.oauth._setup({oauthVersion: 2}); // connect middleware Meteor.accounts.oauth2._handleRequest = function (req, res, next) { + // req.url will be "/_oauth/?" // NOTE: query param is mandatory. var barePath = req.url.substring(0, req.url.indexOf('?'));