refactoring and reverting back to using clientId internally for weibo and google

This commit is contained in:
Mike Bannister
2012-08-14 03:39:51 -04:00
committed by Nick Martin
parent a352ff2524
commit 56399c2755
11 changed files with 35 additions and 17 deletions

View File

@@ -1,5 +1,6 @@
if (!Meteor.accounts.facebook) {
Meteor.accounts.facebook = {};
Meteor.accounts.facebook._requireConfigs = ['appId', 'appUrl'];
}
Meteor.accounts.facebook.config = function(appId, appUrl, options) {

View File

@@ -1,6 +1,6 @@
(function () {
Meteor.loginWithGoogle = function () {
if (!Meteor.accounts.google._appId || !Meteor.accounts.google._appUrl)
if (!Meteor.accounts.google._clientId || !Meteor.accounts.google._appUrl)
throw new Meteor.accounts.ConfigError("Need to call Meteor.accounts.google.config first");
var state = Meteor.uuid();
@@ -20,7 +20,7 @@
var loginUrl =
'https://accounts.google.com/o/oauth2/auth' +
'?response_type=code' +
'&client_id=' + Meteor.accounts.google._appId +
'&client_id=' + Meteor.accounts.google._clientId +
'&scope=' + flat_scope +
'&redirect_uri=' + Meteor.accounts.google._appUrl + '/_oauth/google?close' +
'&state=' + state;

View File

@@ -1,9 +1,10 @@
if (!Meteor.accounts.google) {
Meteor.accounts.google = {};
Meteor.accounts.google._requireConfigs = ['clientId', 'appUrl'];
}
Meteor.accounts.google.config = function(clientId, appUrl, options) {
Meteor.accounts.google._appId = clientId;
Meteor.accounts.google._clientId = clientId;
Meteor.accounts.google._appUrl = appUrl;
Meteor.accounts.google._options = options;
};

View File

@@ -22,7 +22,7 @@
var result = Meteor.http.post(
"https://accounts.google.com/o/oauth2/token", {params: {
code: query.code,
client_id: Meteor.accounts.google._appId,
client_id: Meteor.accounts.google._clientId,
client_secret: Meteor.accounts.google._secret,
redirect_uri: Meteor.accounts.google._appUrl + "/_oauth/google?close",
grant_type: 'authorization_code'

View File

@@ -51,7 +51,7 @@
};
// Handle _oauth paths, gets a bunch of stuff ready for the oauth implementation middleware
Meteor.accounts.oauth._prepareRequest = function (req) {
Meteor.accounts.oauth._requestServiceName = function (req) {
// req.url will be "/_oauth/<service name>?<action>"
var barePath = req.url.substring(0, req.url.indexOf('?'));
@@ -66,15 +66,23 @@
return;
}
// Make sure we're configured
if (!Meteor.accounts[serviceName]._appId || !Meteor.accounts[serviceName]._appUrl)
throw new Meteor.accounts.ConfigError("Need to call Meteor.accounts." + serviceName + ".config first");
if (!Meteor.accounts[serviceName]._secret)
throw new Meteor.accounts.ConfigError("Need to call Meteor.accounts." + serviceName + ".setSecret first");
return serviceName;
};
// Make sure we're configured
Meteor.accounts.oauth._ensureConfigured = function(serviceName) {
var service = Meteor.accounts[serviceName];
_.each(Meteor.accounts[serviceName]._requireConfigs, function(key) {
var configKey = '_' + key;
if (!service[configKey])
throw new Meteor.accounts.ConfigError("Need to call Meteor.accounts." + serviceName + ".config first");
});
if (!service._secret)
throw new Meteor.accounts.ConfigError("Need to call Meteor.accounts." + serviceName + ".setSecret first");
};
Meteor.accounts.oauth._loadMiddleWare = function(middleware) {
__meteor_bootstrap__.app
.use(connect.query())

View File

@@ -8,7 +8,7 @@
// connect middleware
Meteor.accounts.oauth1._handleRequest = function (req, res, next) {
var serviceName = Meteor.accounts.oauth._prepareRequest(req);
var serviceName = Meteor.accounts.oauth._requestServiceName(req);
var service = Meteor.accounts.oauth1._services[serviceName];
// Skip everything if there's no service set by the oauth middleware
@@ -17,6 +17,9 @@
return;
}
// Make sure we're configured
Meteor.accounts.oauth._ensureConfigured(serviceName);
// Make sure we prepare the login results before returning.
// This way the subsequent call to the `login` method will be
// immediate.

View File

@@ -8,7 +8,7 @@
// connect middleware
Meteor.accounts.oauth2._handleRequest = function (req, res, next) {
var serviceName = Meteor.accounts.oauth._prepareRequest(req);
var serviceName = Meteor.accounts.oauth._requestServiceName(req);
var service = Meteor.accounts.oauth2._services[serviceName];
// Skip everything if there's no service set by the oauth middleware
@@ -17,6 +17,9 @@
return;
}
// Make sure we're configured
Meteor.accounts.oauth._ensureConfigured(serviceName);
if (req.query.error) {
// The user didn't authorize access
return null;

View File

@@ -1,5 +1,6 @@
if (!Meteor.accounts.twitter) {
Meteor.accounts.twitter = {};
Meteor.accounts.twitter._requireConfigs = ['appId', 'appUrl'];
}
Meteor.accounts.twitter.config = function(appId, appUrl, options) {

View File

@@ -1,6 +1,6 @@
(function () {
Meteor.loginWithWeibo = function () {
if (!Meteor.accounts.weibo._appId || !Meteor.accounts.weibo._appUrl)
if (!Meteor.accounts.weibo._clientId || !Meteor.accounts.weibo._appUrl)
throw new Meteor.accounts.ConfigError("Need to call Meteor.accounts.weibo.config first");
var state = Meteor.uuid();
@@ -8,7 +8,7 @@
var loginUrl =
'https://api.weibo.com/oauth2/authorize' +
'?response_type=code' +
'&client_id=' + Meteor.accounts.weibo._appId +
'&client_id=' + Meteor.accounts.weibo._clientId +
'&redirect_uri=' + Meteor.accounts.weibo._appUrl + '/_oauth/weibo?close' +
'&state=' + state;

View File

@@ -1,8 +1,9 @@
if (!Meteor.accounts.weibo) {
Meteor.accounts.weibo = {};
Meteor.accounts.weibo._requireConfigs = ['clientId', 'appUrl'];
}
Meteor.accounts.weibo.config = function(clientId, appUrl) {
Meteor.accounts.weibo._appId = clientId;
Meteor.accounts.weibo._clientId = clientId;
Meteor.accounts.weibo._appUrl = appUrl;
};

View File

@@ -27,7 +27,7 @@
var result = Meteor.http.post(
"https://api.weibo.com/oauth2/access_token", {params: {
code: query.code,
client_id: Meteor.accounts.weibo._appId,
client_id: Meteor.accounts.weibo._clientId,
client_secret: Meteor.accounts.weibo._secret,
redirect_uri: Meteor.accounts.weibo._appUrl + "/_oauth/weibo?close",
grant_type: 'authorization_code'