-
Hello, I am trying to implement HMAC authentication as a middleware. I need:
currently I am working with something like: export const hmacAuthMiddleware = new Middleware({
input: z.object({
'x-hmac-signature': z.string(),
}),
// input: ez.raw(),
handler: async ({ input, request }) => {
const { 'x-hmac-signature': signature } = input;
if (
!verifyHmacSignature({
body: JSON.stringify(request.body),
signatureHeader: signature,
secret: secret(), // I look this up elsewhere
})
) {
throw new createHttpError.Unauthorized('Invalid HMAC signature');
}
return {};
},
}); This is incorrect because the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
There are different parsers involved into processing the request BEFORE the request given to any handler: express-zod-api/express-zod-api/src/server.ts Lines 80 to 88 in 6b78d2e The right parser applied depending on the By default it uses However, you can customize it, by setting express-zod-api/express-zod-api/src/config-type.ts Lines 175 to 180 in 6b78d2e Set it to Check out the documentation for all |
Beta Was this translation helpful? Give feedback.
There are different parsers involved into processing the request BEFORE the request given to any handler:
express-zod-api/express-zod-api/src/server.ts
Lines 80 to 88 in 6b78d2e
The right parser applied depending on the
Endpoint::requestType
, which in your case depends on the presence ofez.raw()
in the input schema:ex…