<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Akash Devdhar</title>
    <description>The latest articles on DEV Community by Akash Devdhar (@neospeed83).</description>
    <link>https://dev.to/neospeed83</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4059095%2Fdb1c8fab-81c1-4bb3-a8da-da71cd7abc12.jpg</url>
      <title>DEV Community: Akash Devdhar</title>
      <link>https://dev.to/neospeed83</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/neospeed83"/>
    <language>en</language>
    <item>
      <title>Auditing AI Agents in Enterprise Systems</title>
      <dc:creator>Akash Devdhar</dc:creator>
      <pubDate>Wed, 18 Nov 2026 22:07:26 +0000</pubDate>
      <link>https://dev.to/neospeed83/auditing-ai-agents-in-enterprise-systems-302m</link>
      <guid>https://dev.to/neospeed83/auditing-ai-agents-in-enterprise-systems-302m</guid>
      <description>&lt;p&gt;Most enterprise audit logs were built for a human clicking a button. They record user ID, endpoint, timestamp, and status code. An AI agent can make twenty tool calls, delegate two of them, retry one side effect, and finish after the user has left. Writing the user's ID on every event does not explain what happened.&lt;/p&gt;

&lt;p&gt;Agent audit needs a delegation chain, full stop.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.akashdevdhar.com%2Fdiagrams%2Fagent-audit-chain.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.akashdevdhar.com%2Fdiagrams%2Fagent-audit-chain.png" alt="Audit records must connect delegation, agent, decision, and outcome" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Record evidence, not a story
&lt;/h2&gt;

&lt;p&gt;An audit event should capture the initiating subject, agent workload, tenant, task, tool, normalized resource, policy decision, credential identifier, and result. Link retries and sub-agent calls through correlation identifiers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"event"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"tool.execute"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"task_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"task-92"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"subject"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"user-123"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"actor"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"agent-invoice-4"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"tenant"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"tenant-a"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"tool"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"invoice.update_status"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"invoice-881"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"decision_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"dec-771"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"outcome"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"allowed"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Do not treat hidden model reasoning as the audit source. It may be unavailable, sensitive, or unreliable as evidence. Record observable inputs, policy facts, selected action, and actual outcome. If the agent provides a user-facing explanation, store it as an explanation, not as proof of authorization.&lt;/p&gt;

&lt;h2&gt;
  
  
  Audit the decision point
&lt;/h2&gt;

&lt;p&gt;Logging only after execution misses denied attempts and policy behavior. Capture why the policy allowed or denied the call, including policy version and relevant attributes. This makes it possible to distinguish agent error from authorization error later.&lt;/p&gt;

&lt;p&gt;Protect the logs. Tool arguments and model context may contain personal data, access tokens, or confidential documents. Redact secrets before ingestion, minimize payloads, encrypt storage, and restrict who can search agent traces. An audit platform should not become the easiest place to recover every credential.&lt;/p&gt;

&lt;p&gt;Use append-only or tamper-evident controls where evidence matters. Synchronize clocks and keep identifiers stable across queues and services. Define retention based on incident, regulatory, and privacy needs rather than keeping every prompt forever.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make audit operational
&lt;/h2&gt;

&lt;p&gt;Alert on patterns that matter: an agent requesting new scopes repeatedly, cross-tenant resource attempts, unusual tool sequences, refresh replay, or actions continuing after task cancellation. Periodically reconstruct a task from its events. If responders cannot answer who authorized an action and what changed, the schema is incomplete.&lt;/p&gt;

&lt;p&gt;Audit should support revocation also. A suspicious task identifier should lead to its active credentials, sessions, queued work, and downstream agents so responders can stop the chain.&lt;/p&gt;

&lt;p&gt;The takeaway is that agent accountability lives between identity and outcome. Record the human intent, machine actor, policy decision, execution, and resulting state. Anything less is an application log pretending to be an audit trail.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Akash Devdhar is a Senior Software Engineer specializing in enterprise identity, authentication, authorization, and AI infrastructure. He writes about building secure AI systems using OAuth, OIDC, RBAC, and modern identity architectures.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>ai</category>
      <category>security</category>
      <category>authorization</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Identity Federation for AI Ecosystems</title>
      <dc:creator>Akash Devdhar</dc:creator>
      <pubDate>Wed, 11 Nov 2026 21:27:42 +0000</pubDate>
      <link>https://dev.to/neospeed83/identity-federation-for-ai-ecosystems-1m7f</link>
      <guid>https://dev.to/neospeed83/identity-federation-for-ai-ecosystems-1m7f</guid>
      <description>&lt;p&gt;AI ecosystems are moving toward agents from one organization calling tools owned by another. The easy answer is federation: accept the other company's token and let the agent work. But federation does not mean foreign authorization becomes local authorization. It means you can verify who made a claim. Your system still decides what that claim is worth.&lt;/p&gt;

&lt;p&gt;Portable identity is useful. Portable permission is dangerous only.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.akashdevdhar.com%2Fdiagrams%2Fidentity-federation-ecosystem.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.akashdevdhar.com%2Fdiagrams%2Fidentity-federation-ecosystem.png" alt="Federated identity becomes local trust through mapping and policy" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Preserve the issuer and actor
&lt;/h2&gt;

&lt;p&gt;The stable identity key is normally issuer plus subject. A subject identifier without its issuer can collide. An email address can change or be reassigned. Map the external identity into a local tenant and account through configured trust, not through a domain string supplied at runtime.&lt;/p&gt;

&lt;p&gt;Agents add another identity. The human or organization authorizing the work is the subject, while the agent workload is the actor. Flattening both into one &lt;code&gt;sub&lt;/code&gt; claim makes audit and policy weaker.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;principal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;issuer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;iss&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;subject&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;actor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;act&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;audience&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;aud&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;tenant&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;localTrustMap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;iss&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reject unknown issuers, unexpected audiences, and algorithms outside the configured profile. Federation metadata helps distribute keys and endpoints, but configuration still needs ownership and change control.&lt;/p&gt;

&lt;h2&gt;
  
  
  Exchange external proof for local authority
&lt;/h2&gt;

&lt;p&gt;Do not forward a partner token through every internal service. Validate it at the federation boundary, apply local policy, then issue or exchange a shorter internal credential for the exact resource. RFC 8693 token exchange provides one model. Workload federation systems use a similar principle: external proof becomes a local, bounded credential.&lt;/p&gt;

&lt;p&gt;This translation is where tenant policy, contractual limits, risk, and resource ownership belong. The external issuer can say that agent X belongs to company Y. It cannot decide that agent X may update your production customer records.&lt;/p&gt;

&lt;p&gt;Keep trust directional. Accepting an issuer for one API does not mean accepting it everywhere. Bind the local token to one audience and prevent confused-deputy behavior where a token for a low-risk tool is replayed at a high-risk service.&lt;/p&gt;

&lt;h2&gt;
  
  
  Plan for trust lifecycle
&lt;/h2&gt;

&lt;p&gt;Federation relationships change. Keys rotate, partners are offboarded, issuers are compromised, and agent identities are replaced. Cache metadata with bounded lifetimes, support emergency distrust, and audit which trust configuration produced each decision.&lt;/p&gt;

&lt;p&gt;The future AI ecosystem will not have one global identity provider. It will have many trust domains exchanging evidence. The winning architecture will make those exchanges explicit and local authority narrow.&lt;/p&gt;

&lt;p&gt;The takeaway is that federation connects identities, not permission models. Verify external proof, preserve the actor chain, then make a local authorization decision. Trust can cross organizations without becoming unlimited.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Akash Devdhar is a Senior Software Engineer specializing in enterprise identity, authentication, authorization, and AI infrastructure. He writes about building secure AI systems using OAuth, OIDC, RBAC, and modern identity architectures.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>ai</category>
      <category>oidc</category>
      <category>oauth</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Giving AI Agents Least Privilege</title>
      <dc:creator>Akash Devdhar</dc:creator>
      <pubDate>Wed, 04 Nov 2026 20:51:16 +0000</pubDate>
      <link>https://dev.to/neospeed83/giving-ai-agents-least-privilege-jhf</link>
      <guid>https://dev.to/neospeed83/giving-ai-agents-least-privilege-jhf</guid>
      <description>&lt;p&gt;Teams say an agent has least privilege because its prompt says "only read customer tickets." Then the process receives a service-account token that can update tickets, export users, and call three internal APIs. The prompt is trying to negotiate with the model. The credential has already made the security decision.&lt;/p&gt;

&lt;p&gt;Least privilege for agents means the credential cannot perform actions outside the task, even when the model asks nicely or a prompt injection tells it to.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.akashdevdhar.com%2Fdiagrams%2Fagent-least-privilege.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.akashdevdhar.com%2Fdiagrams%2Fagent-least-privilege.png" alt="Agent authority should shrink at every delegation hop" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Size authority to the task
&lt;/h2&gt;

