diff --git a/src/oidc_templates/interaction.ejs b/dashboard/oidc_interaction_abort.html similarity index 71% rename from src/oidc_templates/interaction.ejs rename to dashboard/oidc_interaction_abort.html index 728830445..50ccdd652 100644 --- a/src/oidc_templates/interaction.ejs +++ b/dashboard/oidc_interaction_abort.html @@ -4,7 +4,7 @@ - Authorize <%= name %> + Authorize ##NAME## @@ -49,43 +49,29 @@ -<% if (hasAccess) { -%> -
- -
-<% } else { -%>
- +
-

You do not have access to <%= name %>

+

You do not have access to ##NAME##


-<% } -%> - - diff --git a/dashboard/oidc_interaction_confirm.html b/dashboard/oidc_interaction_confirm.html new file mode 100644 index 000000000..b90a17cab --- /dev/null +++ b/dashboard/oidc_interaction_confirm.html @@ -0,0 +1,63 @@ + + + + + + + Authorize ##NAME## + + + + + + + + + + + + + +
+ +
+ + + + + diff --git a/src/oidc.js b/src/oidc.js index 7c49f9c41..07302dcbb 100644 --- a/src/oidc.js +++ b/src/oidc.js @@ -26,7 +26,6 @@ const assert = require('assert'), database = require('./database.js'), debug = require('debug')('box:oidc'), dns = require('./dns.js'), - ejs = require('ejs'), express = require('express'), eventlog = require('./eventlog.js'), fs = require('fs'), @@ -503,38 +502,52 @@ function renderInteractionPage(provider) { return res.send(html); } case 'consent': { - const options = { - hasAccess: false, - submitUrl: '', - iconUrl: '/api/v1/cloudron/avatar', - name: client?.name || '', - footer: marked.parse(await branding.renderFooter()) + let hasAccess = false; + + const data = { + ICON_URL: '/api/v1/cloudron/avatar', + NAME: client?.name || '', + FOOTER: marked.parse(await branding.renderFooter()) }; // check if user has access to the app if client refers to an app if (app) { const user = await users.get(session.accountId); - options.name = app.label || app.fqdn; - options.iconUrl = app.iconUrl; - options.hasAccess = apps.canAccess(app, user); + data.NAME = app.label || app.fqdn; + data.ICON_URL = app.iconUrl; + hasAccess = apps.canAccess(app, user); } else { - options.hasAccess = true; + hasAccess = true; } - options.submitUrl = `${ROUTE_PREFIX}/interaction/${uid}/${options.hasAccess ? 'confirm' : 'abort'}`; + data.SUBMIT_URL = `${ROUTE_PREFIX}/interaction/${uid}/${hasAccess ? 'confirm' : 'abort'}`; - return res.render('interaction', options); + let html = fs.readFileSync(path.join(__dirname, hasAccess ? '/../dashboard/oidc_interaction_confirm.html' : '/../dashboard/oidc_interaction_abort.html'), 'utf8'); + Object.keys(data).forEach(key => { + html = html.replaceAll(`##${key}##`, data[key]); + }); + + return res.send(html); } default: return undefined; } } catch (error) { debug('route interaction get error', error); - return res.render('error', { - errorMessage: error.error_description || 'Internal error', - footer: marked.parse(await branding.renderFooter()) + + const data = { + ERROR_MESSAGE: error.error_description || 'Internal error', + FOOTER: marked.parse(await branding.renderFooter()) + }; + + let html = fs.readFileSync(path.join(__dirname, '/../dashboard/oidc_error.html'), 'utf8'); + Object.keys(data).forEach(key => { + html = html.replaceAll(`##${key}##`, data[key]); }); + + res.set('Content-Type', 'text/html'); + return res.send(html); } }; } @@ -768,7 +781,7 @@ async function renderError(ctx, out, error) { }; debug('renderError: %o', error); - let html = fs.readFileSync(path.join(__dirname, '/..dashboard/oidc_error.html'), 'utf8'); + let html = fs.readFileSync(path.join(__dirname, '/../dashboard/oidc_error.html'), 'utf8'); Object.keys(data).forEach(key => { html = html.replaceAll(`##${key}##`, data[key]); }); @@ -915,9 +928,6 @@ async function start() { app.enable('trust proxy'); provider.proxy = true; - app.set('views', path.join(__dirname, 'oidc_templates')); - app.set('view engine', 'ejs'); - const json = express.json({ strict: true, limit: '2mb' }); function setNoCache(req, res, next) { res.set('cache-control', 'no-store');