Remove Oauth clients code

This commit is contained in:
Johannes Zellner
2020-02-06 16:57:33 +01:00
parent 2854462e0e
commit 2b6bf8d195
19 changed files with 105 additions and 1436 deletions

58
src/tokens.js Normal file
View File

@@ -0,0 +1,58 @@
'use strict';
exports = module.exports = {
addTokenByUserId: addTokenByUserId,
// token client ids. we categorize them so we can have different restrictions based on the client
ID_WEBADMIN: 'cid-webadmin', // dashboard oauth
ID_SDK: 'cid-sdk', // created by user via dashboard
ID_CLI: 'cid-cli' // created via cli tool
};
let assert = require('assert'),
BoxError = require('./boxerror.js'),
hat = require('./hat.js'),
uuid = require('uuid'),
tokendb = require('./tokendb.js');
function validateTokenName(name) {
assert.strictEqual(typeof name, 'string');
if (name.length > 64) return new BoxError(BoxError.BAD_FIELD, 'name too long', { field: 'name' });
return null;
}
function addTokenByUserId(clientId, userId, expiresAt, options, callback) {
assert.strictEqual(typeof clientId, 'string');
assert.strictEqual(typeof userId, 'string');
assert.strictEqual(typeof expiresAt, 'number');
assert.strictEqual(typeof options, 'object');
assert.strictEqual(typeof callback, 'function');
const name = options.name || '';
let error = validateTokenName(name);
if (error) return callback(error);
const token = {
id: 'tid-' + uuid.v4(),
accessToken: hat(8 * 32),
identifier: userId,
clientId: clientId,
expires: expiresAt,
scope: 'unused',
name: name
};
tokendb.add(token, function (error) {
if (error) return callback(error);
callback(null, {
accessToken: token.accessToken,
tokenScopes: 'unused',
identifier: userId,
clientId: clientId,
expires: expiresAt
});
});
}