&lt;p&gt;A permanent agent role is usually too broad because agent work is contextual. One task may read invoices for tenant A. Another may draft an email without sending it. Create task-level grants that express the audience, scopes, tenant, resource constraints, and expiry.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"sub"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"agent:invoice-assistant"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"act"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"sub"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"user:123"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"aud"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://billing.example.com"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"scope"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"invoices:read"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"tenant_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"tenant-a"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"exp"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1788622800&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Claims are not enough by themselves. The billing API must validate each one and enforce object-level policy. A token saying &lt;code&gt;tenant-a&lt;/code&gt; should never be accepted for an invoice resolved to &lt;code&gt;tenant-b&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Delegation should only reduce power
&lt;/h2&gt;

&lt;p&gt;When a primary agent calls a sub-agent or tool, do not forward the original token. Exchange it for a downstream token with a smaller audience, shorter lifetime, and only the scope required for that hop. RFC 8693 provides the OAuth token-exchange pattern for this.&lt;/p&gt;

&lt;p&gt;This creates a monotonic rule: authority can stay the same or shrink, but it cannot grow during delegation. A calendar-reading agent cannot mint an email-sending token because a model decided that sending a summary would be useful also.&lt;/p&gt;

&lt;p&gt;Separate read, draft, and commit actions. Agents can often perform analysis with read access, produce a proposed change without write access, and request a narrowly approved credential only for the final side effect. This reduces standing privilege without making the product unusable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Remove invisible privilege
&lt;/h2&gt;

&lt;p&gt;Credentials are only one path. Network reachability, filesystem access, inherited cloud roles, plugin permissions, and cached secrets can all bypass the token model. Run agents in constrained environments and inventory the real capabilities available to the process.&lt;/p&gt;

&lt;p&gt;Audit denied actions as well as successful ones. Repeated requests for unavailable scopes may reveal a broken workflow or prompt injection. Make revocation task aware so cancelling one agent run does not require disabling the user entirely.&lt;/p&gt;

&lt;p&gt;The takeaway is that least privilege is not a static role. It is a property of every task and delegation hop. Give the agent enough authority to complete the approved work, then make everything else technically impossible, full stop.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Akash Devdhar is a Senior Software Engineer specializing in enterprise identity, authentication, authorization, and AI infrastructure. He writes about building secure AI systems using OAuth, OIDC, RBAC, and modern identity architectures.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>ai</category>
      <category>authorization</category>
      <category>oauth</category>
      <category>security</category>
    </item>
    <item>
      <title>OAuth for MCP: A Reference Architecture</title>
      <dc:creator>Akash Devdhar</dc:creator>
      <pubDate>Wed, 28 Oct 2026 19:39:54 +0000</pubDate>
      <link>https://dev.to/neospeed83/oauth-for-mcp-a-reference-architecture-ll1</link>
      <guid>https://dev.to/neospeed83/oauth-for-mcp-a-reference-architecture-ll1</guid>
      <description>&lt;p&gt;OAuth integrations for MCP become confusing when the MCP server is expected to be everything at once: resource server, login page, token issuer, and client registry. That design may work for one local demo, but it removes the trust boundaries OAuth is giving you basically for free.&lt;/p&gt;

&lt;p&gt;A useful reference architecture keeps four roles separate: MCP client, authorization server, access token, and MCP protected resource.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9teue6wjjxp3qfatufgx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9teue6wjjxp3qfatufgx.png" alt="OAuth for MCP separates the client, issuer, token, and protected resource" width="800" height="330"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Start at the resource
&lt;/h2&gt;

&lt;p&gt;The MCP client contacts a server and learns its authorization configuration through RFC 9728 protected-resource metadata. The metadata identifies the canonical resource and supported authorization server. The client then uses authorization-server metadata from RFC 8414 to find authorization and token endpoints.&lt;/p&gt;

&lt;p&gt;The current MCP specification requires this discovery for HTTP authorization. That matters because the client may encounter servers it was not preconfigured to know. Discovery must still be validated. Metadata is input, not automatic trust.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="nf"&gt;GET&lt;/span&gt; &lt;span class="nn"&gt;/.well-known/oauth-protected-resource&lt;/span&gt; &lt;span class="k"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="m"&gt;1.1&lt;/span&gt;
&lt;span class="na"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;mcp.example.com&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://mcp.example.com"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"authorization_servers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"https://identity.example.com"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"scopes_supported"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"calendar:read"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"calendar:write"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Bind the grant to the MCP server
&lt;/h2&gt;

&lt;p&gt;The authorization request should identify the target resource. The resulting access token must be valid for that MCP server only. The server validates issuer, audience, expiry, signature, and scope before processing a protocol request.&lt;/p&gt;

&lt;p&gt;Do not use an ID token as the access token. The ID token tells the client about authentication. The access token authorizes the protected resource. Mixing them creates exactly the cross-token confusion that strict audiences and token types are meant to prevent.&lt;/p&gt;

&lt;p&gt;Public clients use authorization code with PKCE. Confidential clients authenticate to the token endpoint using an appropriate method. Keep redirect URIs exact and use &lt;code&gt;state&lt;/code&gt; to bind the browser response. RFC 9700 collects the current OAuth 2.0 security practices behind these choices.&lt;/p&gt;

&lt;h2&gt;
  
  
  Scopes describe capabilities, policy limits resources
&lt;/h2&gt;

&lt;p&gt;MCP scopes should be stable capabilities such as &lt;code&gt;calendar:read&lt;/code&gt;, not thousands of object identifiers. The MCP server combines scope with tenant, delegated subject, tool arguments, and resource ownership at execution time.&lt;/p&gt;

&lt;p&gt;An AI agent calling on behalf of a user may need token exchange from RFC 8693. Exchange the upstream grant for a shorter token with one MCP audience and narrower scopes. Preserve the actor and delegated subject in a form the authorization server and resource understand.&lt;/p&gt;

&lt;p&gt;Revocation and audit complete the architecture. The authorization server controls token or grant state. The MCP server records which client and subject called which tool. Sensitive operations can request step-up authentication rather than treating the original login as permanent approval.&lt;/p&gt;

&lt;p&gt;The takeaway is not to invent MCP-specific credentials. Use OAuth roles properly. Let the authorization server issue bounded authority and make each MCP server defend its own resource boundary.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Akash Devdhar is a Senior Software Engineer specializing in enterprise identity, authentication, authorization, and AI infrastructure. He writes about building secure AI systems using OAuth, OIDC, RBAC, and modern identity architectures.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>oauth</category>
      <category>mcp</category>
      <category>authorization</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Secure Tool Calling for AI Agents</title>
      <dc:creator>Akash Devdhar</dc:creator>
      <pubDate>Wed, 21 Oct 2026 18:45:10 +0000</pubDate>
      <link>https://dev.to/neospeed83/secure-tool-calling-for-ai-agents-2275</link>
      <guid>https://dev.to/neospeed83/secure-tool-calling-for-ai-agents-2275</guid>
      <description>&lt;p&gt;Tool calling turns a model output into an action. That one transition is where an AI assistant becomes a security principal, but many systems protect it with only a JSON schema. The arguments are valid, therefore the action runs. Valid syntax is not valid authority.&lt;/p&gt;

&lt;p&gt;The agent should propose an action. A deterministic layer should decide whether that action is allowed, full stop.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F04jcxqklep36xn360nzg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F04jcxqklep36xn360nzg.png" alt="Every tool call needs a policy gate" width="800" height="330"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Treat model output as untrusted input
&lt;/h2&gt;

&lt;p&gt;Prompt injection, misunderstood context, and plain model mistakes all arrive through the same channel: tool name plus arguments. Validate types and lengths, reject unknown fields, normalize identifiers, and never allow the model to choose a credential or authorization scope.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;executeTool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;call&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ToolCall&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;AgentContext&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;input&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;TOOL_SCHEMAS&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;call&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;call&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;decision&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;policy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;evaluate&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;subject&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;agentId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;delegatedBy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;tenant&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tenantId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;action&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;call&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;resource&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resourceId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;decision&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;allowed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;tool call denied&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;tools&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;call&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;decision&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;credential&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The policy decision needs the real resource, not just the tool name. Permission to &lt;code&gt;read_file&lt;/code&gt; inside one project is not permission to read every path the tool can reach. Resolve aliases and indirect references before the final authorization check, otherwise the model can ask for an allowed-looking object that redirects to a protected one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Separate planning from execution
&lt;/h2&gt;

&lt;p&gt;Run planning without production credentials when possible. The agent can assemble a proposed sequence, then an execution service evaluates each step with current context. This reduces the chance that a malicious document can directly drive a privileged connector.&lt;/p&gt;

&lt;p&gt;High-impact tools need stronger controls. Sending money, deleting records, publishing externally, or changing identity policy may require human confirmation tied to the exact normalized action. A generic "allow this agent" click at session start is not meaningful approval for a different action twenty minutes later.&lt;/p&gt;

