oidc-provider 9.13.3 with PKCE, ES256, crosscode.identity/1 claims and back-channel logout; clients are the linked products (Connect). Sign-in steps (password, sign-up, email check, 2FA and its setup, privacy notice, news question, password reset) survive to the product. Account page and admin API, church profile, export and deletion fan-out, Hub v2 client, jobs. End-to-end tests with a test product on openid-client. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
52 lines
3.4 KiB
TypeScript
52 lines
3.4 KiB
TypeScript
/**
|
|
* The few pages oidc-provider renders itself (an error, the sign-out confirmation, "signed out"),
|
|
* in the church's colours. No inline scripts (the CSP forbids them): the sign-out page submits
|
|
* itself with /api/static/logout.js.
|
|
*/
|
|
import type { KoaContextWithOIDC } from 'oidc-provider';
|
|
import type { Ctx } from '../context.js';
|
|
import { branding } from '../church/profile.js';
|
|
|
|
const esc = (s: unknown) => String(s ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c]!);
|
|
|
|
async function page(ctx: Ctx, title: string, body: string): Promise<string> {
|
|
const b = await branding(ctx).catch(() => ({ name: 'Sign in', colours: { primary: '#1f4e79' }, logoUrl: null }));
|
|
return `<!doctype html><html lang="en-ZA"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="robots" content="noindex">
|
|
<title>${esc(title)} · ${esc(b.name)}</title>
|
|
<style>body{font-family:system-ui,sans-serif;background:#f7f7f8;color:#1f2937;margin:0;display:flex;min-height:100vh;align-items:center;justify-content:center;padding:16px}
|
|
main{background:#fff;border-radius:16px;box-shadow:0 1px 3px rgba(0,0,0,.08);padding:32px;max-width:420px;width:100%;text-align:center}
|
|
h1{font-size:1.25rem;margin:0 0 12px}p{color:#4b5563;line-height:1.5}button,a.btn{display:inline-block;background:${esc(b.colours.primary)};color:#fff;border:0;border-radius:10px;padding:10px 20px;font-size:1rem;text-decoration:none;cursor:pointer}
|
|
img{max-height:56px;margin-bottom:16px}</style></head>
|
|
<body><main>${b.logoUrl ? `<img src="${esc(b.logoUrl)}" alt="">` : ''}<p style="margin:0 0 8px;font-weight:600">${esc(b.name)}</p>${body}</main></body></html>`;
|
|
}
|
|
|
|
export function renderError(ctx: Ctx) {
|
|
return async (k: KoaContextWithOIDC, out: { error: string; error_description?: string }, err?: Error) => {
|
|
console.warn(`[oidc] ${out.error}: ${out.error_description ?? ''}${err && !(err as { expose?: boolean }).expose ? ` (${err.stack})` : ''}`);
|
|
k.type = 'html';
|
|
const message = out.error === 'invalid_redirect_uri' || out.error === 'invalid_client'
|
|
? 'This sign-in link isn\'t from one of the church\'s sites, so it was stopped.'
|
|
: out.error_description || 'Something went wrong with signing in.';
|
|
k.body = await page(ctx, 'Sign-in problem', `<h1>We couldn't sign you in</h1><p>${esc(message)}</p><a class="btn" href="/account">Go to your account</a>`);
|
|
};
|
|
}
|
|
|
|
export function renderLogout(ctx: Ctx) {
|
|
return async (k: KoaContextWithOIDC, form: string) => {
|
|
k.type = 'html';
|
|
k.body = await page(ctx, 'Signing out', `${form}<h1>Signing you out…</h1><p>You'll be signed out of all the church's sites.</p>
|
|
<button form="op.logoutForm" type="submit" name="logout" value="yes">Sign out</button>
|
|
<script src="/api/static/logout.js"></script>`);
|
|
};
|
|
}
|
|
|
|
export function renderLoggedOut(ctx: Ctx) {
|
|
return async (k: KoaContextWithOIDC) => {
|
|
k.type = 'html';
|
|
k.body = await page(ctx, 'Signed out', '<h1>You\'re signed out</h1><p>You\'ve been signed out of all the church\'s sites.</p><a class="btn" href="/account">Sign in again</a>');
|
|
};
|
|
}
|
|
|
|
/** Submits the sign-out form straight away (the person already chose to sign out on the product). */
|
|
export const LOGOUT_JS = 'document.addEventListener("DOMContentLoaded",function(){var f=document.getElementById("op.logoutForm");if(f){var i=document.createElement("input");i.type="hidden";i.name="logout";i.value="yes";f.appendChild(i);f.submit();}});';
|