moved common server side oauth setup code to accounts-oauth-helpers

This commit is contained in:
Mike Bannister
2012-08-02 01:53:31 -04:00
committed by Nick Martin
parent 2acd9e17e3
commit 19f043583d
2 changed files with 3 additions and 44 deletions

View File

@@ -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) {

View File

@@ -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/<service name>?<action>"
// NOTE: query param is mandatory.
var barePath = req.url.substring(0, req.url.indexOf('?'));