&lt;p&gt;Issue short-lived credentials for the approved tool and audience. RFC 8693 token exchange is useful when a user delegates to an agent and the agent needs a narrower downstream token. Do not hand every tool the agent's original broad token.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make retries safe and visible
&lt;/h2&gt;

&lt;p&gt;Agents retry. Networks retry also. Destructive tools need idempotency keys and clear side-effect semantics so a timeout does not send the same payment twice. Audit the proposed call, policy decision, credential identity, normalized input, tool result, and retry chain.&lt;/p&gt;

&lt;p&gt;Avoid placing secrets or full sensitive outputs into model-visible logs. The audit record should explain what happened without becoming a second data leak.&lt;/p&gt;

&lt;p&gt;The takeaway is that tool calling is an authorization workflow. Schemas make calls well formed. Policy makes them permitted. Scoped credentials and audit make them containable when the agent gets the plan wrong.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Akash Devdhar is a Senior Software Engineer specializing in enterprise identity, authentication, authorization, and AI infrastructure. He writes about building secure AI systems using OAuth, OIDC, RBAC, and modern identity architectures.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>ai</category>
      <category>authorization</category>
      <category>security</category>
      <category>mcp</category>
    </item>
    <item>
      <title>Designing Authentication for MCP Servers</title>
      <dc:creator>Akash Devdhar</dc:creator>
      <pubDate>Wed, 14 Oct 2026 18:43:31 +0000</pubDate>
      <link>https://dev.to/neospeed83/designing-authentication-for-mcp-servers-1kbh</link>
      <guid>https://dev.to/neospeed83/designing-authentication-for-mcp-servers-1kbh</guid>
      <description>&lt;p&gt;The fastest way to make an MCP server insecure is to treat authentication as an API key field in the client configuration. It works in a demo, then the server grows ten tools, connects to customer data, and one copied secret can call everything. MCP changes how tools are discovered. It does not change what a protected resource must prove before executing them.&lt;/p&gt;

&lt;p&gt;An HTTP MCP server should behave like an OAuth protected resource. It receives access tokens. It does not authenticate the human directly, and it should not collect the user's identity-provider password, full stop.&lt;/p&gt;

&lt;h2&gt;
  
  
  Discovery is part of the boundary
&lt;/h2&gt;

&lt;p&gt;The July 2026 MCP authorization specification requires protected-resource metadata for HTTP authorization. RFC 9728 defines the &lt;code&gt;/.well-known/oauth-protected-resource&lt;/code&gt; document that tells a client which authorization servers and scopes belong to the resource.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.akashdevdhar.com%2Fdiagrams%2Fmcp-auth-boundary.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.akashdevdhar.com%2Fdiagrams%2Fmcp-auth-boundary.png" alt="An MCP server is an OAuth protected resource" width="800" height="400"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://mcp.example.com"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"authorization_servers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"https://identity.example.com"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"scopes_supported"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"tickets:read"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"tickets:update"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The client must validate that the returned resource identifier matches the server it contacted. Otherwise discovery can become an authorization-server substitution path. The server must also validate that the access token was issued specifically for its own resource identifier, not merely signed by a familiar issuer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Authentication and tool authorization are separate
&lt;/h2&gt;

&lt;p&gt;A valid token answers which subject and client are calling. It does not mean every advertised tool is allowed. Map each tool to a required scope and evaluate resource context inside the handler.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;TOOL_SCOPES&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;get_ticket&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;tickets:read&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;update_ticket&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;tickets:update&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;authorizeTool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;token&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;AccessToken&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;tool&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;keyof&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;TOOL_SCOPES&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;token&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;aud&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://mcp.example.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;wrong audience&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;token&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;scopes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;TOOL_SCOPES&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;tool&lt;/span&gt;&lt;span class="p"&gt;]))&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;insufficient scope&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The handler must still check tenant and object-level access. &lt;code&gt;tickets:update&lt;/code&gt; is not permission to update every ticket in every customer's account.&lt;/p&gt;

&lt;p&gt;For local STDIO servers, the trust boundary is different because the process inherits credentials from its environment. Do not copy the HTTP OAuth flow blindly into that transport. Protect the environment, minimize the credential, and make the host application explicit about which local server it launches.&lt;/p&gt;

&lt;h2&gt;
  
  
  Preserve both human and client identity
&lt;/h2&gt;

&lt;p&gt;An MCP client often calls on behalf of a human, but the client is an actor also. Audit records should preserve the user subject, client identifier, MCP server, tool, scope, tenant, and outcome. If the token reduces everything to one service account, the server cannot distinguish a user-approved action from an autonomous retry.&lt;/p&gt;

&lt;p&gt;The takeaway is that MCP authentication is normal resource-server security applied to a powerful new interface. Publish trustworthy metadata, accept only audience-bound tokens, and authorize each tool call. The protocol can discover capabilities. Identity decides which capabilities become actions.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Akash Devdhar is a Senior Software Engineer specializing in enterprise identity, authentication, authorization, and AI infrastructure. He writes about building secure AI systems using OAuth, OIDC, RBAC, and modern identity architectures.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>mcp</category>
      <category>oauth</category>
      <category>authentication</category>
      <category>security</category>
    </item>
    <item>
      <title>MFA Isn’t Enough: Defense in Depth for Modern Applications</title>
      <dc:creator>Akash Devdhar</dc:creator>
      <pubDate>Wed, 07 Oct 2026 20:01:28 +0000</pubDate>
      <link>https://dev.to/neospeed83/mfa-isnt-enough-defense-in-depth-for-modern-applications-2d9</link>
      <guid>https://dev.to/neospeed83/mfa-isnt-enough-defense-in-depth-for-modern-applications-2d9</guid>
      <description>&lt;p&gt;MFA has become the answer to almost every authentication review. Password risk? Add MFA. Admin access? Add MFA. AI agent acting for a user? Somehow, add MFA once at the beginning and trust everything afterward. This is giving one control a job it was never designed to do.&lt;/p&gt;

&lt;p&gt;MFA proves that more than one factor was present during an authentication event. It does not prove that the current browser is still safe, that the session was not stolen, or that the next action is authorized. It raises assurance at one point in time only.&lt;/p&gt;

&lt;h2&gt;
  
  
  The attack moves after login
&lt;/h2&gt;

&lt;p&gt;Phishing-resistant MFA can make account takeover much harder. But attackers are adapting by stealing session cookies, abusing recovery flows, convincing users to approve malicious OAuth grants, and operating inside already authenticated devices. None of those attacks need to defeat the second factor again.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.akashdevdhar.com%2Fdiagrams%2Fmfa-defense-depth.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.akashdevdhar.com%2Fdiagrams%2Fmfa-defense-depth.png" alt="MFA is one control inside a larger trust chain" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The application needs multiple controls with different jobs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Secure session cookies, rotation, short idle windows, and revocation reduce the value of stolen sessions.&lt;/li&gt;
&lt;li&gt;Authorization checks limit what the authenticated subject can do on this resource right now.&lt;/li&gt;
&lt;li&gt;Device, network, and behavioral signals can trigger step-up authentication when risk changes.&lt;/li&gt;
&lt;li&gt;Recovery and support flows must preserve the same assurance level instead of becoming a cheaper back door.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;NIST SP 800-63B separates authentication assurance from session management for a reason. RFC 9470 also defines an OAuth step-up challenge so a resource can request stronger authentication for a specific action.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step up for the action, not for the whole day
&lt;/h2&gt;

&lt;p&gt;A user reading their profile and a user changing payout instructions should not consume the same trust decision forever. Represent the authentication context, then let sensitive operations require a recent or stronger method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;canChangePayout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;session&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Session&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;now&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mfaIsRecent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;now&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;mfaVerifiedAt&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="nx"&gt;_000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;authMethods&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;webauthn&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;mfaIsRecent&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is not an invitation to interrupt users constantly. It is a way to spend friction where the consequence is high. Low-risk work can continue with the ordinary session. High-risk work gets a fresh decision.&lt;/p&gt;

&lt;p&gt;AI agents make this separation more important also. A human completing MFA should not create an unlimited agent credential. The agent needs a separate, short-lived token scoped to the approved task. If the agent attempts a more sensitive tool, pause for a new authorization decision rather than stretching the original MFA event.&lt;/p&gt;

&lt;h2&gt;
  
  
  Defense in depth needs independent failure modes
&lt;/h2&gt;

&lt;p&gt;Five controls are not useful if all five trust the same stale session flag. Each layer should reduce risk the others cannot see. The identity provider authenticates. The session layer maintains continuity. The policy engine authorizes each action. The resource validates scope and tenant. Audit and revocation limit damage when something still goes wrong.&lt;/p&gt;

