tokens: add lastUsedTime

This commit is contained in:
Girish Ramakrishnan
2021-03-15 12:47:57 -07:00
parent 750f313c6a
commit 176388111c
15 changed files with 222 additions and 81 deletions

View File

@@ -1,19 +1,22 @@
'use strict';
exports = module.exports = {
verifyToken: verifyToken
verifyToken
};
var assert = require('assert'),
BoxError = require('./boxerror.js'),
tokendb = require('./tokendb.js'),
debug = require('debug')('box:accesscontrol'),
tokens = require('./tokens.js'),
users = require('./users.js');
const NOOP_CALLBACK = function (error) { if (error) debug(error); };
function verifyToken(accessToken, callback) {
assert.strictEqual(typeof accessToken, 'string');
assert.strictEqual(typeof callback, 'function');
tokendb.getByAccessToken(accessToken, function (error, token) {
tokens.getByAccessToken(accessToken, function (error, token) {
if (error && error.reason === BoxError.NOT_FOUND) return callback(new BoxError(BoxError.INVALID_CREDENTIALS));
if (error) return callback(error);
@@ -23,6 +26,8 @@ function verifyToken(accessToken, callback) {
if (!user.active) return callback(new BoxError(BoxError.INVALID_CREDENTIALS));
tokens.update(token.id, { lastUsedTime: new Date() }, NOOP_CALLBACK);
callback(null, user);
});
});