move tokens.ID_ into oidcClients.ID_

This commit is contained in:
Girish Ramakrishnan
2025-06-11 22:53:29 +02:00
parent 00da650524
commit d112d6308c
11 changed files with 48 additions and 42 deletions
+5 -4
View File
@@ -19,6 +19,7 @@ const assert = require('assert'),
eventlog = require('../eventlog.js'),
HttpError = require('connect-lastmile').HttpError,
HttpSuccess = require('connect-lastmile').HttpSuccess,
oidcClients = require('../oidcclients.js'),
safe = require('safetydance'),
speakeasy = require('speakeasy'),
tokens = require('../tokens.js'),
@@ -29,18 +30,18 @@ async function login(req, res, next) {
if ('type' in req.body && typeof req.body.type !== 'string') return next(new HttpError(400, 'type must be a string'));
const type = req.body.type || tokens.ID_WEBADMIN;
const type = req.body.type || oidcClients.ID_WEBADMIN;
const ip = req.headers['x-forwarded-for'] || req.socket.remoteAddress || null;
const userAgent = req.headers['user-agent'] || '';
const tokenTypeError = tokens.validateTokenType(type);
const tokenTypeError = oidcClients.validateId(type);
if (tokenTypeError) return next(new HttpError(400, tokenTypeError.message));
const [error, token] = await safe(tokens.add({ clientId: type, identifier: req.user.id, allowedIpRanges: '', expires: Date.now() + constants.DEFAULT_TOKEN_EXPIRATION_MSECS }));
if (error) return next(new HttpError(500, error));
const auditSource = AuditSource.fromRequest(req);
await eventlog.add(req.user.ghost ? eventlog.ACTION_USER_LOGIN_GHOST : eventlog.ACTION_USER_LOGIN, auditSource, { userId: req.user.id, user: users.removePrivateFields(req.user), type, appId: tokens.ID_CLI });
await eventlog.add(req.user.ghost ? eventlog.ACTION_USER_LOGIN_GHOST : eventlog.ACTION_USER_LOGIN, auditSource, { userId: req.user.id, user: users.removePrivateFields(req.user), type, appId: oidcClients.ID_CLI });
await safe(users.notifyLoginLocation(req.user, ip, userAgent, auditSource), { debug });
next(new HttpSuccess(200, token));
@@ -90,7 +91,7 @@ async function passwordReset(req, res, next) {
if (error && error.reason === BoxError.BAD_FIELD) return next(new HttpError(400, error.message));
if (error) return next(BoxError.toHttpError(error));
const [addError, result] = await safe(tokens.add({ clientId: tokens.ID_WEBADMIN, identifier: userObject.id, allowedIpRanges: '', expires: Date.now() + constants.DEFAULT_TOKEN_EXPIRATION_MSECS }));
const [addError, result] = await safe(tokens.add({ clientId: oidcClients.ID_WEBADMIN, identifier: userObject.id, allowedIpRanges: '', expires: Date.now() + constants.DEFAULT_TOKEN_EXPIRATION_MSECS }));
if (addError) return next(BoxError.toHttpError(addError));
next(new HttpSuccess(202, { accessToken: result.accessToken }));
+3 -2
View File
@@ -9,6 +9,7 @@ const apps = require('../../apps.js'),
fs = require('fs'),
mailer = require('../../mailer.js'),
nock = require('nock'),
oidcClients = require('../../oidcclients.js'),
oidcServer = require('../../oidcserver.js'),
safe = require('safetydance'),
server = require('../../server.js'),
@@ -155,7 +156,7 @@ async function setup() {
expect(response.status).to.equal(201);
admin.id = response.body.id;
// HACK to get a token for second user (passwords are generated and the user should have gotten a password setup link...)
const token1 = await tokens.add({ identifier: admin.id, clientId: tokens.ID_WEBADMIN, expires: Date.now() + (60 * 60 * 1000), name: 'fromtest', allowedIpRanges: '' });
const token1 = await tokens.add({ identifier: admin.id, clientId: oidcClients.ID_WEBADMIN, expires: Date.now() + (60 * 60 * 1000), name: 'fromtest', allowedIpRanges: '' });
admin.token = token1.accessToken;
// create user
@@ -165,7 +166,7 @@ async function setup() {
expect(response.status).to.equal(201);
user.id = response.body.id;
// HACK to get a token for second user (passwords are generated and the user should have gotten a password setup link...)
const token2 = await tokens.add({ identifier: user.id, clientId: tokens.ID_WEBADMIN, expires: Date.now() + (60 * 60 * 1000), name: 'fromtest', allowedIpRanges: '' });
const token2 = await tokens.add({ identifier: user.id, clientId: oidcClients.ID_WEBADMIN, expires: Date.now() + (60 * 60 * 1000), name: 'fromtest', allowedIpRanges: '' });
user.token = token2.accessToken;
// create app object
+2 -1
View File
@@ -12,6 +12,7 @@ const assert = require('assert'),
BoxError = require('../boxerror.js'),
HttpError = require('connect-lastmile').HttpError,
HttpSuccess = require('connect-lastmile').HttpSuccess,
oidcClients = require('../oidcclients.js'),
safe = require('safetydance'),
tokens = require('../tokens.js');
@@ -59,7 +60,7 @@ async function add(req, res, next) {
const scope = req.body.scope || null;
const allowedIpRanges = req.body.allowedIpRanges || '';
const [error, result] = await safe(tokens.add({ clientId: tokens.ID_SDK, identifier: req.user.id, expires: expiresAt, name: req.body.name, scope, allowedIpRanges }));
const [error, result] = await safe(tokens.add({ clientId: oidcClients.ID_SDK, identifier: req.user.id, expires: expiresAt, name: req.body.name, scope, allowedIpRanges }));
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(201, result));