&lt;p&gt;MFA is one of the strongest controls in that chain, especially when it is phishing resistant. But making it the whole chain creates a secure front door attached to an open building.&lt;/p&gt;

&lt;p&gt;The takeaway is simple. Use MFA to raise confidence, then keep verifying what that confidence is being used for. Authentication starts trust. Defense in depth keeps it bounded.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Akash Devdhar is a Senior Software Engineer specializing in enterprise identity, authentication, authorization, and AI infrastructure. He writes about building secure AI systems using OAuth, OIDC, RBAC, and modern identity architectures.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>authentication</category>
      <category>mfa</category>
      <category>security</category>
      <category>architecture</category>
    </item>
    <item>
      <title>How Enterprise SSO Actually Works</title>
      <dc:creator>Akash Devdhar</dc:creator>
      <pubDate>Wed, 30 Sep 2026 19:28:23 +0000</pubDate>
      <link>https://dev.to/neospeed83/how-enterprise-sso-actually-works-5gh3</link>
      <guid>https://dev.to/neospeed83/how-enterprise-sso-actually-works-5gh3</guid>
      <description>&lt;p&gt;Enterprise SSO is usually explained as "log in once and access every application." That describes the user experience, but it hides the architecture so completely that teams start believing every application is sharing one giant session. They are not. Each application has its own session. What is shared is trust in the same identity provider, full stop.&lt;/p&gt;

&lt;p&gt;This difference matters because SSO failures are rarely about the login screen. They happen when an application trusts the wrong issuer, accepts an assertion intended for somebody else, maps groups directly into permanent privilege, or assumes that signing out from one place has magically ended every session everywhere.&lt;/p&gt;

&lt;p&gt;SSO is federation. One system proves that authentication happened, another system decides whether to accept that proof, and then the application creates local state of its own.&lt;/p&gt;

&lt;h2&gt;
  
  
  The identity provider does not log you into the application
&lt;/h2&gt;

&lt;p&gt;Take a normal employee opening a software-as-a-service application. The application does not have the employee's password, and it should not ask for it. Instead, it redirects the browser to an identity provider, usually called the IdP. The IdP authenticates the user using whatever controls the enterprise requires, perhaps password, phishing-resistant MFA, device posture, or an existing IdP session.&lt;/p&gt;

&lt;p&gt;After authentication, the IdP sends a signed response back through the browser. With SAML, that response contains a SAML assertion. With OpenID Connect, the application receives an authorization response, exchanges the authorization code at the token endpoint, and obtains an ID token.&lt;/p&gt;

&lt;p&gt;The browser is carrying the response, but the browser is not what makes it trustworthy. The signature, issuer, audience, time bounds, request correlation, and protocol validation make it trustworthy.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.akashdevdhar.com%2Fdiagrams%2Fsso-federated-login.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.akashdevdhar.com%2Fdiagrams%2Fsso-federated-login.png" alt="Enterprise SSO is a trust exchange followed by a local application session" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once the application validates the response, it maps the external identity to a local account and creates its own session cookie. On the next request, the application normally reads that local cookie. It does not redirect to the IdP every time only. This is why the application can remain signed in even when the IdP page is not open, and why logout becomes more complicated than login.&lt;/p&gt;

&lt;h2&gt;
  
  
  SAML and OIDC carry similar trust in different shapes
&lt;/h2&gt;

&lt;p&gt;SAML 2.0 is still common in enterprise software. It uses signed XML assertions and browser POST or redirect bindings. The application is the Service Provider, or SP. The IdP sends an assertion containing a subject, an audience restriction, validity times, and attributes.&lt;/p&gt;

&lt;p&gt;OpenID Connect is an identity layer built on OAuth 2.0. The application is an OIDC client, and the IdP is an OpenID Provider. Modern applications normally use the authorization code flow with PKCE. The ID token is usually a JWT, and the client can use the access token for a separate API when the design requires it.&lt;/p&gt;

&lt;p&gt;They solve a similar SSO problem, but they are not interchangeable payload formats. SAML has assertion consumer service URLs, entity IDs, XML signatures, and metadata. OIDC has redirect URIs, client IDs, discovery metadata, JSON Web Keys, authorization codes, and ID-token validation. Wrapping both behind one "SSO callback" abstraction can be useful, but the validation rules must stay protocol specific.&lt;/p&gt;

&lt;p&gt;The application should load trusted configuration from an administrative onboarding flow. It should not accept an arbitrary issuer or metadata URL from a login request. Otherwise the caller can choose which identity provider the application trusts, which is basically allowing the user to bring their own authority.&lt;/p&gt;

&lt;h2&gt;
  
  
  Validation is the real SSO implementation
&lt;/h2&gt;

&lt;p&gt;Redirecting a browser is easy. Correctly deciding whether the returned identity proof belongs to this request and this application is the security work.&lt;/p&gt;

&lt;p&gt;For OIDC, validate at least the issuer, audience, signature algorithm, expiry, and &lt;code&gt;nonce&lt;/code&gt;. Correlate the &lt;code&gt;state&lt;/code&gt; value with the browser session to defend the authorization response flow. Use an exact registered redirect URI. If the token contains multiple audiences, apply the protocol's authorized-party rules rather than picking the first value that looks familiar.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;tokenSet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;oidcClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://app.example.com/auth/callback&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;callbackParams&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;loginAttempt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;nonce&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;loginAttempt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;nonce&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;code_verifier&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;loginAttempt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;codeVerifier&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;claims&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;tokenSet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;claims&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;claims&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;iss&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;configuredIssuer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;unexpected identity provider&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;account&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;accounts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolveFederatedIdentity&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;issuer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;claims&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;iss&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;subject&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;claims&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The stable external identifier is the pair of issuer and subject, not email address by itself. Email can change, be reused, or collide across identity providers. Linking accounts by an unverified email is convenient right until one tenant's identity becomes another tenant's local account.&lt;/p&gt;

&lt;p&gt;For SAML, validate the XML signature using the configured IdP certificate, the response destination, audience restriction, assertion validity, and request correlation such as &lt;code&gt;InResponseTo&lt;/code&gt; when the flow expects it. Protect against XML signature wrapping by using a maintained SAML library and consuming only the element that the library verified. Searching the XML tree manually for a convenient &lt;code&gt;NameID&lt;/code&gt; defeats the point of the signature.&lt;/p&gt;

&lt;p&gt;The OIDC Core specification and SAML 2.0 Profiles define these checks because each one closes a different substitution or replay path. They are not optional decoration around the signature.&lt;/p&gt;

&lt;h2&gt;
  
  
  Account mapping is where tenants get crossed
&lt;/h2&gt;

&lt;p&gt;After validation, the application has an external identity. It still has to answer a local question: which account and tenant does this identity belong to.&lt;/p&gt;

&lt;p&gt;Enterprise applications often discover the tenant from the verified issuer or an explicit SSO connection selected before redirect. That connection maps one enterprise IdP to one application tenant. The returned email or domain may help onboarding, but it should not silently override the configured tenant boundary.&lt;/p&gt;

&lt;p&gt;Just-in-time provisioning can create a local user after the first successful SSO response. SCIM can provision users and groups before login. These are lifecycle choices, not authentication shortcuts. Whether the account was created just in time or through SCIM, the application still needs a durable mapping and a clear disabled state.&lt;/p&gt;

&lt;p&gt;Group and role claims need careful treatment also. An IdP group proves that the IdP placed the user in that group. It does not automatically mean the application should grant administrator access. Map external groups through tenant-owned policy, keep defaults narrow, and decide what happens when a claim disappears. Authorization remains an application responsibility.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.akashdevdhar.com%2Fdiagrams%2Fsso-identity-to-authorization.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.akashdevdhar.com%2Fdiagrams%2Fsso-identity-to-authorization.png" alt="SSO establishes identity, then the application applies tenant and authorization policy" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This separation is useful during incidents. You can see whether the IdP authenticated the wrong person, the federation mapping selected the wrong local account, or the application granted the wrong permission. If everything is called "SSO," those three failures become one vague ticket.&lt;/p&gt;

&lt;h2&gt;
  
  
  SSO login is easier than SSO logout
&lt;/h2&gt;

&lt;p&gt;Login works well because the browser follows a chain and every participant can create new state. Logout asks multiple independent systems to destroy state they own, sometimes when one of them is unavailable.&lt;/p&gt;

&lt;p&gt;Signing out of the application should always end the application's local session. Redirecting to an IdP logout endpoint may end the IdP session, but it does not guarantee every other application session is gone. SAML Single Logout and OIDC logout specifications provide coordination mechanisms, but deployments vary and front-channel browser flows can fail.&lt;/p&gt;

&lt;p&gt;For high-risk environments, do not rely on coordinated logout as the only revocation strategy. Keep local session lifetimes appropriate, consume deprovisioning events, and re-check sensitive authorization. If an employee is disabled at the IdP, an application session with a month-long lifetime should not remain trusted simply because no logout message arrived.&lt;/p&gt;

