Accounts: Playwright on the real pages; interaction cookie path fix
The interaction address is now /api/v2/interaction/<uid> (redirecting to the sign-in page): oidc-provider scopes its cookie to that path, so every step's API call gets it. Before, a real browser never sent it and every sign-in 'expired'; the test browser now honours cookie paths too. 8 Playwright tests (deep link, wrong password, foreign return address, sign-up, reset mid-sign-in, 2FA set-up, account page, admin) on the real backend with an in-memory database, no Postgres needed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -51,7 +51,13 @@ export function interactionRouter(ctx: Ctx, provider: Provider) {
|
||||
return next(req, res, extra);
|
||||
});
|
||||
|
||||
r.get('/interaction/:uid', handle(async (req, res) => next(req, res)));
|
||||
// Where oidc-provider sends the browser (its cookie's path): on to the sign-in page.
|
||||
r.get('/interaction/:uid', (req, res) => {
|
||||
const uid = String(req.params.uid);
|
||||
res.redirect(303, /^[A-Za-z0-9_-]{10,64}$/.test(uid) ? `/signin?uid=${uid}` : '/account');
|
||||
});
|
||||
// The page's state for the current step.
|
||||
r.get('/interaction/:uid/state', handle(async (req, res) => next(req, res)));
|
||||
r.post('/interaction/:uid/password', limit(20), step(async (req, _res, p) => { await flow.submitPassword(ctx, p, req.body ?? {}, req); }));
|
||||
r.post('/interaction/:uid/signup', limit(10, 60), step(async (req, _res, p) => { await flow.signUp(ctx, p, req.body ?? {}); }));
|
||||
r.post('/interaction/:uid/verify-email', limit(20), step(async (req, _res, p) => { await flow.verifyEmail(ctx, p, req.body?.code); }));
|
||||
|
||||
@@ -94,7 +94,11 @@ export async function createProvider(ctx: Ctx): Promise<Provider> {
|
||||
revocation: { enabled: true },
|
||||
userinfo: { enabled: true },
|
||||
},
|
||||
interactions: { url: (_k, interaction) => `/signin?uid=${interaction.uid}`, policy: policy(ctx) },
|
||||
// oidc-provider scopes the interaction cookie to this address's path, so it's the API's path for
|
||||
// the sign-in (every step's call is under it); that address sends the browser on to the page
|
||||
// (interaction/routes.ts). Absolute, so a proxy that doesn't keep the Host header can't send
|
||||
// people to the backend's own port.
|
||||
interactions: { url: (_k, interaction) => `${ctx.config.publicUrl}/api/v2/interaction/${interaction.uid}`, policy: policy(ctx) },
|
||||
loadExistingGrant: async (k) => {
|
||||
const grantId = k.oidc.result?.consent?.grantId || k.oidc.session!.grantIdFor(k.oidc.client!.clientId);
|
||||
if (grantId) {
|
||||
|
||||
Reference in New Issue
Block a user