diff --git a/src/addons.js b/src/addons.js index 5d1538381..ef312b453 100644 --- a/src/addons.js +++ b/src/addons.js @@ -21,7 +21,7 @@ var appdb = require('./appdb.js'), async = require('async'), clients = require('./clients.js'), config = require('./config.js'), - DatabaseError = require('./databaseerror.js'), + ClientsError = clients.ClientsError, debug = require('debug')('box:addons'), docker = require('./docker.js'), dockerConnection = docker.connection, @@ -287,7 +287,7 @@ function setupOauth(app, options, callback) { var scope = 'profile'; clients.delByAppIdAndType(appId, clients.TYPE_OAUTH, function (error) { // remove existing creds - if (error && error.reason !== DatabaseError.NOT_FOUND) return callback(error); + if (error && error.reason !== ClientsError.NOT_FOUND) return callback(error); clients.add(appId, clients.TYPE_OAUTH, redirectURI, scope, function (error, result) { if (error) return callback(error); @@ -313,7 +313,7 @@ function teardownOauth(app, options, callback) { debugApp(app, 'teardownOauth'); clients.delByAppIdAndType(app.id, clients.TYPE_OAUTH, function (error) { - if (error && error.reason !== DatabaseError.NOT_FOUND) console.error(error); + if (error && error.reason !== ClientsError.NOT_FOUND) console.error(error); appdb.unsetAddonConfig(app.id, 'oauth', callback); }); @@ -328,7 +328,7 @@ function setupSimpleAuth(app, options, callback) { var scope = 'profile'; clients.delByAppIdAndType(app.id, clients.TYPE_SIMPLE_AUTH, function (error) { // remove existing creds - if (error && error.reason !== DatabaseError.NOT_FOUND) return callback(error); + if (error && error.reason !== ClientsError.NOT_FOUND) return callback(error); clients.add(appId, clients.TYPE_SIMPLE_AUTH, '', scope, function (error, result) { if (error) return callback(error); @@ -356,7 +356,7 @@ function teardownSimpleAuth(app, options, callback) { debugApp(app, 'teardownSimpleAuth'); clients.delByAppIdAndType(app.id, clients.TYPE_SIMPLE_AUTH, function (error) { - if (error && error.reason !== DatabaseError.NOT_FOUND) console.error(error); + if (error && error.reason !== ClientsError.NOT_FOUND) console.error(error); appdb.unsetAddonConfig(app.id, 'simpleauth', callback); }); diff --git a/src/apptask.js b/src/apptask.js index 27f241d9d..fb6f26c82 100644 --- a/src/apptask.js +++ b/src/apptask.js @@ -38,8 +38,8 @@ var addons = require('./addons.js'), certificates = require('./certificates.js'), clients = require('./clients.js'), config = require('./config.js'), + ClientsError = clients.ClientsError, database = require('./database.js'), - DatabaseError = require('./databaseerror.js'), debug = require('debug')('box:apptask'), docker = require('./docker.js'), ejs = require('ejs'), @@ -172,7 +172,7 @@ function removeOAuthProxyCredentials(app, callback) { assert.strictEqual(typeof callback, 'function'); clients.delByAppIdAndType(app.id, clients.TYPE_PROXY, function (error) { - if (error && error.reason !== DatabaseError.NOT_FOUND) { + if (error && error.reason !== ClientsError.NOT_FOUND) { debugApp(app, 'Error removing OAuth client id', error); return callback(error); } diff --git a/src/auth.js b/src/auth.js index ac41edd5b..d253b0564 100644 --- a/src/auth.js +++ b/src/auth.js @@ -12,11 +12,11 @@ var assert = require('assert'), BearerStrategy = require('passport-http-bearer').Strategy, clients = require('./clients'), ClientPasswordStrategy = require('passport-oauth2-client-password').Strategy, + ClientsError = clients.ClientsError, DatabaseError = require('./databaseerror'), debug = require('debug')('box:auth'), LocalStrategy = require('passport-local').Strategy, crypto = require('crypto'), - groups = require('./groups'), passport = require('passport'), tokendb = require('./tokendb'), user = require('./user'), @@ -67,7 +67,7 @@ function initialize(callback) { // username is actually client id here // password is client secret clients.get(username, function (error, client) { - if (error && error.reason === DatabaseError.NOT_FOUND) return callback(null, false); + if (error && error.reason === ClientsError.NOT_FOUND) return callback(null, false); if (error) return callback(error); if (client.clientSecret != password) return callback(null, false); return callback(null, client); @@ -85,7 +85,7 @@ function initialize(callback) { passport.use(new ClientPasswordStrategy(function (clientId, clientSecret, callback) { clients.get(clientId, function(error, client) { - if (error && error.reason === DatabaseError.NOT_FOUND) return callback(null, false); + if (error && error.reason === ClientsError.NOT_FOUND) return callback(null, false); if (error) { return callback(error); } if (client.clientSecret != clientSecret) { return callback(null, false); } return callback(null, client); diff --git a/src/routes/oauth2.js b/src/routes/oauth2.js index 1aecefe3f..1b66c0452 100644 --- a/src/routes/oauth2.js +++ b/src/routes/oauth2.js @@ -5,8 +5,8 @@ var appdb = require('../appdb'), assert = require('assert'), authcodedb = require('../authcodedb'), clients = require('../clients'), + ClientsError = clients.ClientsError, config = require('../config.js'), - constants = require('../constants.js'), DatabaseError = require('../databaseerror'), debug = require('debug')('box:routes/oauth2'), eventlog = require('../eventlog.js'), @@ -405,7 +405,7 @@ var authorization = [ debug('authorization: client %s with callback to %s.', clientId, redirectURI); clients.get(clientId, function (error, client) { - if (error && error.reason === DatabaseError.NOT_FOUND) return callback(null, false); + if (error && error.reason === ClientsError.NOT_FOUND) return callback(null, false); if (error) return callback(error); // ignore the origin passed into form the client, but use the one from the clientdb diff --git a/src/simpleauth.js b/src/simpleauth.js index a1b92c7f6..f6ecb964d 100644 --- a/src/simpleauth.js +++ b/src/simpleauth.js @@ -86,7 +86,7 @@ function login(req, res, next) { if (typeof req.body.password !== 'string') return next(new HttpError(400, 'password is required')); loginLogic(req.body.clientId, req.body.username, req.body.password, function (error, result) { - if (error && error.reason === DatabaseError.NOT_FOUND) return next(new HttpError(401, 'Unknown client')); + if (error && error.reason === ClientsError.NOT_FOUND) return next(new HttpError(401, 'Unknown client')); if (error && error.reason === ClientsError.INVALID_CLIENT) return next(new HttpError(401, 'Unkown client')); if (error && error.reason === UserError.NOT_FOUND) return next(new HttpError(401, 'Forbidden')); if (error && error.reason === AppsError.NOT_FOUND) return next(new HttpError(401, 'Unkown app'));