&lt;h2&gt;
  
  
  AI agents should not borrow the SSO session
&lt;/h2&gt;

&lt;p&gt;An AI agent acting for an employee needs the human identity context, but the agent is not the human. Passing the browser session cookie into an agent process collapses two actors into one credential and makes the audit trail useless basically.&lt;/p&gt;

&lt;p&gt;Use SSO to authenticate the human and establish the application's local session. When the user delegates a task, issue or exchange a separate short-lived credential for the agent. That credential should identify the workload, preserve the delegated subject, target one audience, and carry narrower scope. RFC 8693 token exchange is one useful pattern for this on-behalf-of relationship.&lt;/p&gt;

&lt;p&gt;The distinction becomes important when the user logs out, the task is cancelled, or the agent delegates to a tool. The application can revoke the agent task without pretending the browser and the agent are one session. The resource API can log both who authorized the work and which workload actually performed it.&lt;/p&gt;

&lt;p&gt;SSO answers how the human entered the trust system. It does not give every autonomous process permission to impersonate that human afterward.&lt;/p&gt;

&lt;h2&gt;
  
  
  The takeaway
&lt;/h2&gt;

&lt;p&gt;Enterprise SSO is a chain of explicit trust decisions. The IdP authenticates the user and signs a protocol response. The application validates that response, maps the external identity into the correct tenant, and creates a local session. Then the application applies its own authorization policy.&lt;/p&gt;

&lt;p&gt;SAML and OIDC make the exchange interoperable. They do not remove the need for strict validation, lifecycle management, or local access control. Once you see SSO as federation instead of a shared login, the architecture becomes much easier to reason about, and much harder to accidentally trust too broadly.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Akash Devdhar is a Senior Software Engineer specializing in enterprise identity, authentication, authorization, and AI infrastructure. He writes about building secure AI systems using OAuth, OIDC, RBAC, and modern identity architectures.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>authentication</category>
      <category>sso</category>
      <category>oidc</category>
      <category>saml</category>
    </item>
    <item>
      <title>Designing Secure Authentication APIs</title>
      <dc:creator>Akash Devdhar</dc:creator>
      <pubDate>Wed, 23 Sep 2026 18:26:28 +0000</pubDate>
      <link>https://dev.to/neospeed83/designing-secure-authentication-apis-2c4l</link>
      <guid>https://dev.to/neospeed83/designing-secure-authentication-apis-2c4l</guid>
      <description>&lt;p&gt;Many authentication APIs are basically one controller with very high confidence. Accept email and password, compare a hash, sign a JWT, return 200. Add HTTPS and rate limiting, then call it production ready. The endpoint may be only fifty lines, but those fifty lines are now issuing proof that every other service will trust. That is not a normal controller. It is a security protocol boundary, full stop.&lt;/p&gt;

&lt;p&gt;What I am seeing is that teams are reviewing authentication APIs like business APIs. Does the input validate. Does the database query work. Does the happy path return the right JSON. Those questions matter, but the dangerous behavior is usually between requests: what an attacker can learn from failures, whether an old refresh token still works, which audience accepts the token, and what happens after the account is disabled.&lt;/p&gt;

&lt;h2&gt;
  
  
  The endpoint is smaller than the protocol
&lt;/h2&gt;

&lt;p&gt;Consider the naive shape:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/login&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findByEmail&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;email&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;404&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;user not found&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;verifyPassword&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;password&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;passwordHash&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;401&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;wrong password&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;signJwt&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;role&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;token&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It works. It also reveals which email addresses exist, gives every resource server the same vaguely defined token, copies authorization into a credential with no freshness model, and has no visible session or refresh-token lifecycle. The bug is not one missing &lt;code&gt;if&lt;/code&gt; statement. The API has no protocol around it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.akashdevdhar.com%2Fdiagrams%2Fauth-api-credential-factory.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.akashdevdhar.com%2Fdiagrams%2Fauth-api-credential-factory.png" alt="A naive login endpoint becomes an uncontrolled credential factory" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Authentication design starts before password verification and continues after token issuance. Treat enrollment, recovery, MFA, login, refresh, logout, and revocation as one connected system. An account-recovery flow that bypasses MFA can defeat a perfectly implemented login endpoint. A refresh endpoint that accepts replay forever can undo a short access-token lifetime also.&lt;/p&gt;

&lt;h2&gt;
  
  
  Failure responses are part of the attack surface
&lt;/h2&gt;

&lt;p&gt;Different errors make debugging pleasant and account enumeration easy. "User not found" and "incorrect password" tell an attacker whether the first guess was correct. Different response times can reveal the same thing even when the JSON is identical.&lt;/p&gt;

&lt;p&gt;For public login and recovery endpoints, return a uniform external response for invalid credentials or unknown accounts. Internally, log the actual reason with appropriate access controls. When the account does not exist, perform a bounded password-hash operation using a fixed dummy hash so the timing shape stays reasonably close.&lt;/p&gt;

&lt;p&gt;Rate limiting needs more than an IP address. Attackers distribute traffic, and shared corporate networks put many legitimate users behind one IP. Combine controls by source, account identifier, device or client signal, and overall risk. Apply progressive delay or step-up checks where appropriate. Do not turn rate limiting into a denial-of-service button where anyone can lock a victim's account by sending bad passwords.&lt;/p&gt;

&lt;p&gt;The response should not explain your internal identity state. The audit trail should.&lt;/p&gt;

&lt;h2&gt;
  
  
  A token needs one meaning
&lt;/h2&gt;

&lt;p&gt;"It is a valid JWT" is not a security decision. A JWT is a container. The resource server must know who issued it, which audience it targets, which algorithms are allowed, what token type it represents, and whether its time bounds are acceptable.&lt;/p&gt;

&lt;p&gt;RFC 8725, the JSON Web Token Best Current Practices document, is clear about algorithm verification and cross-JWT confusion. An ID token should not accidentally work as an API access token. A token minted for the billing API should not work at the administration API just because both services know the same signing key.&lt;/p&gt;

&lt;p&gt;Validation should be explicit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;claims&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;jwtVerify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rawToken&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;signingKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;issuer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://identity.example.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;audience&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://api.example.com/invoices&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;algorithms&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ES256&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;typ&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;at+jwt&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;clockTolerance&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;claims&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;token_use&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;access&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;unexpected token type&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nf"&gt;hasRequiredScope&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;claims&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;scope&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;invoices:read&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;insufficient scope&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Do not let the token choose its own verification algorithm. Do not accept every audience your company owns. Do not make a resource server understand login-session cookies, ID tokens, access tokens, and internal agent tokens through one permissive parser. Separate token profiles make rejection easier to reason about.&lt;/p&gt;

&lt;h2&gt;
  
  
  Short access tokens need a real refresh design
&lt;/h2&gt;

&lt;p&gt;Short-lived access tokens reduce the useful window after theft, but only if the refresh token is handled as the more powerful credential it is. A refresh token that lives for months, can be replayed repeatedly, and is stored beside the access token has not reduced much risk actually.&lt;/p&gt;

&lt;p&gt;Rotate refresh tokens on every successful use. Store a hash of the current token, link tokens into a family, and treat reuse of an already-consumed token as a replay signal. Revoke the active family and require reauthentication rather than issuing one more access token to whichever party arrived second.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;exchangeRefreshToken&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;presented&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;digest&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;hashToken&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;presented&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;tokenStore&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;tx&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;record&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;tx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findForUpdate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;digest&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;record&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;record&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;revokedAt&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;record&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;expiresAt&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;invalid refresh token&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;record&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;consumedAt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;tx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;revokeFamily&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;record&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;familyId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
      &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;refresh token replay detected&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;tx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;markConsumed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;record&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;tx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;issueSuccessor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;record&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;familyId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;record&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;subjectId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The transaction is important. Two refresh requests racing each other should not both receive valid successors. One succeeds. The other becomes evidence that the credential may have been copied.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.akashdevdhar.com%2Fdiagrams%2Fauth-api-controlled-issuance.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.akashdevdhar.com%2Fdiagrams%2Fauth-api-controlled-issuance.png" alt="A secure authentication API keeps token issuance inside explicit controls" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Agents are not unusual users
&lt;/h2&gt;

&lt;p&gt;When an AI agent needs an API, teams often send it through the human login endpoint using a service account. That creates a credential which looks like a person, has no delegation chain, and usually carries broad permissions because nobody can predict every task the agent may attempt.&lt;/p&gt;

&lt;p&gt;Give workloads their own client identity. Use an OAuth grant appropriate for the actor, such as client credentials for the agent's own authority or token exchange from RFC 8693 when it acts on behalf of a user. Bind the resulting access token to one audience and narrow scopes. Keep the human subject and agent identity distinguishable in logs.&lt;/p&gt;

