diff --git a/src/oidc.js b/src/oidc.js index b2660cd8a..ae4a5305e 100644 --- a/src/oidc.js +++ b/src/oidc.js @@ -105,7 +105,7 @@ class CloudronAdapter { } else { this.fileStorePath = path.join(paths.OIDC_STORE_DIR, `${name}.json`); - debug(`Creating adapter for ${name} backed by ${this.fileStorePath}`); + debug(`Creating storage adapter for ${name} backed by ${this.fileStorePath}`); let data = {}; try { @@ -512,6 +512,27 @@ async function postLogoutSuccessSource(ctx) { ctx.body = ejs.render(fs.readFileSync(path.join(__dirname, 'oidc_templates/post_logout.ejs'), 'utf8'), data, {}); } +async function findAccount(ctx, id) { + debug(`findAccount id:${id}`); + + return { + accountId: id, + async claims(use, scope) { return await claims(id, use, scope); }, + }; +} + +async function renderError(ctx, out, error) { + const data = { + dashboardOrigin: settings.dashboardOrigin(), + error + }; + + debug('renderError:', error); + + ctx.type = 'html'; + ctx.body = ejs.render(fs.readFileSync(path.join(__dirname, 'oidc_templates/error.ejs'), 'utf8'), data, {}); +} + async function start() { const app = express(); @@ -520,14 +541,8 @@ async function start() { const { Provider } = await import('oidc-provider'); const configuration = { - async findAccount(ctx, id) { - debug(`findAccount id:${id}`); - - return { - accountId: id, - async claims(use, scope) { return await claims(id, use, scope); }, - }; - }, + findAccount, + renderError, adapter: CloudronAdapter, interactions: { url: async function(ctx, interaction) { diff --git a/src/oidc_templates/error.ejs b/src/oidc_templates/error.ejs new file mode 100644 index 000000000..cc434bd04 --- /dev/null +++ b/src/oidc_templates/error.ejs @@ -0,0 +1,42 @@ + + + + + + + OpenID Connect Error + + + + + + + + + + + + + +
+
+
+
+
+ +
+

OpenID Connect Error

+
+
+
+
+
+ <%- Object.entries(error).map(([key, value]) => `
${key}: ${value}
`).join('') %> +
+
+
+
+
+ + +