OAuth2 Scope Naming Convention
An oauth2 scope naming convention groups permissions by pairing a resource name with an action verb. You build it by joining the object and the allowed task with a colon or dot. Most teams start with broad scopes like read and write across the whole app. Over time, these broad roles give users and scripts far too much power. A single token can then change settings or read private tables across every service. Clear naming rules help teams scope down what a token can do from day one. How an oaut
Scope Naming Convention: the complete guide
Architecture patterns, implementation strategies, and security best practices. Delivered to your inbox.
An oauth2 scope naming convention groups permissions by pairing a resource name with an action verb. You build it by joining the object and the allowed task with a colon or dot. Most teams start with broad scopes like read and write across the whole app. Over time, these broad roles give users and scripts far too much power. A single token can then change settings or read private tables across every service. Clear naming rules help teams scope down what a token can do from day one.
How an oauth2 scope naming convention works
In OAuth, a scope is a plain text string that defines a specific permission. When an app asks to log in, it sends a list of scope strings. The auth server checks if the user or service role allows those exact scopes. If the check passes, the server puts those strings inside the access token. When the app calls an API, the target service reads the token scopes. The service then blocks the call if the needed scope string is missing.
A clean oauth2 scope naming convention uses a two-part or three-part pattern. The most common pattern puts the resource first and the action second. For example, a team can name a scope for reading billing data with two words. They join the word billing and the word read with a colon. Some large teams add a system or domain name at the very front. This three-part pattern stops name clashes when many services share one auth server. Regardless of the separator, every team member must use the exact same word order. Mixing verb-first and noun-first names leads to logic bugs in API permission checks.
How to pick clear resource and action names
Start by listing the core data objects that your APIs expose to users. Good resource names are plural nouns like users, orders, invoices, or clusters. Avoid naming scopes after internal database tables or temporary team names. Keep the action verbs limited to a tiny, fixed list across all services. Most teams use read, write, delete, or admin as their only action words. If a service needs a special task, add a clear verb like export or approve. Write every scope string in lowercase letters and use hyphens for multi-word nouns.
Keep the total number of scopes small enough for humans to read and manage. If you create a scope for every single API field, tokens become too large. Large tokens can break HTTP header size limits on standard web servers. Group related fields under one logical resource name to keep token size small. Document each scope in a central catalog so developers know what to request. Review this list twice a year and remove old scopes that no service checks.
Scope Naming Convention: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
What token scopes solve and what they miss
A clear scope design solves the problem of coarse access across different microservices. It stops a billing script from calling the user management API by mistake. It also lets users see what permissions a third-party app wants before they approve it. Auth servers can match these scopes to team roles during the login flow. This keeps the front-end login check clean and easy to audit at a high level.
Still, token scopes only work at the API perimeter when a session starts. A scope decides who logs in, not what individual queries or commands do in flight. For instance, a read scope on a database service allows any read query. It does not stop a user from pulling ten million rows of sensitive data. It also cannot rewrite emails, phone numbers, card numbers, or national IDs in query results. Also, static scopes stay active for the whole life of the token. If an engineer only needs write power for five minutes, the scope keeps the session active longer. Teams still lack visibility into the exact statements or CLI commands run inside that session.
Govern statements and responses across databases and APIs
Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev runs beside each supported service as an open-source proxy, a sidecar for your database or API.
First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.
Frequently asked questions
Should I use colons, dots, or slashes to separate scope words?
Colons and dots are the safest choices for most auth servers and web tools. Slashes can clash with URL paths when scopes pass through web query strings. Pick either colons or dots and use that single mark across every service.
What is the difference between OAuth scopes and user roles?
A user role defines who a person is within a team, like an admin. An OAuth scope defines what a specific app token can do on their behalf. A token often holds a smaller subset of the permissions granted to the user role.
How many scopes should a single access token hold?
Keep a token under twenty scopes so the HTTP header stays small and fast. If an app needs more, group those fine permissions into broader domain scopes. You can also issue separate tokens for different backend services to split the load.
Related guides
In this post