oidc: flatten the export list

This commit is contained in:
Girish Ramakrishnan
2024-12-02 08:31:35 +01:00
parent 6623061c2c
commit dc3d23c27b
3 changed files with 37 additions and 39 deletions
+18 -19
View File
@@ -1,13 +1,12 @@
'use strict';
exports = module.exports = {
clients: {
get,
list,
add,
update,
del
},
addClient,
listClients,
getClient,
updateClient,
delClient,
destroyUserSession
};
@@ -21,7 +20,7 @@ const assert = require('assert'),
safe = require('safetydance'),
tokens = require('../tokens.js');
async function add(req, res, next) {
async function addClient(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
if (typeof req.body.name !== 'string' || !req.body.name) return next(new HttpError(400, 'name must be non-empty string'));
@@ -40,7 +39,7 @@ async function add(req, res, next) {
loginRedirectUri: req.body.loginRedirectUri
};
const [error] = await safe(oidc.clients.add(clientId, data));
const [error] = await safe(oidc.addClient(clientId, data));
if (error) return next(BoxError.toHttpError(error));
data.id = clientId;
@@ -48,10 +47,10 @@ async function add(req, res, next) {
next(new HttpSuccess(201, data));
}
async function get(req, res, next) {
async function getClient(req, res, next) {
assert.strictEqual(typeof req.params.clientId, 'string');
const [error, client] = await safe(oidc.clients.get(req.params.clientId));
const [error, client] = await safe(oidc.getClient(req.params.clientId));
if (error) return next(BoxError.toHttpError(error));
if (!client) return next(new HttpError(404, 'OpenID connect client not found'));
if (client.appId) return next(new HttpError(422, 'OpenID connect client from an internal app'));
@@ -59,7 +58,7 @@ async function get(req, res, next) {
next(new HttpSuccess(200, client));
}
async function update(req, res, next) {
async function updateClient(req, res, next) {
assert.strictEqual(typeof req.params.clientId, 'string');
assert.strictEqual(typeof req.body, 'object');
@@ -67,7 +66,7 @@ async function update(req, res, next) {
if (typeof req.body.loginRedirectUri !== 'string' || !req.body.loginRedirectUri) return next(new HttpError(400, 'loginRedirectUri must be non-empty string'));
if (req.body.tokenSignatureAlgorithm !== 'EdDSA' && req.body.tokenSignatureAlgorithm !== 'RS256') return next(new HttpError(400, 'tokenSignatureAlgorithm must be either EdDSA or RS256'));
const [error, client] = await safe(oidc.clients.get(req.params.clientId));
const [error, client] = await safe(oidc.getClient(req.params.clientId));
if (error) return next(BoxError.toHttpError(error));
if (!client) return next(new HttpError(404, 'OpenID connect client not found'));
if (client.appId) return next(new HttpError(422, 'OpenID connect client from an internal app'));
@@ -79,28 +78,28 @@ async function update(req, res, next) {
loginRedirectUri: req.body.loginRedirectUri
};
const [updateError] = await safe(oidc.clients.update(req.params.clientId, data));
const [updateError] = await safe(oidc.updateClient(req.params.clientId, data));
if (updateError) return next(BoxError.toHttpError(updateError));
next(new HttpSuccess(201, {}));
}
async function list(req, res, next) {
const [error, result] = await safe(oidc.clients.list());
async function listClients(req, res, next) {
const [error, result] = await safe(oidc.listClients());
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(200, { clients: result.filter(client => !client.appId) }));
}
async function del(req, res, next) {
async function delClient(req, res, next) {
assert.strictEqual(typeof req.params.clientId, 'string');
const [error, client] = await safe(oidc.clients.get(req.params.clientId));
const [error, client] = await safe(oidc.oidc.getClient(req.params.clientId));
if (error) return next(BoxError.toHttpError(error));
if (!client) return next(new HttpError(404, 'OpenID connect client not found'));
if (client.appId) return next(new HttpError(422, 'OpenID connect client from an internal app'));
const [delError] = await safe(oidc.clients.del(req.params.clientId));
const [delError] = await safe(oidc.delClient(req.params.clientId));
if (delError) return next(BoxError.toHttpError(delError));
next(new HttpSuccess(204));