antlion-lacewing - v2.0.1
    Preparing search index...

    Frameworks

    verifyDPoPRequest reads a WHATWG Request. On Node's http, Express, Fastify and Koa, fromNodeRequest from antlion-lacewing/node builds one. The refusal is a status and headers each framework can send as they are. The Node, Express, Fastify and Koa code below is what tests/integration/frameworks.test.ts runs against a real server, with the route mounted under a prefix.

    • It reads headers from req.headersDistinct. Node's req.headers keeps only the first of two Authorization headers, so a duplicate would never reach Antlion.
    • It copies only Authorization and DPoP.
    • It uses the path the client signed. A mounted router rewrites req.url: Express keeps the original in req.originalUrl, which the adapter prefers, and Koa keeps it in ctx.originalUrl, which you pass. Fastify leaves request.raw.url alone.

    The origin always comes from your profile, never from Host.

    const { token } = await verifyDPoPRequest(request, dpop);
    // on refusal:
    return new Response(null, error.refusal);
    import { fromNodeRequest } from "antlion-lacewing/node";

    const { token } = await verifyDPoPRequest(fromNodeRequest(req), dpop);
    // on refusal:
    res.writeHead(error.refusal.status, error.refusal.headers).end();
    router.get("/accounts/:id", async (req, res) => {
    const { token } = await verifyDPoPRequest(fromNodeRequest(req), dpop);
    // on refusal:
    res.status(error.refusal.status).set(error.refusal.headers).end();
    });
    app.use("/api", router);
    app.get("/accounts/:id", async (request, reply) => {
    const { token } = await verifyDPoPRequest(fromNodeRequest(request.raw), dpop);
    // on refusal:
    return reply.code(error.refusal.status).headers(error.refusal.headers).send();
    });
    app.use(async (ctx) => {
    const { token } = await verifyDPoPRequest(fromNodeRequest(ctx.req, ctx.originalUrl), dpop);
    // on refusal:
    ctx.status = error.refusal.status;
    ctx.set(error.refusal.headers);
    });

    Pass ctx.originalUrl. Under koa-mount, ctx.req.url has lost the mount prefix, and every proof would fail its htu check.

    With nonce: "required", a verified request carries nextNonce. Send it on your response so the client does not need a 401 to learn it:

    if (nextNonce !== undefined) {
    res.set({ "DPoP-Nonce": nextNonce, "Cache-Control": "no-store" }); // Express
    }

    no-store is RFC 9449 section 8.2: a cached response would hand a stale nonce to the next request.