biscuit-auth / biscuit-wasm

WebAssembly wrapper for Biscuit authorization tokens
Apache License 2.0
24 stars 10 forks source link

Add middleware auth support for express #35

Closed divarvel closed 1 year ago

divarvel commented 1 year ago

This provides a middleware function (not a final name, please chime in with better suggestions!) allowing to protect an express JS app with biscuit.

const protect = middleware({ 
  publicKey: keypair.getPublicKey(),
  priorityAuthorizer: authorizer`time(${new Date()});`
});

app.get(
  "/protected/:dog",
  protect((req) => authorizer`allow if scope(${req.params.dog}, "read");`),
  (req, res) => {
    res.send(`Hello, ${req.params.dog}`);
  });

Please see examples/node/express.js for a more complete example.