Overview
@grantex/gateway is a standalone reverse-proxy that enforces Grantex grant tokens in front of any upstream API. Define routes and required scopes in a YAML config — no code required.
Quick Start
1. Creategateway.yaml:
How It Works
- Route matching — finds the first route matching the request method + path
- Token verification — extracts the Bearer token, resolves keys from the configured JWKS endpoint, and verifies signature and claims locally
- Scope checking — ensures the grant includes all required scopes, and (from version 0.2.0) that the token’s
audclaim is for this gateway; see Grant token audience - Proxy — strips Authorization header, adds upstream headers +
X-Grantex-*context, forwards to upstream - Response — returns the upstream response to the client
YAML Config Reference
Route Definition
Path Matching
Context Headers
The gateway adds these headers to every upstream request:
Your upstream API can use these to apply fine-grained business logic without re-verifying the token.
Credentials by reference
WithcredentialReference: on, an agent that exchanged its grant token for a credential
reference (exchange with delivery: "reference") presents it as
Grantex-Credential-Ref: vcr_.... The gateway redeems the reference for the request’s grant with
its own API key (resolve) and forwards the request with
Authorization: Bearer <credential>; the agent never holds the secret. The auth service refuses
a reference that belongs to another grant, has expired, or whose grant is revoked or stopped, and
the gateway then denies the request rather than forwarding it without the credential. A request
that presents no reference is proxied as before. With the check on, the header is not forwarded
upstream; off, the gateway treats it as any other request header, as earlier releases did.
Error Responses
All errors return JSON witherror and message fields:
Grant token audience
The gateway checks the token’saud claim
(RFC 7519 section 4.1.3)
with the same semantics as enforce() in the SDKs, right after the signature
and before anything is forwarded. As in enforce(), the audience comes before
the scopes: a token for another relying party that also lacks the route’s
scopes is refused with the audience code below, not SCOPE_INSUFFICIENT.
The expected audience is the route’s
audience, or else the top-level
audience. aud matches when the expected audience is one of its values,
compared as exact strings. A token whose payload cannot be read is refused
with TOKEN_INVALID. Every one of these denials is logged with the method,
path and grant ID.
audienceCheck: off, and remove it once audience is set. An audienceCheck
other than on or off, an empty audience, or an audience together with
audienceCheck: off stops the gateway from starting.
CLI Usage
Library API
Use the gateway programmatically in your own server:Docker Deployment
Example: Protecting a Calendar API
Ownership
Grantex is owned by Orchestrum Technologies LLP. Inventor and owner: Sanjeev Kumar. Ownership contact: sanjeev@orchestrum.in or mishra.sanjeev@gmail.com.Stop-sensitive deployments
A gateway verifies a grant token’s signature, claims and scopes locally. That accepts a token until it expires: a grant revoked, or ended by an emergency stop, a minute after the token was issued is still accepted for the rest of the token’s lifetime. WithcurrentAuthorityCheck: true the gateway also asks the issuer, on
every request, whether the grant is still active, so a stopped or revoked grant is
refused on the next request. This is the documented default for stop-sensitive
deployments: anywhere an emergency stop must take effect before token expiry, turn
it on and treat a gateway without it as accepting stale authority for up to a
token lifetime. Set GRANTEX_API_KEY (or grantexApiKey), give every route an
audience, and keep audienceCheck on; grantexBaseUrl selects the issuer for a
self-hosted deployment. The issuer being unreachable denies the request: the
gateway never falls back to the signature alone.