OAuth Scopes and Claims

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up oauth scopes and claims in your login provider to control app rules. Scopes state what an app can do, while claims store facts about the user. Most teams map broad group roles to these tokens during the login setup. When those roles are too wide, one token grants write power across every backend system. A single stolen token or bad query can then wipe out whole tables. How oauth scopes and claims work in login flows Scopes and claims serve two distinct jobs inside a token login flo

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 oauth scopes and claims in your login provider to control app rules. Scopes state what an app can do, while claims store facts about the user. Most teams map broad group roles to these tokens during the login setup. When those roles are too wide, one token grants write power across every backend system. A single stolen token or bad query can then wipe out whole tables.

How oauth scopes and claims work in login flows

Scopes and claims serve two distinct jobs inside a token login flow. A scope is a request from an app to act on a user's behalf. When an engineer logs in, the app asks the login server for specific scopes. These scopes might cover reading data, writing records, or running admin tasks. The login server checks if the user has the right to grant that scope.

Claims work as key and value pairs inside the issued token itself. Each claim states one fact about the user, the app, or the login event. Common claims hold the user email, team group, issue time, and token end time. The login server signs these claims with a private key so nobody can fake them. Backend systems then check that signature and read the claims to know who logged in.

Together, scopes set the outer limit of what the client app can ask to do. Claims tell the target service who the person is and which groups they belong to. You set up both in your identity provider by defining custom rules for each app.

Why token rules are hard to manage at scale

As teams add more databases and internal apps, scope lists grow out of control. Engineers often create coarse scopes like full admin or full read to save time. If you make scopes too fine, tokens grow huge and break size limits in headers. Teams also struggle when different backend systems read group claims in different ways.

Role drift makes this problem worse over time as people switch teams. A user keeps old group claims long after their daily job changes. Because tokens stay valid until they expire, revoking a group does not stop active sessions. The user can keep running commands until the token clock runs out.

OAuth 2.0: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What token checks solve and the runtime gap they leave

Native token checks solve the first step of security by proving who holds the token. They stop unknown users at the door and block apps that lack basic scopes. They also give teams one central place to manage user groups and login rules.

Still, scopes and claims only decide who can open a session with a backend system. Once the session starts, the token has no clue what individual commands or queries run. A user with a valid write scope can drop a table or update every row by default. A user with a read scope can pull millions of phone numbers or card numbers. Static token fields cannot inspect live database statements, block risky commands, or rewrite sensitive results.

Add runtime guardrails and masking beside your databases and APIs

Login rules, role grants, and CI checks govern who connects to your stack. Yet any allowed script, engineer, or AI agent still runs commands with the full scope of its role. For workloads on Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes, SSH, or internal HTTP services, hoop.dev sits beside the service as an open-source proxy, a sidecar for your database or API.

Before a query runs, hoop.dev guardrails check the statement against your rules. An AI Analyzer you configure can score intent or hold risky calls for human review. Next, hoop.dev data masking rewrites sensitive fields in responses, and each verdict is logged per listener. Explore the MIT-licensed project on GitHub.

Frequently asked questions

What is the main difference between a scope and a claim?

A scope defines the broad actions an app asks to perform for a user. A claim is a single piece of data inside the token, like an email address.

Can I put database table permissions directly into token claims?

You can add custom claims, but putting every table rule in a token bloats it. Large tokens can fail network header limits and still cannot inspect live queries in flight.

What happens when a user's group claim changes during an active session?

The active token keeps the old claim values until its timer runs out. Backend systems that only read the token will still trust the old group until renewal.

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.