&lt;p&gt;An agent session also needs a different lifetime. A browser may remain signed in for convenience, while an agent task should receive a credential bounded to the task and expire when the work should stop. Reusing the browser token is easy, but it makes logout, audit, and least privilege much harder only.&lt;/p&gt;

&lt;p&gt;For high-risk machine-to-machine calls, sender-constrained tokens can reduce bearer-token theft. Mutual TLS and proof-of-possession approaches add operational work, so use them where the threat justifies it, but understand the tradeoff. A bearer token belongs to whoever holds it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Recovery and revocation are authentication APIs too
&lt;/h2&gt;

&lt;p&gt;Password reset, account recovery, device removal, and session revocation are sometimes built later by a different team. Attackers do not respect those ownership boundaries. They use whichever path produces trust most cheaply.&lt;/p&gt;

&lt;p&gt;Recovery tokens should be single use, short lived, stored hashed, and scoped to the exact recovery action. Completing recovery should invalidate relevant sessions and refresh-token families. Changing a password without touching already issued credentials leaves the attacker signed in.&lt;/p&gt;

&lt;p&gt;Revocation behavior needs a measurable target. If disabling an account must stop sensitive access within five minutes, access-token lifetimes, caches, long-lived connections, and background jobs must honor that window. Writing a disabled flag into the user table is not revocation until the services check it.&lt;/p&gt;

&lt;p&gt;Audit every credential transition: issuance, failed authentication, MFA challenge, refresh rotation, replay detection, recovery, and revocation. Avoid logging raw passwords, session IDs, access tokens, or recovery secrets. An audit system that captures the credential itself becomes another credential store.&lt;/p&gt;

&lt;h2&gt;
  
  
  The takeaway
&lt;/h2&gt;

&lt;p&gt;A secure authentication API does more than verify a password and sign a token. It controls what failures reveal, gives each token one precise meaning, detects refresh replay, and carries revocation through the rest of the architecture.&lt;/p&gt;

&lt;p&gt;Treat human sessions, service identities, and delegated agent access as different credential flows. They can share identity infrastructure, but they should not share one ambiguous token. The API is issuing trust that other systems will act on, and that trust needs a protocol around it, not just a controller.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Akash Devdhar is a Senior Software Engineer specializing in enterprise identity, authentication, authorization, and AI infrastructure. He writes about building secure AI systems using OAuth, OIDC, RBAC, and modern identity architectures.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>authentication</category>
      <category>oauth</category>
      <category>security</category>
      <category>api</category>
    </item>
    <item>
      <title>Session Management at Scale</title>
      <dc:creator>Akash Devdhar</dc:creator>
      <pubDate>Wed, 16 Sep 2026 18:14:18 +0000</pubDate>
      <link>https://dev.to/neospeed83/session-management-at-scale-3hl0</link>
      <guid>https://dev.to/neospeed83/session-management-at-scale-3hl0</guid>
      <description>&lt;p&gt;Teams usually discover they have a session-management problem when Redis gets slow. They add replicas, tune TTLs, maybe shard by user ID, and declare the system scaled. The cache is faster, yes. The security model is still the same fragile one only.&lt;/p&gt;

&lt;p&gt;A session is not just a cookie pointing at some server state. It is a live trust decision that has escaped the login service and started moving through your architecture. It reaches APIs, background workers, WebSocket connections, mobile devices, and now AI agents that can keep working after the user closes the browser. Scaling the lookup is the easy part. Scaling the meaning of that trust is where systems break.&lt;/p&gt;

&lt;h2&gt;
  
  
  Login creates a session, but the session keeps changing
&lt;/h2&gt;

&lt;p&gt;At login time the picture looks clean. A user proves identity, perhaps completes MFA, and receives a session identifier. The server stores a record with the user, expiry, and maybe a few claims. Every request presents the cookie and the application loads the record.&lt;/p&gt;

&lt;p&gt;Then reality arrives. The user changes organizations. An administrator removes a role. Risk signals require another MFA check. The user signs out one device but not another. A support team needs to revoke every active session after an account recovery. The original login was valid, but the authorization context around it is changing basically all the time.&lt;/p&gt;

&lt;p&gt;If the session is a signed blob with a 30-day expiry and no server-side control, those changes wait 30 days also. Cryptographic validity is not the same as current authorization.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.akashdevdhar.com%2Fdiagrams%2Fsession-stale-trust.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.akashdevdhar.com%2Fdiagrams%2Fsession-stale-trust.png" alt="A long-lived session spreads stale trust across the system" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is the first design decision that matters: what must be checked on every request, and what can safely remain fixed until expiry. User identity might be stable for the session. Tenant membership, account status, risk level, and sensitive permissions often are not.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep the browser credential small and meaningless
&lt;/h2&gt;

&lt;p&gt;The browser should hold an opaque, high-entropy session identifier in a cookie with &lt;code&gt;Secure&lt;/code&gt;, &lt;code&gt;HttpOnly&lt;/code&gt;, and an appropriate &lt;code&gt;SameSite&lt;/code&gt; policy. It should not hold the full authorization model in a value that every service learns to trust independently.&lt;/p&gt;

&lt;p&gt;RFC 6265 defines cookie behavior, but cookie flags are only transport controls. They help protect the identifier. They do not solve rotation, revocation, or authorization freshness.&lt;/p&gt;

&lt;p&gt;A server-side session record can stay compact:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;SessionRecord&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;subjectId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;tenantId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;createdAt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;lastSeenAt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;idleExpiresAt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;absoluteExpiresAt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;authLevel&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;password&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;mfa&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;version&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;revokedAt&lt;/span&gt;&lt;span class="p"&gt;?:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice what is not there: a copied list of every permission the user had at login. Keep stable session facts in the record, then resolve authorization that can change from the current policy or membership source. Otherwise the session store becomes a warehouse of stale entitlements.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rotation closes a window that expiry leaves open
&lt;/h2&gt;

&lt;p&gt;Session expiry answers how long a credential may live. Rotation answers whether the same credential should survive a security boundary such as login, MFA completion, password reset, tenant switch, or privilege elevation.&lt;/p&gt;

&lt;p&gt;Without rotation, an identifier captured before login can become an authenticated session after login. That is session fixation. Without rotation after privilege elevation, the same long-lived identifier moves from ordinary access to sensitive access with no new boundary around it.&lt;/p&gt;

&lt;p&gt;The safe pattern is to create a new identifier and invalidate the old one atomically:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;rotateSession&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;oldId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;update&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Partial&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;SessionRecord&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;sessionStore&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;tx&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;tx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getForUpdate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;oldId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;revokedAt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;session is no longer active&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;update&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;crypto&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;randomUUID&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
      &lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;version&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;lastSeenAt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;tx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;revoke&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;oldId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;tx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;insert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Atomicity matters. If both identifiers remain valid during a race, rotation has created a second session rather than replacing the first one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Revocation must reach every service
&lt;/h2&gt;

&lt;p&gt;Central session storage gives you a revocation point, but only if every path actually checks it. A normal HTTP request may load the session on every call while a WebSocket authenticates once and remains connected for hours. A queued job may have copied the subject and tenant into its payload. An internal service may cache a successful session check for longer than the revocation target.&lt;/p&gt;

&lt;p&gt;This is why a useful session design begins with a revocation objective. If disabling an account must stop sensitive actions within five minutes, every cache, connection, and worker must either revalidate inside five minutes or receive a reliable revocation event. Writing &lt;code&gt;revokedAt&lt;/code&gt; into Redis does nothing for a process that never looks again.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.akashdevdhar.com%2Fdiagrams%2Fsession-revocation-control.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.akashdevdhar.com%2Fdiagrams%2Fsession-revocation-control.png" alt="Central session control keeps distributed work inside the revocation window" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For high-risk actions, check current session state immediately and require step-up authentication when the authentication level is not sufficient. For lower-risk reads, a short cache may be reasonable. The policy should be explicit. Accidental cache duration is not a security policy.&lt;/p&gt;

&lt;p&gt;NIST SP 800-63B is useful here because it separates overall session lifetime from inactivity timeout and reauthentication requirements. Those controls should not collapse into one TTL field. An active session can still hit its absolute maximum, and a session inside its maximum can still require fresh authentication before a sensitive action.&lt;/p&gt;

&lt;h2&gt;
  
  
  AI agents create sessions inside sessions
&lt;/h2&gt;

&lt;p&gt;An agent task is often treated as a background continuation of the user's browser session. The user starts a task, the agent receives some credentials, and it keeps running. But the browser session may end while the task is still making decisions. If the agent simply copied the original bearer token, logout becomes mostly cosmetic.&lt;/p&gt;

&lt;p&gt;The agent needs its own bounded execution session. It should identify the workload, preserve who delegated the task, target one tenant, and carry only the scopes needed for that task. Its lifetime should reflect the work, not the user's browser-cookie lifetime. If it delegates to another agent or tool, the downstream credential should become narrower, not inherit everything.&lt;/p&gt;

