oidc: Provide custom error page

This commit is contained in:
Johannes Zellner
2023-03-21 15:12:55 +01:00
parent 2315cf330f
commit 8d7efc5701
2 changed files with 66 additions and 9 deletions
+24 -9
View File
@@ -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) {
+42
View File
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height" />
<title>OpenID Connect Error</title>
<!-- Theme CSS -->
<link type="text/css" rel="stylesheet" href="/theme.css">
<!-- Fontawesome -->
<link type="text/css" rel="stylesheet" href="/3rdparty/fontawesome/css/all.css"/>
<!-- Bootstrap Core JavaScript -->
<script type="text/javascript" src="/3rdparty/js/bootstrap.min.js"></script>
</head>
<body>
<div class="layout-root">
<div class="layout-content">
<div class="card" style="padding: 20px; margin-top: 100px; max-width: 620px;">
<div class="row">
<div class="col-md-12" style="text-align: center;">
<img width="128" height="128" style="margin-top: -84px" src="/api/v1/cloudron/avatar"/>
<br/>
<h1>OpenID Connect Error</h1>
</div>
</div>
<br/>
<div class="row">
<div class="col-md-12 text-center">
<%- Object.entries(error).map(([key, value]) => `<pre><strong>${key}</strong>: ${value}</pre>`).join('') %>
</div>
</div>
</div>
</div>
</div>
</body>
</html>