Add oidc.name and oidc.appId fields
This commit is contained in:
+28
-13
@@ -31,22 +31,27 @@ const assert = require('assert'),
|
||||
util = require('util');
|
||||
|
||||
const OIDC_CLIENTS_TABLE_NAME = 'oidcClients';
|
||||
const OIDC_CLIENTS_FIELDS = [ 'id', 'secret', 'loginRedirectUri', 'logoutRedirectUri' ];
|
||||
const OIDC_CLIENTS_FIELDS = [ 'id', 'secret', 'name', 'appId', 'loginRedirectUri', 'logoutRedirectUri' ];
|
||||
|
||||
const ROUTE_PREFIX = '/openid';
|
||||
|
||||
let gHttpServer = null;
|
||||
|
||||
async function clientsAdd(id, secret, loginRedirectUri, logoutRedirectUri) {
|
||||
// -----------------------------
|
||||
// Database model
|
||||
// -----------------------------
|
||||
async function clientsAdd(id, data) {
|
||||
assert.strictEqual(typeof id, 'string');
|
||||
assert.strictEqual(typeof secret, 'string');
|
||||
assert.strictEqual(typeof loginRedirectUri, 'string');
|
||||
assert.strictEqual(typeof logoutRedirectUri, 'string');
|
||||
assert.strictEqual(typeof data.secret, 'string');
|
||||
assert.strictEqual(typeof data.loginRedirectUri, 'string');
|
||||
assert.strictEqual(typeof data.logoutRedirectUri, 'string');
|
||||
assert.strictEqual(typeof data.name, 'string');
|
||||
assert.strictEqual(typeof data.appId, 'string');
|
||||
|
||||
debug(`clientsAdd: id:${id} secret:${secret} loginRedirectUri:${loginRedirectUri} logoutRedirectUri:${logoutRedirectUri}`);
|
||||
debug(`clientsAdd: id:${id} secret:${data.secret} name:${data.name} appId:${data.appId} loginRedirectUri:${data.loginRedirectUri} logoutRedirectUri:${data.logoutRedirectUri}`);
|
||||
|
||||
const query = `INSERT INTO ${OIDC_CLIENTS_TABLE_NAME} (id, secret, loginRedirectUri, logoutRedirectUri) VALUES (?, ?, ?, ?)`;
|
||||
const args = [ id, secret, loginRedirectUri, logoutRedirectUri ];
|
||||
const query = `INSERT INTO ${OIDC_CLIENTS_TABLE_NAME} (id, secret, name, appId, loginRedirectUri, logoutRedirectUri) VALUES (?, ?, ?, ?, ?, ?)`;
|
||||
const args = [ id, data.secret, data.name, data.appId, data.loginRedirectUri, data.logoutRedirectUri ];
|
||||
|
||||
const [error] = await safe(database.query(query, args));
|
||||
if (error && error.code === 'ER_DUP_ENTRY') throw new BoxError(BoxError.ALREADY_EXISTS, 'client already exists');
|
||||
@@ -64,13 +69,17 @@ async function clientsGet(id) {
|
||||
return result[0];
|
||||
}
|
||||
|
||||
async function clientsUpdate(id, secret, loginRedirectUri, logoutRedirectUri) {
|
||||
async function clientsUpdate(id, data) {
|
||||
assert.strictEqual(typeof id, 'string');
|
||||
assert.strictEqual(typeof secret, 'string');
|
||||
assert.strictEqual(typeof loginRedirectUri, 'string');
|
||||
assert.strictEqual(typeof logoutRedirectUri, 'string');
|
||||
assert.strictEqual(typeof data.secret, 'string');
|
||||
assert.strictEqual(typeof data.loginRedirectUri, 'string');
|
||||
assert.strictEqual(typeof data.logoutRedirectUri, 'string');
|
||||
assert.strictEqual(typeof data.name, 'string');
|
||||
assert.strictEqual(typeof data.appId, 'string');
|
||||
|
||||
const result = await database.query(`UPDATE ${OIDC_CLIENTS_TABLE_NAME} SET secret=?, loginRedirectUri=?, logoutRedirectUri=? WHERE id = ?`, [ secret, loginRedirectUri, logoutRedirectUri, id]);
|
||||
debug(`clientsUpdate: id:${id} secret:${data.secret} name:${data.name} appId:${data.appId} loginRedirectUri:${data.loginRedirectUri} logoutRedirectUri:${data.logoutRedirectUri}`);
|
||||
|
||||
const result = await database.query(`UPDATE ${OIDC_CLIENTS_TABLE_NAME} SET secret=?, name=?, appId=?, loginRedirectUri=?, logoutRedirectUri=? WHERE id = ?`, [ data.secret, data.name, data.appId, data.loginRedirectUri, data.logoutRedirectUri, id]);
|
||||
if (result.affectedRows !== 1) throw new BoxError(BoxError.NOT_FOUND, 'client not found');
|
||||
}
|
||||
|
||||
@@ -86,6 +95,9 @@ async function clientsList() {
|
||||
return results;
|
||||
}
|
||||
|
||||
// -----------------------------
|
||||
// Generic oidc node module data store model
|
||||
// -----------------------------
|
||||
class CloudronAdapter {
|
||||
/**
|
||||
*
|
||||
@@ -294,6 +306,9 @@ class CloudronAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------
|
||||
// Route handler
|
||||
// -----------------------------
|
||||
function renderInteractionPage(provider) {
|
||||
assert.strictEqual(typeof provider, 'object');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user