&lt;p&gt;OAuth 2.0 Token Exchange from RFC 8693 gives a useful pattern for creating that downstream credential. The browser session establishes the human context, but the agent receives a separate short-lived token with its own audience and traceable delegation. Revoking the task can then stop the agent without destroying every user session, and revoking the user can still cascade to active tasks when policy requires it.&lt;/p&gt;

&lt;p&gt;This distinction also improves audit logs. "User 123 made API call" is incomplete when an autonomous workload performed the call twenty minutes after the user clicked a button. Record the session, agent identity, delegated subject, tenant, and task identifier. Otherwise all autonomous work becomes indistinguishable from direct human action.&lt;/p&gt;

&lt;h2&gt;
  
  
  Availability cannot quietly disable security
&lt;/h2&gt;

&lt;p&gt;A centralized session store becomes critical infrastructure, so teams are tempted to fail open when it is unavailable. That turns an operational incident into an authorization bypass. If a service cannot determine whether a sensitive session is active, it should not assume active.&lt;/p&gt;

&lt;p&gt;You can reduce the availability risk with replicas, regional stores, carefully bounded local caches, and signed short-lived proofs. But every optimization needs a maximum stale-trust window. A five-minute cache is a decision that revoked access may continue for five minutes. Sometimes that is acceptable. Pretending it is only a performance setting is not.&lt;/p&gt;

&lt;p&gt;Monitor identity outcomes, not just cache latency. Track rejected expired sessions, revoked-session reuse, rotation failures, impossible tenant switches, and how long revocation takes to reach long-lived connections. A session system can have perfect uptime while authorization freshness is completely broken.&lt;/p&gt;

&lt;h2&gt;
  
  
  The takeaway
&lt;/h2&gt;

&lt;p&gt;Session management at scale is the work of keeping trust current while it spreads. Store as little as possible in the browser, rotate identifiers when trust changes, separate idle and absolute lifetime, and make revocation reach every execution path inside a known window.&lt;/p&gt;

&lt;p&gt;For AI agents, do not stretch a human browser session until it covers autonomous work. Create a smaller, traceable execution session with its own identity and expiry. The moment a session crosses a service boundary, it becomes identity architecture, full stop.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Akash Devdhar is a Senior Software Engineer specializing in enterprise identity, authentication, authorization, and AI infrastructure. He writes about building secure AI systems using OAuth, OIDC, RBAC, and modern identity architectures.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>authentication</category>
      <category>security</category>
      <category>architecture</category>
      <category>ai</category>
    </item>
    <item>
      <title>Designing Multi-Tenant Identity Systems</title>
      <dc:creator>Akash Devdhar</dc:creator>
      <pubDate>Wed, 09 Sep 2026 17:52:07 +0000</pubDate>
      <link>https://dev.to/neospeed83/designing-multi-tenant-identity-systems-1702</link>
      <guid>https://dev.to/neospeed83/designing-multi-tenant-identity-systems-1702</guid>
      <description>&lt;p&gt;Most multi-tenant applications are one missing filter away from becoming somebody else's data breach. That sounds dramatic, but the architecture is often exactly this: accept a &lt;code&gt;tenant_id&lt;/code&gt; from the request, add it to a SQL query, and call the system isolated. It is not isolated. It is trusting the caller to tell you which security boundary should apply, which is basically asking the request to authorize itself.&lt;/p&gt;

&lt;p&gt;A tenant is not just a row partition. It is an identity and authorization boundary, full stop. If that boundary is not established from a verified identity and enforced at every layer that touches protected data, then the application is multi-tenant only in the product brochure.&lt;/p&gt;

&lt;h2&gt;
  
  
  The dangerous version looks reasonable
&lt;/h2&gt;

&lt;p&gt;The most common design is attractive because it is simple. A frontend knows the current tenant, so it sends &lt;code&gt;X-Tenant-ID&lt;/code&gt;. The API reads the header and uses it in every repository query. Engineers review the query and see &lt;code&gt;WHERE tenant_id = ?&lt;/code&gt;, so everybody feels safe.&lt;/p&gt;

&lt;p&gt;The issue is not the filter. The issue is who supplied its value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/invoices&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;tenantId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;header&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;X-Tenant-ID&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;invoices&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;invoice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findMany&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;where&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;tenantId&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;invoices&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An authenticated user can change a header only. If the API does not independently prove that the user belongs to that tenant, the filter is doing exactly what the attacker requested. Authentication succeeded, the database query is scoped, and the data is still wrong. This is why authentication and tenant isolation cannot be separate conversations.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.akashdevdhar.com%2Fdiagrams%2Fmulti-tenant-caller-controlled.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.akashdevdhar.com%2Fdiagrams%2Fmulti-tenant-caller-controlled.png" alt="Caller-controlled tenant context creates a false security boundary" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What I am noticing is that teams are putting tenant selection inside application state, when it belongs inside verified security context. The browser can request a tenant switch, of course, but the identity layer must decide whether that switch is permitted and mint or establish the resulting context. The browser does not get to declare it as fact.&lt;/p&gt;

&lt;h2&gt;
  
  
  Derive tenant context from identity
&lt;/h2&gt;

&lt;p&gt;The safer model begins with a verified session or access token. That identity carries a subject, an audience, and either a tenant claim or enough membership information for the authorization service to resolve one. The API validates the token, confirms membership, then creates an internal request context that downstream code cannot replace with a header or request-body field.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;TenantContext&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;subjectId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;tenantId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;scopes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Set&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;buildTenantContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;TenantContext&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;verifyAccessToken&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;authorization&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;requestedTenant&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;x-tenant-id&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;requestedTenant&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;tenant context is required&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;membership&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;memberships&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findActive&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nx"&gt;token&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;subject&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;requestedTenant&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;membership&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;subject is not a member of this tenant&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;subjectId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;token&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;subject&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;tenantId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;membership&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tenantId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;scopes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;token&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;scopes&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The header still exists here, but it is a request to select from the user's verified memberships, not proof of membership by itself. That difference is the whole model actually.&lt;/p&gt;

&lt;p&gt;For an AI agent, the context needs one more piece: delegation. The agent's own identity tells you which workload is calling. It does not automatically prove which customer or human authorized this task. A useful agent token or token-exchange result should preserve both the agent identity and the delegated subject, with a narrow tenant and audience. Otherwise one agent credential can quietly become a bridge between every customer the service supports.&lt;/p&gt;

&lt;p&gt;OAuth 2.0 Token Exchange, defined in RFC 8693, is useful here because a service can exchange an upstream token for a narrower downstream token. The new token can target one resource server and one tenant context rather than forwarding a broad credential through the full service chain. OpenID Connect claims establish identity, but your authorization policy still has to decide how those claims map to tenant membership.&lt;/p&gt;

&lt;h2&gt;
  
  
  Carry the boundary through every hop
&lt;/h2&gt;

&lt;p&gt;Verifying tenant membership at the first API is necessary, but it is not enough only. Multi-tenant systems usually have queues, background jobs, internal APIs, caches, and agents calling tools. Tenant context gets lost at these boundaries because developers serialize the business payload and forget the security context that made the action valid.&lt;/p&gt;

&lt;p&gt;A background job should never wake up with only an &lt;code&gt;invoiceId&lt;/code&gt; and then search globally. It should carry the tenant identifier, initiating subject, and authorization purpose, and the worker should verify those values before acting. Internal services should receive a signed, audience-bound token rather than a forwarded browser header. Cache keys must include the tenant boundary also, otherwise perfectly authorized reads can leak through a shared cache.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.akashdevdhar.com%2Fdiagrams%2Fmulti-tenant-verified-context.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.akashdevdhar.com%2Fdiagrams%2Fmulti-tenant-verified-context.png" alt="Verified tenant context is carried and enforced through every service hop" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The important part in this design is that each service treats tenant context as security input. It is not ordinary metadata that can be dropped, overwritten, or filled with a default when missing. Missing tenant context should fail closed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Enforce isolation again at the data layer
&lt;/h2&gt;

&lt;p&gt;Application checks are valuable, but relying on every engineer to remember every filter forever is a weak last line of defense. The repository or database layer should make cross-tenant access difficult by construction.&lt;/p&gt;

