cap-client
v1.0.0
Published
client library for Cap
Readme
CapClient
Node module for verifying response tokens with Cap server. Also provides an Express middleware.
No additional dependencies. Requires nodejs 18.0+ (uses Fetch API). Types included.
Install
npm install cap-clientUsage
import { CapClient } from 'cap-client';
const cap = new CapClient({
instance: 'https://cap.example.com', // instance includes the protocol. Doesn't have to be the public hostname necessarily.
key: '1234',
secret: 's3cr3t'
});
const result = await cap.verifyToken('t0k3n'); // token comes from the client
// Or use the middleware:
const app = express();
app.post('/submit', cap.middleware, (req, res) => {
if (req.capResponse) {
res.send('verified by cap');
}
else {
res.send('cap verification failed');
}
});
// Note that body must be parsed
Development
pnpm install
pnpm run build
pnpm test