oidc: move routes to server.js for visibility

This commit is contained in:
Johannes Zellner
2023-03-14 14:19:29 +01:00
parent 2038a98e61
commit cef34bfbb7
2 changed files with 39 additions and 21 deletions
+27 -19
View File
@@ -2,7 +2,12 @@
exports = module.exports = {
getProvider,
attachInteractionRoutes
routes: {
renderInteractionPage,
interactionLogin,
interactionConfirm,
interactionAbort
}
};
const assert = require('assert'),
@@ -174,20 +179,11 @@ class CloudronAdapter {
}
}
function attachInteractionRoutes(routePrefix, app, provider) {
function renderInteractionPage(routePrefix, provider) {
assert.strictEqual(typeof routePrefix, 'string');
assert.strictEqual(typeof app, 'function'); // express app
assert.strictEqual(typeof provider, 'object');
function setNoCache(req, res, next) {
res.set('cache-control', 'no-store');
next();
}
// FIXME duplicate, all those routes should go to server.js
const json = middleware.json({ strict: true, limit: '2mb' }); // application/json
app.get(routePrefix + '/interaction/:uid', setNoCache, async (req, res, next) => {
return async function (req, res, next) {
try {
const { uid, prompt, params, session } = await provider.interactionDetails(req, res);
console.log('details', await provider.interactionDetails(req, res));
@@ -236,9 +232,13 @@ function attachInteractionRoutes(routePrefix, app, provider) {
return next(error);
}
});
};
}
app.post(routePrefix + '/interaction/:uid/login', json, setNoCache, async (req, res, next) => {
function interactionLogin(provider) {
assert.strictEqual(typeof provider, 'object');
return async function(req, res, next) {
const [detailsError, details] = await safe(provider.interactionDetails(req, res));
if (detailsError) return next(new HttpError(500, detailsError));
@@ -277,9 +277,13 @@ function attachInteractionRoutes(routePrefix, app, provider) {
debug(`route interaction login post result redirectTo:${redirectTo}`);
res.status(200).send({ redirectTo });
});
};
}
app.post(routePrefix + '/interaction/:uid/confirm', json, setNoCache, async (req, res, next) => {
function interactionConfirm(provider) {
assert.strictEqual(typeof provider, 'object');
return async function (req, res, next) {
try {
const interactionDetails = await provider.interactionDetails(req, res);
const { uid, prompt: { name, details }, params, session: { accountId } } = interactionDetails;
@@ -328,9 +332,13 @@ function attachInteractionRoutes(routePrefix, app, provider) {
} catch (err) {
next(err);
}
});
};
}
app.get(routePrefix + '/interaction/:uid/abort', setNoCache, async (req, res, next) => {
function interactionAbort(provider) {
assert.strictEqual(typeof provider, 'object');
return async function (req, res, next) {
debug(`route interaction abort`);
try {
@@ -342,7 +350,7 @@ function attachInteractionRoutes(routePrefix, app, provider) {
} catch (err) {
next(err);
}
});
};
}
/**