Gateway Authz
WhilegetAuth() is designed exclusively for verifying lightweight frontend JWT user sessions, B2B applications also frequently need to authenticate programmatic API requests. These typically come in two forms:
- API Keys: Static, long-lived generic tokens prefixed with
wk_live_... - OAuth Access Tokens: Short-lived, scoped tokens generated via machine-to-machine OAuth flows.
@wacht/backend SDK provides the gateway module to verify these tokens against the Wacht Authz Engine.
Unlike session JWTs which are verified locally, Gateway assertions require a network roundtrip because API Keys can be revoked instantly and their permissions modified dynamically.
Verifying an API Key
When a developer integrates with your custom API, they will pass an API Key in theAuthorization: Bearer <api_key> header. You can extract that key and verify it using gateway.verifyApiKeyRequest.
The extracted raw API Key string (
wk_live_...).The HTTP Method representing the action (e.g.
GET, POST).The specific URL path resource being requested.
Enforcing Specific Permissions
API Keys natively inherit the Role-Based Access Control (RBAC) permissions of the roles they are assigned within a Workspace or Organization. You can instruct the gateway to decline the request automatically if the key lacks required permissions.workspace:project:delete permission, verifyApiKeyRequest will throw a 403 AuthorizationError.
Verifying OAuth Tokens
If your application operates as an OAuth Resource Server accepting access tokens generated via standard OIDC grants (likeclient_credentials), verify them using verifyOauthAccessTokenRequest.
The signature is identical to API Key verification:
The extracted short-lived OAuth Bearer token.
The evaluated HTTP action method.
The target evaluation path.
