6.2 API Gateway: Authentication, JWT Validation, Rate Limiting & Usage Plans
Key Takeaways
OCI API Gateway is a managed, highly available regional proxy deployed into public or private VCN subnets to route API traffic to HTTP backends, OCI Functions, or mock responses.
Native OAuth 2.0 / JWT validation inspects JSON Web Tokens directly against external identity provider JWKS endpoints without invoking serverless code, minimizing latency and execution costs.
Custom Authorizer Functions provide flexible, programmable identity verification for non-JWT tokens, legacy HMAC schemes, and custom database lookups, utilizing gateway-level caching to control compute overhead.
Usage plans contain entitlements with a per-second rate limit and a quota per minute, hour, day, or month, and subscribers identify their API clients with client tokens.
11.2 API Gateway: Authentication, JWT Validation, Rate Limiting & Usage Plans
Managed Regional API Proxy Architecture
Oracle Cloud Infrastructure (OCI) API Gateway is a fully managed, multi-tenant regional proxy service that enables organizations to publish, secure, route, and monitor APIs at scale. Positioned at the network perimeter or within internal enterprise boundaries, API Gateway acts as the unified front door for microservices, legacy HTTP backends, and serverless applications.
API Gateway is deployed directly into a customer's Virtual Cloud Network (VCN), inheriting standard OCI network isolation and security controls:
- Public API Gateway: Provisioned in a public subnet with an internet-facing public IP address. It exposes public REST endpoints to mobile applications, web clients, and external third-party partners.
- Private API Gateway: Provisioned within a private subnet without public internet routability. It serves as an internal gateway for enterprise service meshes, hub-and-spoke VCN transit routing, or hybrid workloads connected over FastConnect or Site-to-Site VPN.
API Gateway is a managed, highly available service that Oracle scales automatically, so you do not provision load balancers or plan gateway capacity yourself.
Deployments, Path Routing & Backend Types
The core operational unit on an API Gateway is an API Deployment. A single API Gateway instance can host multiple API Deployments, each bound to a unique path prefix and managing its own collection of routes, security policies, and traffic rules.
API Gateway (Regional Proxy)
├── Deployment A (Prefix: /v1/payments) ──> Routes (/charge, /refund) ──> OCI Functions
├── Deployment B (Prefix: /v1/inventory) ──> Routes (/items, /{sku}) ──> HTTP Load Balancer
└── Deployment C (Prefix: /v1/health) ──> Routes (/status) ──> Stock Mock Backend
Routing Mechanics
Deployments map incoming client HTTP request paths and verbs (GET, POST, PUT, DELETE) to specific upstream backends using route definitions:
- Path Mapping: Supports exact path matching (e.g.,
/orders), path parameters (e.g.,/orders/{orderId}), and wildcard prefixes (e.g.,/static/*). Path parameters can be extracted and forwarded to backend query strings, headers, or URL paths. - URL Rewriting & Transformations: The gateway can strip prefixes, rewrite target paths, or append static headers before passing requests to backend servers.
Supported Backend Types
OCI API Gateway natively supports three distinct backend architectures:
- HTTP / HTTPS Backends: Routes traffic to web applications, OCI Flexible Load Balancers, Container Engine for Kubernetes (OKE) Ingress controllers, Compute instances, or public third-party endpoints. Supports SSL/TLS verification, custom timeouts, and SNI host header overrides.
- OCI Functions Backends: Dispatches incoming requests directly to serverless OCI Functions. The gateway handles the translation between HTTP request bodies and the Fn container input stream, returning function output directly to the calling client.
- Stock (Mock) Backends: Returns synthetic static HTTP responses—including custom HTTP status codes (e.g., 200 OK, 503 Service Unavailable), response headers, and static JSON/XML response bodies—directly from the gateway without dispatching calls to any downstream compute resource. Mock backends are invaluable for API contract prototyping, health check endpoints, and graceful degradation during maintenance windows.
Authentication & Security Policies
API Gateway serves as the centralized enforcement point for authentication and authorization, decoupling security logic from backend business code. Architects can choose between two primary authentication mechanisms:
1. Native OAuth 2.0 / JWT Validation
For modern enterprise architectures utilizing standard JSON Web Tokens (JWT) issued by identity providers—such as Microsoft Entra ID, Okta, Auth0, or OCI Identity Domains—API Gateway provides native JWT validation without requiring custom code or serverless execution.
When a client submits an HTTP Authorization: Bearer {token} header:
- The gateway retrieves and caches the JSON Web Key Set (JWKS) from the identity provider's public keys endpoint (
jwks_uri). - It validates the cryptographic signature of the token using the corresponding public key.
- It verifies core JWT claims: token expiration (
exp), not-before (nbf), issuer (iss), and audience (aud). - It validates custom scopes and role claims required for specific routes.
- It extracts token claims (such as
sub,email, ortenant_id) and injects them as new HTTP headers forwarded to backend services.
Architectural Advantage: Native JWT validation executes entirely within the API Gateway data plane. It incurs zero compute billing for OCI Functions, produces no cold starts, and prevents unauthorized requests from ever reaching backend infrastructure.
2. Custom Authorizer Functions
When authentication requires non-standard validation logic—such as inspecting proprietary API keys in database tables, verifying legacy HMAC signatures, checking LDAP directories, or calling legacy SOAP security services—architects implement a Custom Authorizer Function.
In this model:
- The gateway intercepts the incoming request and invokes an OCI Function designated as the custom authorizer.
- The authorizer function receives the request headers and query parameters, executes custom verification logic, and returns a structured JSON response:
{ "active": true, "principal": "user_98765", "scope": ["orders:read", "orders:write"], "expiresAt": "2026-10-11T20:30:00Z", "context": { "tier": "gold", "companyId": "corp_102" } } - If
activeis true, the gateway permits the request, injecting values from thecontextobject into backend HTTP headers. - Authorizer Caching: To prevent invoking the authorizer function on every single incoming request, the gateway caches authorization verdicts based on the
expiresAttimestamp or a configured cache TTL. Subsequent requests with identical credentials are authenticated directly from cache.
Traffic Management: Rate Limiting, Throttling & CORS
To maintain service reliability and protect backend applications from cascading failures, API Gateway incorporates robust traffic management policies:
Rate Limiting & Throttling
Architects can configure rate limiting at the deployment level or route level:
- Global Rate Limiting: Enforces a maximum aggregate request-per-second (RPS) threshold across the entire deployment.
- Per-Client Throttling: A rate-limiting policy can count requests per client IP address or in total across all clients.
- When a client exceeds the limit, the gateway rejects the request with HTTP 429 Too Many Requests before it reaches the backend.
Cross-Origin Resource Sharing (CORS)
Web browsers enforce the Same-Origin Policy, restricting web applications from issuing cross-origin API calls unless explicit CORS headers are returned. API Gateway provides a declarative CORS policy engine that defines:
- Allowed Origins: Specific authorized domains (e.g.,
https://app.example.com) or wildcards (*). - Allowed Methods: Permitted HTTP verbs (GET, POST, PUT, DELETE, OPTIONS).
- Allowed & Exposed Headers: Headers the client may send or read from responses.
- Preflight Cache (Max Age): How long browsers can cache
OPTIONSpreflight responses, drastically reducing preflight traffic.
API Usage Plans & Client Subscriber Management
Enterprise organizations exposing APIs to external partners or commercial subscribers require monetization, quota enforcement, and tier-based consumption management. API Gateway provides this through Usage Plans and Client Subscribers.
Subscriber (Client Application) ──[client token]──> API Gateway Deployment
│
Validates Subscription Tier
├── Bronze: 10 RPS, 50k req/month
├── Silver: 50 RPS, 500k req/month
└── Gold: 500 RPS, 5M req/month
Core Governance Components
- API Usage Plans: Define access agreements comprising two constraints:
- Rate Limit: Maximum requests per second allowed for the plan.
- Quota: Maximum total requests in a period of a minute, hour, day, or month. You choose whether requests over the quota are rejected or still allowed, and a rejected response tells the client when it can retry.
- Subscribers: Represent API consumers. Each subscriber definition contains client names and client tokens, and names the usage plans the clients can use. Requests pass the client token in the location you define in the deployment's usage plan request policy, such as a header or a query parameter.
- Entitlements: Each usage plan has one or more entitlements that target API deployments, possibly on different gateways. When a request arrives with a client token, the gateway checks that the client is subscribed to a plan covering that deployment, applies the rate limit and quota, and rejects requests that exceed them. If an entitlement has no rate limit or quota, access is unlimited, but the client must still be subscribed and present a client token.
Authentication Architectural Comparison
| Evaluation Dimension | Native JWT Validation Policy | Custom Authorizer Function |
|---|---|---|
| Execution Engine | Native API Gateway proxy data plane | External OCI Function (Fn Container) |
| Latency Overhead | Validation runs inside the gateway, with no function call | Adds a function call for each uncached request; cold starts add more delay |
| Additional Compute Cost | None (included in gateway cost) | Billed per invocation and GB-second |
| Supported Token Types | Standard OAuth 2.0 / RFC 7519 JWT | Any format (HMAC, legacy DB, API tokens, SOAP) |
| Identity Provider Integration | Direct JWKS URI fetching (Okta, Entra, OCI) | Custom code queries IdP, LDAP, or database |
| Result Caching | Built-in public key caching | Gateway caches authorization verdict via TTL |
| Header Transformation | Directly maps JWT claims to headers | Maps custom context key-values to headers |
A multinational enterprise exposes microservices on OKE and OCI Functions through an OCI API Gateway deployed in a public subnet. Corporate security mandates validating OAuth 2.0 access tokens issued by Microsoft Entra ID on all requests, verifying the issuer and audience claims, and passing the client tenant ID to backend services. The solution must minimize request latency and eliminate compute charges for unauthorized requests. Which security design should the architect select?
A WAF rule that parses the Authorization header and calls a token-checking script on a bastion host
An API Gateway JWT authentication policy that validates tokens against the Entra ID JWKS URI and checks issuer and audience
Pass all requests to the OKE ingress controller and validate tokens inside each microservice
A custom authorizer function that downloads Entra ID signing certificates on every request and decodes each token with custom code
A SaaS provider publishes a developer API via OCI API Gateway. The business offers three subscription tiers: Free (limited to 5 requests per second and 10,000 requests per month), Silver (50 requests per second and 500,000 requests per month), and Gold (unrestricted burst rate with 5,000,000 requests per month). When consumers exceed their monthly quota, the gateway must reject incoming traffic with HTTP status code 429 without routing calls to backend compute instances. Which feature set provides this functionality with the lowest operational complexity?
A custom authorizer that updates a database counter on each request and returns HTTP 429 at the limit
Network security group rules that OCI Events updates dynamically with per-client request limits
Usage plans with rate-limit and quota entitlements, plus subscribers identified by client tokens
A load balancer in front of the gateway with weighted routing that sends excess traffic to error servers
Sections you finish are checked off in the contents.