guides
Intended Documentation
Enforcement SDK
Use the Intended Enforcement SDK to enforce authorization decisions in your application code with middleware integration, automatic verification, and structured error handling.
Enforcement SDK#
The Intended Enforcement SDK provides a programmatic layer for enforcing authorization decisions in your application. Instead of manually verifying tokens and checking decisions, the SDK handles verification, claim inspection, expiry checks, and error propagation as middleware in your application stack.
Installation#
Quick Setup#
Initialize the client
Create an enforcement client with your API key and JWKS endpoint. The client caches public keys and handles rotation automatically.
Enforce a decision
Pass a decision token to the enforce method. It verifies the token, checks claims, and raises on denial.
Middleware Integration#
The SDK provides middleware adapters for common web frameworks. Middleware intercepts requests, extracts the decision token from the Authorization header, verifies it, and attaches the enforcement result to the request context.
Express.js Middleware#
FastAPI Middleware#
Selective Enforcement#
Apply enforcement only to specific routes:
Configuration Reference#
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | required | Intended API key for fallback remote verification |
jwksUrl | string | required | URL to fetch public signing keys |
issuer | string | "intended.so" | Expected token issuer |
clockToleranceSec | number | 30 | Seconds of clock skew tolerance |
jwksCacheTtlSec | number | 86400 | How long to cache JWKS keys (seconds) |
fallbackToRemote | boolean | true | Fall back to remote /tokens/verify if local fails |
strictMode | boolean | false | Reject tokens missing optional claims |
Error Handling#
The SDK raises specific error types so you can handle each failure mode:
| Error Class | Cause | Recommended Action |
|---|---|---|
DeniedError | Policy denied the intent | Log and return 403 to the caller |
TokenExpiredError | Decision token TTL exceeded | Re-evaluate intent via /intent |
TokenInvalidError | Signature verification failed | Reject request; potential tampering |
ClaimMismatchError | Token claims do not match expectations | Reject request; wrong token for this action |
JwksUnavailableError | Cannot fetch JWKS keys | If fallbackToRemote is true, retries via API; otherwise fail open or closed per config |
NetworkError | Connectivity issue | Retry with backoff; check network |
Warning
By default, the SDK fails closed: if it cannot verify a token for any reason, the request is denied. Set failOpen: true only if you accept the risk of unverified decisions in degraded conditions.
Custom Error Handler#
Logging and Observability#
The SDK emits structured events you can pipe to your logging infrastructure:
Troubleshooting#
| Problem | Cause | Remediation |
|---|---|---|
| Middleware returns 403 on every request | Token header name mismatch | Verify tokenHeader matches the header your client sends |
JwksUnavailableError on startup | Network or DNS issue | Ensure the service can reach api.intended.so; check firewall rules |
| High latency on first request | JWKS cold cache | The first request fetches keys; subsequent requests use cache |
ClaimMismatchError | Token issued for different intent/resource | Ensure the token matches the exact action being performed |
Next Steps#
- Verify Decision Tokens -- understand the verification mechanics the SDK uses internally
- Connector SDK -- build custom connectors for downstream systems
- Error Patterns -- comprehensive error handling strategies