Protect your Express.js APIs with Grantex grant tokens. Express middleware that verifies JWTs, enforces scopes, and attaches verified grant context.
Your Express APIs accept API keys or bearer tokens with no scope enforcement. Any valid token can access any endpoint. No agent identity tracking.
Grantex middleware verifies JWTs against published JWKS, enforces scopes per route, and identifies the calling agent. Warm resolvers can reuse cached signing keys; initial retrieval and rotation refreshes require network access.
npm install @grantex/express — uses Express and @grantex/sdk as peer dependencies.
One line to protect your routes. Specify required scopes per endpoint.
JWT signatures are checked locally. Warm resolvers can reuse cached JWKS keys; initial retrieval and rotation refreshes require network access.
req.grant contains the verified agent DID, scopes, principal, and grant ID.
JWKS-backed verification, scope enforcement, key rotation support, and typed authorization errors.
import express from 'express';
import {
requireGrantToken,
requireScopes,
type GrantexRequest,
} from '@grantex/express';
const app = express();
app.use('/api', requireGrantToken({
jwksUri: 'https://api.grantex.dev/.well-known/jwks.json',
}));
app.get('/api/emails', requireScopes('email:read'), (req, res) => {
const grant = (req as GrantexRequest).grant;
console.log(grant.agentDid);
console.log(grant.scopes);
res.json({ emails: [] });
});
Install the middleware on every protected Express route and verify compatibility with your Express version.
Signing keys are retrieved from the configured JWKS endpoint. Cached resolvers avoid repeat fetches while valid and refresh as keys rotate.
requireScopes() enforces specific permissions per endpoint. Returns 403 if scopes don't match.
req.grant provides agent DID, scopes, principal ID, and grant ID after verification.
Automatic key caching and rotation. Handles key rollover transparently.
Full type definitions are provided for req.grant and verified grant claims.
This integration enforces authorization only where its wrapper or middleware is installed. Local JWT verification checks signatures and claims after JWKS retrieval; it does not prove current revocation unless the verifier performs an online state check or synchronizes revocation data.
Token verification does not create a consent record or prove that a tool executed. Use the configured authorization flow for grant decisions and add an audit integration at the execution boundary when action records are required.
Follow the integration guide and verify the package version before deployment. Apache 2.0.