oidc: flatten the export list
This commit is contained in:
+18
-19
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user