Skip to main content

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.
Node.js 22.12+ is required. Audience and trusted-amount configuration are breaking changes; see migration. Gateway JWT checks alone do not prove current grant revocation; wire current-state enforcement at the protected service before side effects.

Quick Start

1. Create gateway.yaml:
2. Start the gateway:
3. Make requests with grant tokens:

How It Works

  1. Route matching — finds the first route matching the request method + path
  2. Token verification — extracts the Bearer token, resolves keys from the configured JWKS endpoint, and verifies signature and claims locally
  3. Scope checking — ensures the grant includes all required scopes, and (from version 0.2.0) that the token’s aud claim is for this gateway; see Grant token audience
  4. Proxy — strips Authorization header, adds upstream headers + X-Grantex-* context, forwards to upstream
  5. 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

With credentialReference: 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 with error and message fields:

Grant token audience

From version 0.2.0 (not in @grantex/gateway 0.1.5). This is a breaking change: a grant token that carries an aud claim is refused unless the gateway is configured with that audience. Tokens issued without an audience are unaffected.
The gateway checks the token’s aud 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.
To keep the earlier behaviour while you find the audience, set 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. With currentAuthorityCheck: 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.

Current Authority and Human Identity

Use the exact integration version and minimum primary SDK in Release Status. Per-invocation issuer authority and trusted principal/agent binding are opt-in. Configure the callback with the trusted issuer and derive identity from the host’s authenticated session; signature and scope checks alone do not prove current revocation or human consent. See SDK execution authority for configuration, denial behavior and manifest/decision/caps boundaries.
Last modified on October 4, 2026