Skip to content
Journal
membereditorparentanadesignbrandlogoallow

Access management · · 6 min read

Keep authorization out of your tokens

By the Argenium team

Putting roles and permissions into JWT claims feels efficient: every service can decide on its own, with no network call. In practice it trades correctness for a lookup you didn’t need to avoid.

What goes wrong

  • Staleness. Revoke a permission and every token already issued keeps it until it expires. For a fired employee or a compromised account, that window is the problem.
  • Size. Global roles fit in a header. Per-project or per-document permissions do not, and the token grows with the customer’s success.
  • Missing context. A claim says “editor”. Editor of what? Authorization is almost always about a specific resource, which the token cannot know in advance.
  • Drift. Each service interprets the claims slightly differently, so the same user gets different answers depending on which API they hit.

Scopes are not permissions

OAuth scopes describe what a user has delegated to a client application: this integration may read your calendar. They say nothing about what the user is allowed to do in your product. The effective decision is the intersection of both: the client must hold the scope, and the user must be allowed to perform the action on that resource. Keep scopes coarse and stable; keep permissions in your authorization model.

Decide at the resource, with current data

Let the token carry identity: who the user is, which tenant, which client. Let a single decision point answer the actual question at the moment it matters, using current data:

documents.ts
const allowed = await authz.check({
  subject: `user:${token.sub}`,
  action: "edit",
  resource: `document:${doc.id}`,
});
if (!allowed) return forbidden();

One function, called the same way from every service, removes drift. Because it reads current relationships, revocation takes effect on the next request rather than at the next token refresh.

Model relationships once sharing appears

Role-based access control works well while roles are global: admin, member, billing. It starts to strain the day users can share individual objects. Roles per resource multiply, and questions like “who can see this document?” become joins across half your schema.

Relationship-based access control, the model popularised by Google’s Zanzibar paper, stores facts as edges: Ana is a member of Design, Design is an editor of the Brand folder, the logo’s parent is that folder. A check becomes a question about whether a path exists.

membereditorparentanadesignbrandlogoallow
The decision follows relationships: no claim in Ana’s token mentions the logo.

A short checklist

  • Deny by default. A missing rule is a refusal, never an accident in the user’s favour.
  • Log decisions with reasons. “Denied: no editor relation on folder:brand” turns support tickets into five-minute fixes.
  • Test policies like code. A table of subject, action, resource and expected result, run in CI.
  • Plan list filtering early. “Which documents can I see?” is harder than “can I see this one?”, and it shapes your data model.
  • Cache carefully. Short lifetimes, and invalidation on relationship changes, or you have rebuilt the stale-token problem.
Share