Securing REST API passwords with OAuth and gateways

Published
Length
3 min read

Luis Felipe Dias

All posts

OAuth 2.0 and API gateways control who reaches a REST API password endpoint and how often. A secure setup pairs these controls with a runtime check. This check inspects every request and response for dangerous effects and sensitive values. Good security looks like this. An AI agent or service account authenticates with a scoped token. The gateway validates the token and enforces rate limits. A proxy beside the API blocks destructive calls. It masks sensitive fields in the JSON before the client

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

OAuth 2.0 and API gateways control who reaches a REST API password endpoint and how often. A secure setup pairs these controls with a runtime check. This check inspects every request and response for dangerous effects and sensitive values.

Good security looks like this. An AI agent or service account authenticates with a scoped token. The gateway validates the token and enforces rate limits. A proxy beside the API blocks destructive calls. It masks sensitive fields in the JSON before the client sees them. The agent gets a clear reason if a request is refused.

How OAuth 2.0 and gateways handle access

OAuth 2.0 lets a third-party app obtain limited access to an HTTP service. The Client Credentials grant is used when the client acts on its own behalf. The specification requires it to be used only by confidential clients. RFC 9700 is the security best current practice. It emphasizes that token privileges should be restricted to the minimum required for the specific use case. A token for reading user profiles should not also allow deleting them.

However, these controls are broad. A gateway knows the caller has a valid token for the /users endpoint.

What gateways leave open

OWASP lists Broken Function Level Authorization as a top API risk. This happens when a caller sends legitimate API calls to endpoints they should not have access to. For example, they change a GET request to a DELETE. A rate limit prevents flooding. It does not stop a single, valid, but destructive request. AWS notes that usage plan limits are not hard limits. They are applied on a best-effort basis. Azure similarly cautions that rate limiting is never completely accurate.

Logging has a similar gap. Amazon API Gateway access logs record who called the API and how. They use variables for source IP, method, and path. The variable list has no field for request or response body content. Azure API Management resource logs also do not include request or response bodies by default. Their data masking features in diagnostic settings cover headers and query parameters. They do not cover the JSON body. Most sensitive data lives there.

Adding a check on the connection

This is where a proxy that sits beside the API adds value. hoop.dev is an open-source proxy. It runs next to your HTTP API. It reads every request on the way in. It reads every response on the way back. It speaks the HTTP protocol. It knows a DELETE to /admin/users from a harmless GET to /users/profile. It does not replace your gateway or your OAuth setup. It rides next to them. It adds a layer of control. This layer checks what each statement does and what comes back.

REST API Authentication + OAuth 2.0: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

hoop.dev guardrails let you define rules that match the request effect. You can refuse POST and DELETE requests to specific paths. If a request is refused, the client gets a 403 Forbidden. It includes a message you wrote. The agent or engineer can read why it was blocked. They do not watch the connection drop silently.

Masking sensitive data in responses

The other half of the problem is data leaving the building. hoop.dev data masking walks JSON responses value by value under dotted key paths. A rule can name a JSON key the way it names a database column. For example, data.credit_card_number. It rewrites the value in memory before it reaches the client. The request itself is never touched. The stored data in your backend remains unchanged.

Because the proxy sits on the connection, it can also audit every request and decision. This is per resource.

When to use each layer

Use OAuth and gateways for authentication and coarse-grained authorization. They decide who can connect and how often. Use hoop.dev for statement-level control and response masking. It checks what each request does. It checks what each response returns. They stack instead of compete. Your gateway keeps its rate limits and token validation.

hoop.dev is MIT licensed and open source. You can read the source code. You can run the proxy locally. The setup is simple. Point your API traffic to the proxy. Define your rules. Start inspecting. See the HTTP protocol docs for configuration details. See the guardrails guide for rule syntax. See the data masking docs for masking strategies.

Explore the hoop.dev GitHub repository to see how it works. You can also contribute to the project.

Frequently asked questions

Does hoop.dev replace my API gateway?
No. hoop.dev runs beside your existing gateway. It adds a layer of inspection for requests and responses. You keep your gateway for authentication, rate limiting, and routing.

Can hoop.dev mask data in the request body?
No. Data Masking in hoop.dev rewrites responses only. It does not modify the request the client sends. If you need to block requests based on their content, use guardrails. Guardrails can inspect the request body and refuse the call.

Does hoop.dev work with HTTP/2?
Yes. hoop.dev supports both HTTP/1.1 and HTTP/2. It can be deployed behind an existing Envoy proxy. This keeps your current ext_authz and OPA setup. You point the route cluster at the sidecar.

The query runs. The emails stay hidden.