OAuth 2 0 Architecture

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up an oauth 2 0 architecture by separating login checks from target data servers. An identity server checks the user and hands out a temporary token for the app. Engineering teams often use this setup to manage single sign-on across internal tools. Still, teams often attach broad roles to these tokens to save time during setup. When a token maps to an admin role, one login opens up every table and command. How an oauth 2 0 architecture works in practice A standard setup relies on four

Zero Trust Architecture + OAuth 2.0: the complete guide

Architecture patterns, implementation strategies, and security best practices. Delivered to your inbox.

Free white paper. No spam. Unsubscribe anytime.

You set up an oauth 2 0 architecture by separating login checks from target data servers. An identity server checks the user and hands out a temporary token for the app. Engineering teams often use this setup to manage single sign-on across internal tools. Still, teams often attach broad roles to these tokens to save time during setup. When a token maps to an admin role, one login opens up every table and command.

How an oauth 2 0 architecture works in practice

A standard setup relies on four distinct roles that talk to each other in sequence. The resource owner is the human user or service that wants to run a task. The client is the app or command-line tool that requests permission on the user's behalf. The authorization server checks the user's identity and issues tokens after a valid login. The resource server holds the database or API and checks the token before running requests.

When an engineer starts work, the client sends them to the authorization server to log in. The user enters their password and passes a second factor check on that central server. Next, the server sends a short code back to the client app. The client trades this code for an access token through a direct back-channel call. Finally, the client sends this token to the resource server to start a work session.

Choosing the right token flow for your apps

Different apps need different token flows based on where the app code runs. Web apps with a secure back-end server use the standard authorization code flow. Single-page apps and local command-line tools cannot hide a static client secret on a user's machine. These public clients add a proof key step to stop local apps from stealing the code. Background scripts with no human user use the client credentials flow to get a machine token.

Teams also use refresh tokens so users do not have to log in every hour. The access token expires fast, often in less than sixty minutes, to limit risk if stolen. When it expires, the client app sends the refresh token to get a fresh access token. If a team member leaves the company, admins revoke the refresh token at the central server. This stops the app from getting new tokens once the current short window closes.

Zero Trust Architecture + OAuth 2.0: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native token checks solve and what they miss

This token model solves a huge problem by keeping raw user passwords away from target apps. Teams can enforce multi-factor login and revoke central identities in one place. Target servers only need to check the token signature and expiration time before opening a session. This removes the need to sync local accounts across dozens of cloud servers and databases.

Still, the standard token flow only decides who can open the front door. Once a resource server accepts a token, it maps the user to a local role. That role stays active for every query or command sent during the rest of the session. The token flow does not inspect individual SQL statements or shell commands while they run. It cannot require a peer review for a drop statement or mask emails and card numbers.

Check database and API queries on the wire

Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.

Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.

Frequently asked questions

What is the difference between OAuth 2.0 and OpenID Connect?

OAuth 2.0 handles permissions by giving an app a token to act for a user. OpenID Connect sits on top of it to verify who the user is with an ID token. Most teams use both together when they set up workforce login for internal tools.

How do resource servers check tokens without calling the central server every time?

Many systems format tokens as signed JSON objects that carry the user role and expiration time. The resource server keeps a public key from the login server in local memory. It uses this key to check the token signature fast without making an extra network call.

Why do valid tokens still leave databases exposed to bad queries?

A valid token only proves that the user passed the login check and holds a general role. Once the database session starts, the user can run any query allowed by that broad role. Token checks do not read the text of live queries or rewrite sensitive fields in results.

Save the open-source gateway.

hoop is MIT-licensed infrastructure for controlling how AI agents reach production data. Star hoophq/hoop so you can inspect it, deploy it, or share it when your team starts governing agent access.