How to Use JWTs for Authorization: Best Practices and Common Mistakes

- Share:





3366 Members
JWT best practices start at the verifier. Allowlist the signing algorithms, never accept none for access tokens, and verify the signature before you trust any claim. Then check the claims your token profile depends on, usually exp, nbf, iss, aud and the token type. Keep tokens short-lived, keep sensitive data out of the payload, and let the token carry identity while your authorization layer decides what that identity can do.
The checklist below maps each practice to RFC 8725 (JSON Web Token Best Current Practices), the OWASP JSON Web Token Cheat Sheet and OWASP ASVS 5.0, chapter V9. After it, we get into the authorization side: what belongs in a token, what doesn't, and the mistakes we see most often when teams use JSON Web Tokens for access control.
JWTs are compact, self-contained and cheap to verify, which is why so many authentication flows and APIs use them. They are also easy to misuse for authorization. I've watched it happen with team after team: you start using JWTs for login, and before long the whole permission model lives in the token. Roles, URLs, folder IDs. It looks like a shortcut until access changes and the token doesn't.
none for access tokens. Give the verifier the exact algorithms you expect and never let the alg header choose. RFC 8725 says libraries must let callers specify the supported algorithms and must not use any others. It only allows none when the JWT is protected by other cryptographic means and the caller asks for it, and ASVS says the allowlist must not include it. Sources: RFC 8725 §3.1, §3.2, OWASP ASVS 9.1.2, OWASP: Unsecured JWTs.jwks_uri or a pinned key. Don't trust a key from the jwk, jku or x5u headers unless it chains to an anchor you already trust, and sanitize kid before it reaches a database or directory lookup. Sources: RFC 8725 §3.10, OWASP ASVS 9.1.3, OWASP: Trusting key material named in the token header.iss and sub. Compare iss against an exact allowlist and take the verification key from that issuer's key set only, never from a pool of several issuers' keys. Check that sub is a valid subject for that issuer. Sources: RFC 8725 §3.8, OWASP: Issuer and audience confusion.aud. When an issuer can mint tokens for more than one service, require your own service identifier in aud and reject tokens where it is missing or names someone else. Sources: RFC 8725 §3.9, OWASP ASVS 9.2.3 and 9.2.4.exp and nbf, and keep lifetimes short. Give access tokens an expiration and accept them only inside their validity window. If nbf is present, check it too. A short expiration limits how long a stolen token is useful. Neither source sets a fixed number, so pick the shortest lifetime your user flow can live with. Sources: OWASP ASVS 9.2.1, OWASP: Replay protection.typ to a specific value, such as at+jwt for OAuth access tokens (RFC 9068), and reject the wrong type where the profile requires it. That stops an ID token or a password reset token from passing as an access token. Where typ isn't available, keep validation rules mutually exclusive with different keys, required claims, iss or aud values. Sources: RFC 8725 §3.11, §3.12, OWASP ASVS 9.2.2, OWASP: Cross-JWT and token type confusion.jti and iss, not on the raw token or its hash, which JWT malleability can bypass. A Token Status List lets the issuer revoke tokens. Sender-constrained tokens such as DPoP limit what a stolen token is worth. Sources: OWASP: JWT revocation, OWASP: Replay protection.At its core, the JWT is a compact, URL-safe token that carries information between two parties. It’s made up of three parts: a header, a payload, and a signature.
JWTs are most commonly used for authentication. A user logs in, the server generates a token with their identity inside, and the client stores it, usually in local storage or a cookie. From that point on, every request includes the token, typically in the Authorization header as a Bearer token, like this:
Authorization: Bearer <your-jwt-token>
But here’s where things start to blur. Because JWTs carry claims, and those claims can include things like roles or scopes, many developers assume that JWTs can (or should) handle authorization directly. It feels simple: just check the user's role inside the token and decide what they can access, right?
JWTs do play a role in authorization, but it’s a very specific role. They’re there to communicate who the user is and what they’re allowed to claim about themselves. That identity can then be passed into your authorization logic or system, where the real decision-making happens.
When we talk about "JWT authorization," we usually refer to using identity information inside a JWT to support access control decisions. But that doesn’t mean the JWT is doing the authorization; it helps bootstrap it.
JWTs are best at communicating identity, not permissions.
Think of the JWT as your way of saying: “Here’s who the user is, and here are some basic facts about them that don’t change too often.”
That might include things like their user ID, email, maybe their organization, or even a high-level role like admin or editor.
All of this is identity-bound and changes slowly, so it can travel in a signed token. Anyone holding the token can read it, so leave sensitive data out.
And once you’ve got that token in your application, that’s your starting point. You now know who the user is, and you can start making access decisions by plugging that identity into your actual authorization layer.
Let’s say your app has folders, and each folder has editors, viewers, and owners. You don’t want to list every folder and its permissions inside the JWT. That’s dynamic, contextual data that changes all the time.
What you can do is include that the user has the role VP of Marketing, and then your policy engine can say: “Cool, VPs of Marketing get editor access to these types of folders.”
The access decision happens after the token is verified, in your authorization layer.
This is how you decouple authentication and authorization in a clean, maintainable way. JWTs verify identity. Your authorization logic, whether it’s in code or powered by a policy engine, decides what that identity is allowed to do.
The most common use of JWTs in authorization is OAuth 2.0. In that model the JWT usually carries identity and scopes, which is enough for coarse-grained authorization. You can build your own JWT-based scheme, but for API access tokens a standard profile such as OAuth 2.0 with JWT access tokens is usually the better choice. The thing is, this coarse-grained solution doesn't support anything close to fine-grained authorization requirements. We’ll talk about why these are important next.
So yes, JWTs can support authorization, but only when you treat them as identity carriers, not as the access control system itself.
Now, let’s talk about why relying solely on JWTs for authorization is going to be a problem (and probably sooner than you think).
JWTs are static. Once they’re issued, they’re basically frozen in time. Whatever roles, claims, or metadata you stuffed into the payload is what you’re stuck with until the token expires. If anything changes after that (the user’s role is downgraded, their team is restructured, or their account is suspended), your app won’t know about it.
Since JWTs are stateless, you can't just “revoke” them unless you're tracking them externally, which kind of defeats the purpose. You’re left with stale tokens that still grant access to things the user maybe shouldn’t see anymore.
JWTs are coarse-grained. You might include something like "role": "admin" or "scopes": ["read", "write"], but that doesn’t help when you need to know if a user can access a specific resource, say one document out of a thousand. Put that level of detail in a token and it goes stale and gets hard to manage.
I’ve seen teams try to work around this by cramming more and more data into the JWT: permissions per folder, lists of accessible resource IDs, even full URL-to-permission mappings. Every time, it ends in one of two ways: giant tokens that hit size limits, or completely unmanageable code that breaks the moment something changes.
JWTs just weren’t built to handle real-time, context-aware, or fine-grained authorization. They don’t know about time-sensitive approvals, external conditions, or user activity. They don’t scale with your access logic. And they don’t update when your data changes.
They’re great for saying who someone is. But not for deciding what they can do, at least not on their own.
Not everything belongs in a JWT. Just because you can put something in the payload doesn’t mean you should.
Here’s a quick rule of thumb: if the data changes frequently, depends on external systems, or isn’t part of the user’s core identity, it doesn’t belong in the token.
Don’t put:
The whole point of using JWTs is to keep things clean, fast, and secure. So use them for what they’re good at: stable, identity-bound claims. The stuff that doesn’t change often and that you can safely trust for a few minutes.
Everything else belongs in your authorization layer, not your token.
Having covered the main issues, here are some of the main mistakes developers make when using JWTs for authorization, and how to avoid them.
So if JWTs aren’t meant to do all your authorization work, what’s the right way to use them? Simple: use the token to identify the user, and leave the access decisions to your authorization layer.
The JWT tells you who the user is. That’s its job. From there, your app (or better yet, your policy engine) can figure out what that user is allowed to do, based on real-time data, current system state, relationships, and dynamic rules.
This is where policy engines like OPA, Cedar, or external authorization platforms like Permit.io come in. These tools take the identity claims from your JWT and use them to evaluate access logic separately, without bloating the token or hardcoding permission checks into your app.
Let’s take an example:
Your JWT says the user is user_id: 123, and maybe it includes a claim like role: marketing_vp. Your authorization system can then say:
“Okay, marketing VPs get editor access to department folders, but only if they’re active and haven’t hit their quota.”
You can pull in contextual data, time-based rules, external APIs, whatever your policy requires, and none of that needs to live in the token. Identity stays separate from policy, and access decisions run against current authorization data. This also means you can:
Combining JWTs with a real authorization system keeps identity portable while access rules change without touching the token.
We covered most of these points already, but let’s just do one last quick rundown on how to get things right:
user_id, email, org_id, or maybe a high-level role if it’s fairly stable. If the data changes often or depends on application state, leave it out.JWTs can absolutely support authorization workflows, but only if you use them wisely. Keep them focused on identity and delegate access decisions to the layer built for them.
JWTs are a powerful tool, but only when used in the right way. They’re great for communicating who the user is. They’re fast, portable, and verifiable without needing a centralized session store. That’s why they’ve become the default method for authentication in most apps.
But here’s the key takeaway: JWTs are not your authorization system.
They’re the bridge between your authentication provider and your app. They carry identity, not permissions. Trying to use them as your full access control layer is going to lead to brittle code, stale access, bloated tokens, and ultimately, security risks.
If you need dynamic, fine-grained, or policy-based access control, that’s a job for a real authorization layer, one that can evolve with your app and reflect live system state.
Keep JWTs focused on identity and make access decisions in your authorization layer.
Allowlist the signing algorithms, never accept none for access tokens, and verify the signature or MAC before you accept any claim. Load keys only from sources bound to the issuer, and check the claims your profile depends on, usually exp, nbf, iss, aud and the token type. Keep tokens short-lived, keep sensitive data out of the payload, and keep permissions in your authorization layer. RFC 8725 and the OWASP JSON Web Token Cheat Sheet cover the token checks in detail.
For public-key signatures, the OWASP JSON Web Token Cheat Sheet recommends ES256, PS256, or EdDSA where your libraries support it, and rates RS256 as not recommended. HS256 fits best when the issuer is also the only verifier, as long as the secret is random and at least 256 bits long. Whichever you choose, allowlist it in the verifier and use each key with exactly one algorithm, as RFC 8725 requires.
As short as your user flow allows. Neither RFC 8725 nor OWASP sets a fixed number, but OWASP notes that a short expiration limits token reuse. Verify exp on every request, verify nbf when it is present, and use refresh tokens or re-authentication to issue new access tokens.
Keep permissions out. Put stable identity claims in the token, such as the subject, the issuer and the organization, plus at most a coarse role that rarely changes. Resource-level permissions change faster than tokens expire, so they go stale and bloat the token. Pass the identity from the verified JWT to your authorization layer and let it decide access at request time.
Not on its own. A signed JWT stays valid until it expires unless the verifier checks something outside the token. The usual options are short lifetimes, a deny list keyed on the jti and iss claims, or a Token Status List published by the issuer. Sender-constrained tokens such as DPoP don't revoke anything, but they make a stolen token much harder to use. Every external check adds state, which is the trade-off OWASP points out for stateless sessions.
No. A signed JWT is only base64url encoded, so anyone who gets the token can read every claim. Don't put secrets or sensitive personal data in it. If claims must stay confidential wherever the token travels or is stored, use JWE. If you also need to know who issued it, use a nested JWT: sign the claims, then encrypt, and on receipt decrypt and verify the inner signature before you trust anything.
Want to learn more about Authorization? Join our Slack community, where there are hundreds of devs building and implementing authorization.

Application authorization enthusiast with years of experience as a customer engineer, technical writing, and open-source community advocacy. Comunity Manager, Dev. Convention Extrovert and Meme Enthusiast.

Full-Stack Software Technical Leader | Security, JavaScript, DevRel, OPA | Writer and Public Speaker