diff --git a/src/apptask.js b/src/apptask.js index d8a357119..dd1763d7a 100644 --- a/src/apptask.js +++ b/src/apptask.js @@ -37,6 +37,7 @@ var addons = require('./addons.js'), backups = require('./backups.js'), certificates = require('./certificates.js'), clientdb = require('./clientdb.js'), + clients = require('./clients.js'), config = require('./config.js'), database = require('./database.js'), DatabaseError = require('./databaseerror.js'), @@ -57,7 +58,6 @@ var addons = require('./addons.js'), superagent = require('superagent'), sysinfo = require('./sysinfo.js'), util = require('util'), - uuid = require('node-uuid'), waitForDns = require('./waitfordns.js'), _ = require('underscore'); @@ -163,19 +163,18 @@ function allocateOAuthProxyCredentials(app, callback) { if (!nginx.requiresOAuthProxy(app)) return callback(null); - var id = 'cid-' + uuid.v4(); var clientSecret = hat(256); var redirectURI = 'https://' + config.appFqdn(app.location); var scope = 'profile'; - clientdb.add(id, app.id, clientdb.TYPE_PROXY, clientSecret, redirectURI, scope, callback); + clients.add(app.id, clientdb.TYPE_PROXY, clientSecret, redirectURI, scope, callback); } function removeOAuthProxyCredentials(app, callback) { assert.strictEqual(typeof app, 'object'); assert.strictEqual(typeof callback, 'function'); - clientdb.delByAppIdAndType(app.id, clientdb.TYPE_PROXY, function (error) { + clients.delByAppIdAndType(app.id, clientdb.TYPE_PROXY, function (error) { if (error && error.reason !== DatabaseError.NOT_FOUND) { debugApp(app, 'Error removing OAuth client id', error); return callback(error); diff --git a/src/auth.js b/src/auth.js index 05246d930..c38d0974a 100644 --- a/src/auth.js +++ b/src/auth.js @@ -10,7 +10,7 @@ exports = module.exports = { var assert = require('assert'), BasicStrategy = require('passport-http').BasicStrategy, BearerStrategy = require('passport-http-bearer').Strategy, - clientdb = require('./clientdb'), + clients = require('./clients'), ClientPasswordStrategy = require('passport-oauth2-client-password').Strategy, DatabaseError = require('./databaseerror'), debug = require('debug')('box:auth'), @@ -67,7 +67,7 @@ function initialize(callback) { debug('BasicStrategy: detected client id %s instead of username:password', username); // username is actually client id here // password is client secret - clientdb.get(username, function (error, client) { + clients.get(username, function (error, client) { if (error && error.reason === DatabaseError.NOT_FOUND) return callback(null, false); if (error) return callback(error); if (client.clientSecret != password) return callback(null, false); @@ -85,7 +85,7 @@ function initialize(callback) { })); passport.use(new ClientPasswordStrategy(function (clientId, clientSecret, callback) { - clientdb.get(clientId, function(error, client) { + clients.get(clientId, function(error, client) { if (error && error.reason === DatabaseError.NOT_FOUND) return callback(null, false); if (error) { return callback(error); } if (client.clientSecret != clientSecret) { return callback(null, false); } diff --git a/src/clients.js b/src/clients.js index 513df344f..27cb76434 100644 --- a/src/clients.js +++ b/src/clients.js @@ -10,6 +10,7 @@ exports = module.exports = { getByAppIdAndType: getByAppIdAndType, getClientTokensByUserId: getClientTokensByUserId, delClientTokensByUserId: delClientTokensByUserId, + delByAppIdAndType: delByAppIdAndType, // keep this in sync with start.sh ADMIN_SCOPES that generates the cid-webadmin SCOPE_APPS: 'apps', @@ -219,3 +220,14 @@ function delClientTokensByUserId(clientId, userId, callback) { callback(null); }); } + +function delByAppIdAndType(appId, type, callback) { + assert.strictEqual(typeof appId, 'string'); + assert.strictEqual(typeof type, 'string'); + assert.strictEqual(typeof callback, 'function'); + + clientdb.delByAppIdAndType(appId, type, function (error) { + if (error) return callback(error); + callback(null); + }); +}