&lt;p&gt;PostgreSQL Row-Level Security is one option. The application sets verified tenant context on the database session, and a policy restricts rows regardless of which query the application writes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;invoices&lt;/span&gt; &lt;span class="n"&gt;ENABLE&lt;/span&gt; &lt;span class="k"&gt;ROW&lt;/span&gt; &lt;span class="k"&gt;LEVEL&lt;/span&gt; &lt;span class="k"&gt;SECURITY&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="n"&gt;POLICY&lt;/span&gt; &lt;span class="n"&gt;tenant_isolation&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;invoices&lt;/span&gt;
&lt;span class="k"&gt;USING&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tenant_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;current_setting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'app.tenant_id'&lt;/span&gt;&lt;span class="p"&gt;)::&lt;/span&gt;&lt;span class="n"&gt;uuid&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="k"&gt;CHECK&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tenant_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;current_setting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'app.tenant_id'&lt;/span&gt;&lt;span class="p"&gt;)::&lt;/span&gt;&lt;span class="n"&gt;uuid&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is not magic. Connection pooling has to reset session state correctly, privileged database roles must not bypass the policy casually, and migrations need testing. But it changes the failure mode. A forgotten application filter becomes a denied query instead of a customer-data incident.&lt;/p&gt;

&lt;p&gt;Some systems choose separate schemas or separate databases for stronger isolation. That can be the correct decision for regulatory or high-value tenants, but it adds operational cost. The point is not that one storage model wins everywhere. The point is that the isolation strength should match the consequence of crossing the boundary, and it should not depend on a single controller remembering a &lt;code&gt;WHERE&lt;/code&gt; clause.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tenant membership is lifecycle data
&lt;/h2&gt;

&lt;p&gt;Identity architecture tends to focus on login, while tenant membership keeps changing after login. Users join organizations, leave them, switch roles, and sometimes belong to several tenants at once. Agents get reassigned or disabled. A token issued yesterday can carry authorization that is no longer true today.&lt;/p&gt;

&lt;p&gt;Keep access tokens short-lived. Re-evaluate membership when selecting a tenant or performing sensitive work. Use SCIM where it fits for enterprise provisioning and deprovisioning, but do not assume that provisioning alone gives you runtime authorization. SCIM can tell your system that a user was removed. Your session and token design determines how quickly that removal actually stops access.&lt;/p&gt;

&lt;p&gt;Audit records should capture at least the effective tenant, the human or workload subject, delegated identity when present, the action, and the authorization decision. Logging only &lt;code&gt;user_id&lt;/code&gt; is not enough in a system where the same subject can act inside multiple customer boundaries.&lt;/p&gt;

&lt;h2&gt;
  
  
  The takeaway
&lt;/h2&gt;

&lt;p&gt;The tenant boundary must come from identity, travel with the request, and be enforced where the data lives. If any layer can guess it, default it, or accept it without verification, then that layer can cross it also.&lt;/p&gt;

&lt;p&gt;A &lt;code&gt;tenant_id&lt;/code&gt; column is useful data modeling. A verified tenant context is security architecture. Multi-tenant systems need both, and confusing one for the other is how an application ends up showing the right query in code review and the wrong customer's data in production.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Akash Devdhar is a Senior Software Engineer specializing in enterprise identity, authentication, authorization, and AI infrastructure. He writes about building secure AI systems using OAuth, OIDC, RBAC, and modern identity architectures.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>authentication</category>
      <category>authorization</category>
      <category>architecture</category>
      <category>security</category>
    </item>
    <item>
      <title>RBAC vs ABAC: Choosing the Right Authorization Model</title>
      <dc:creator>Akash Devdhar</dc:creator>
      <pubDate>Wed, 02 Sep 2026 17:56:32 +0000</pubDate>
      <link>https://dev.to/neospeed83/rbac-vs-abac-choosing-the-right-authorization-model-5h4i</link>
      <guid>https://dev.to/neospeed83/rbac-vs-abac-choosing-the-right-authorization-model-5h4i</guid>
      <description>&lt;p&gt;Every time an AI agent project hits its first "wait, this agent should not have been able to do that" moment, someone proposes the same fix: add more roles. Split "support_engineer" into "support_engineer_tier1" and "support_engineer_tier2." Add a "read_only_agent" role. This works for about two more incidents, and then you have forty roles, half of them overlapping, and nobody actually knows what any of them mean anymore. That is the point where the conversation should shift from RBAC to ABAC, and it is also the point where most teams do it wrong, because they treat ABAC as "RBAC but with more config" instead of an actually different way of thinking about the problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  What RBAC is actually good at, and where it stops working
&lt;/h2&gt;

&lt;p&gt;Role Based Access Control is simple, and simple is a feature, not a weakness. You define a role, "support_engineer," you attach a fixed bundle of permissions to it, "read tickets, read customer profile," and you assign the role to a subject, human or agent. This works great when permissions genuinely cluster into a small number of stable job functions. It is also exactly why it breaks for agents.&lt;/p&gt;

&lt;p&gt;An agent's required permissions are not a fixed job function, they are a function of context. The same support agent should be able to read a ticket in its own team's queue but not in a different team's queue. It should be able to act during business hours on a live incident but maybe not at 3am unattended. It should be able to act on behalf of the specific user who invoked it, not on behalf of any user who happens to share its role. RBAC has no native concept of "in its own team's queue" or "on behalf of this specific user," so people fake it with more and more roles, and the role explosion is the actual symptom, not the disease.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.akashdevdhar.com%2Fdiagrams%2Fdiagram-1-rbac-model.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.akashdevdhar.com%2Fdiagrams%2Fdiagram-1-rbac-model.png" alt="RBAC: a role is a fixed bundle of permissions" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What ABAC actually changes
&lt;/h2&gt;

&lt;p&gt;Attribute Based Access Control does not ask "what role does this subject have." It asks "given everything we know about the subject, the resource, and the environment right now, does this specific action pass the policy." Subject attributes: which team, which clearance level, who delegated to it. Resource attributes: which team owns this ticket, how sensitive is it. Environment attributes: what time is it, is this an emergency escalation. The decision is computed at request time, not looked up from a static table.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.akashdevdhar.com%2Fdiagrams%2Fdiagram-2-abac-model.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.akashdevdhar.com%2Fdiagrams%2Fdiagram-2-abac-model.png" alt="ABAC: permission is a live decision computed from attributes" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is genuinely more powerful for the "agent acting on behalf of a specific person, in a specific context" problem that RBAC struggles with. It is also more work, and this is the part people skip. ABAC without a real, maintained policy set is not more secure than RBAC, it is just a different place to hide the same mess, and honestly a worse one, because a bad ABAC policy is harder to audit at a glance than a list of forty overlapping roles.&lt;/p&gt;

&lt;h2&gt;
  
  
  The honest tradeoff
&lt;/h2&gt;

&lt;p&gt;I am not telling you ABAC is strictly better, that would be dishonest actually. RBAC is easier to reason about, easier to audit ("show me everyone with the admin role" is a one line query), and perfectly fine for systems where permissions genuinely map to stable job functions. ABAC is the right call once your access decisions depend on context that changes per request, which for agent systems is most of the time, but only if someone actually owns writing and testing the policies, the same way someone has to actually own the role definitions in an RBAC system that is not a mess. Neither model saves you from doing the thinking, they just organize where the thinking lives.&lt;/p&gt;

&lt;h2&gt;
  
  
  A quick code example
&lt;/h2&gt;

&lt;p&gt;RBAC, a straightforward role lookup:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;ROLE_PERMISSIONS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;support_engineer&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;tickets:read&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;customer_profile:read&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;is_allowed_rbac&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;subject&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;role&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;subject&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;role&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;action&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;ROLE_PERMISSIONS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;role&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;ABAC, a policy evaluated against subject, resource, and environment attributes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;is_allowed_abac&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;subject&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;resource&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;action&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;tickets:read&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;same_team&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;subject&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;team&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;resource&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;team&lt;/span&gt;
        &lt;span class="n"&gt;within_hours&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;hour&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;22&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;acting_for_owner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;subject&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;delegated_by&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;resource&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;owner_id&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;same_team&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;within_hours&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;acting_for_owner&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice the ABAC version is not longer because ABAC is inherently more complex, it is longer because it is actually encoding the real rule, "same team, and either business hours or acting for the resource's owner," instead of pretending that rule can be flattened into a role name.&lt;/p&gt;

&lt;h2&gt;
  
  
  Standards worth reading
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;INCITS 359-2012&lt;/strong&gt;, the NIST RBAC model, for the formal definition of roles, permissions, and role hierarchies.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;NIST SP 800-162&lt;/strong&gt;, Guide to Attribute Based Access Control, for how to actually define subject, resource, and environment attributes and structure policies around them, this is the one to read before building an ABAC system, not after.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The takeaway
&lt;/h2&gt;

&lt;p&gt;RBAC fails for agents not because roles are a bad idea, but because agent permissions are contextual and roles are not. ABAC fixes that by making the decision live instead of a lookup, but it only works if you put in the same discipline you would have needed for RBAC anyway, just applied to policies instead of role definitions. Pick RBAC when your access model genuinely maps to stable jobs. Pick ABAC when it depends on who, what, and when, and budget the time to actually own the policies, because an unmaintained ABAC system is not a safer RBAC system, it is a harder to audit one.&lt;/p&gt;

</description>
      <category>authorization</category>
      <category>rbac</category>
      <category>abac</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
