<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet href="/rss-style.xsl" type="text/xsl"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Sagara Gunathunga</title><description>Practical deep dives on OAuth 2.0, OpenID Connect, SAML, MCP security and AI agent identity by Sagara Gunathunga, Head of DevRel at WSO2 IAM.</description><link>https://sagarag.dev</link><language>en</language><atom:link href="https://sagarag.dev/rss.xml" rel="self" type="application/rss+xml"/><dc:creator>Sagara Gunathunga</dc:creator><item><title>Going Stateless Was the Right Call for MCP, but with a Cost</title><link>https://sagarag.dev/posts/mcp-stateless-migration-cost</link><guid isPermaLink="true">https://sagarag.dev/posts/mcp-stateless-migration-cost</guid><description>MCP is now stateless. Here&apos;s why that&apos;s the right call, what actually replaces the old session handshake, and why state didn&apos;t disappear</description><pubDate>Fri, 25 Sep 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/0.CBzM9HS0_in1rY.webp&quot; alt=&quot;How browser-based agents work&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 2055px) 2055px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;2055&quot; height=&quot;765&quot;&gt;&lt;/p&gt;
&lt;p&gt;Almost two years ago, when I went through the &lt;a href=&quot;https://modelcontextprotocol.io/specification/2024-11-05&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;MCP specification&lt;/a&gt; for the first time, one thing stood out to me immediately. MCP was a &lt;strong&gt;stateful&lt;/strong&gt; protocol.&lt;/p&gt;
&lt;p&gt;Coming from an integration background, this concerned me, a protocol that carries state across requests also carries additional complexity, and MCP was going to inherit all of it.&lt;/p&gt;
&lt;p&gt;This changed with the &lt;a href=&quot;https://modelcontextprotocol.io/specification/2026-07-28&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;code&gt;2026-07-28&lt;/code&gt;&lt;/a&gt; revision. MCP is now a &lt;strong&gt;stateless&lt;/strong&gt; protocol, and according to my point of view, this was the right call. It should have happened sooner, the longer a protocol remains stateful, the more implementations get built around that assumption, and each of them eventually has to pay the migration cost.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/1.CEz1M2cQ_2ht1OJ.webp&quot; alt=&quot;How browser-based agents work&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 2172px) 2172px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;2172&quot; height=&quot;724&quot;&gt;&lt;/p&gt;
&lt;h2 id=&quot;why-statefulness-was-always-going-to-be-a-problem-for-mcp&quot;&gt;Why Statefulness Was Always Going to Be a Problem for MCP&lt;/h2&gt;
&lt;p&gt;Let’s look at what a stateful protocol requires in practice, and the operational problems it creates.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Load balancing breaks down&lt;/strong&gt;:
A stateful protocol ties a client session to a specific server instance, once that instance is selected, every subsequent request from the client has to return to it, and a normal round-robin load balancer is no longer sufficient.
This is the same &lt;strong&gt;sticky session&lt;/strong&gt; problem that WebSocket-based services have dealt with for many years.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Fault tolerance and reliability suffer&lt;/strong&gt;:
When the server instance holding a session goes down, the client cannot simply retry its last request. It first has to detect the disconnected session, reconnect, and rebuild the state that was already established, in MCP’s case, that meant repeating the initialization handshake before the client could send another meaningful request.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Session lifecycle management becomes your responsibility&lt;/strong&gt;:
Someone has to create, track, expire, and eventually clean up the session state, and in practice, this does not always happen as cleanly as expected.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Clients also inherit complexity&lt;/strong&gt;
The server is not the only component paying for statefulness, clients need reconnection and resynchronization logic to recover from a dropped connection, logic a normal request-and-response model never requires.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Standard infrastructure can no longer sit in front of it easily&lt;/strong&gt;
A reverse proxy, API gateway, or security control normally assumes it can process each request independently. A stateful protocol breaks that assumption, the infrastructure in front of the server has to understand the session and route requests accordingly.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Testing and reproducibility become harder&lt;/strong&gt;
With a stateful protocol, a single request can be difficult to understand or reproduce in isolation, you often need to recreate the entire sequence of interactions that came before it just to reach the state it depends on.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;how-mcp-previously-handled-state&quot;&gt;How MCP Previously Handled State&lt;/h2&gt;
&lt;p&gt;Establishing a session started with the &lt;strong&gt;initialization handshake&lt;/strong&gt;, and it required exactly three interactions. The client sent a request to the server, the server returned a response, and the client completed the handshake with a final notification, client to server, server to client, client to server, in that order, and nothing else could begin until all three were done.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/2.BV4HXCUf_Z1ceQvl.webp&quot; alt=&quot;How browser-based agents work&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1819px) 1819px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1819&quot; height=&quot;865&quot;&gt;&lt;/p&gt;
&lt;p&gt;The first message was the &lt;strong&gt;initialize&lt;/strong&gt; request. This was where the client declared the protocol version it wanted to use and the capabilities it supported, one of which was &lt;strong&gt;elicitation&lt;/strong&gt;, which allows a server to pause an operation and ask the user for information through the client. The request also carried the client’s identity, including its name and version, so the server knew exactly which client it was talking to.&lt;/p&gt;
&lt;p&gt;The server returned the same kind of information in the other direction, its own name, version, and supported capabilities. Finally, the client sent &lt;code&gt;notifications/initialized&lt;/code&gt; to confirm the initialization process was complete.&lt;/p&gt;
&lt;p&gt;Client and server capabilities do not become unnecessary simply because MCP is now stateless. Both sides still need to understand what the other supports before they can work together, that need never disappears, only the mechanism for meeting it changes.&lt;/p&gt;
&lt;p&gt;The handshake also gave a server the opening to return a &lt;strong&gt;session&lt;/strong&gt; identifier, an &lt;code&gt;Mcp-Session-Id&lt;/code&gt; header in its initialize response, and the client then had to attach the same header to every request that followed.&lt;/p&gt;
&lt;h2 id=&quot;what-changed-in-mcp-from-version-2026-07-28&quot;&gt;What Changed in MCP &lt;em&gt;[from version 2026-07-28]&lt;/em&gt;&lt;/h2&gt;
&lt;p&gt;The main change is the removal of the entire &lt;code&gt;initialize&lt;/code&gt; request, response, and &lt;code&gt;notifications/initialized&lt;/code&gt; handshake. The &lt;code&gt;Mcp-Session-Id&lt;/code&gt; header is gone too, there is no header carrying a session identifier between requests, because there is no protocol session left to identify.&lt;/p&gt;
&lt;p&gt;It looks like a relatively small change. It isn’t, and this is the part I would check your own implementation against, four other important capabilities were removed or changed along with it:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Servers can no longer initiate their own requests.&lt;/strong&gt; Previously, a server could send requests such as &lt;code&gt;roots/list&lt;/code&gt;, &lt;code&gt;sampling/createMessage&lt;/code&gt;, or &lt;code&gt;elicitation/create&lt;/code&gt; to the client over an SSE stream. This pattern is no longer supported.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The HTTP GET stream endpoint is gone&lt;/strong&gt;, and &lt;code&gt;resources/subscribe&lt;/code&gt; and &lt;code&gt;resources/unsubscribe&lt;/code&gt; went with it. Long-lived server-to-client notifications now use a single &lt;code&gt;subscriptions/listen&lt;/code&gt; request, the client declares the notification types it wants, and the server keeps the response stream open to deliver them.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SSE streams are no longer resumable.&lt;/strong&gt; &lt;code&gt;Last-Event-ID&lt;/code&gt; and SSE event IDs have been removed from the Streamable HTTP transport. If a response stream is interrupted, the in-flight request is lost, and the client must issue it again with a new request ID.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Roots, Sampling, and Logging are also now formally deprecated. They still work, but new implementations should not start depending on them.&lt;/p&gt;
&lt;h3 id=&quot;the-old-and-new-versions-can-coexist&quot;&gt;The old and new versions can coexist&lt;/h3&gt;
&lt;p&gt;If you already have an implementation built on any of this, there is no need to panic. Different MCP protocol versions can coexist, a server can keep supporting an older, stateful version for existing clients while it adopts the new stateless version for newer ones.&lt;/p&gt;
&lt;p&gt;This revision also introduced a formal feature lifecycle and deprecation policy. A feature marked deprecated needs a minimum twelve-month deprecation period before it can be removed, and the specification maintains a published registry of what is currently in that state. That gives implementers a reasonable window, and for once the timeline is documented rather than assumed.&lt;/p&gt;
&lt;p&gt;Even so, I would treat version coexistence as a migration bridge, not a permanent architecture. Maintaining a stateful version and a stateless version side by side gets expensive, the two versions make different assumptions about sessions, connections, and infrastructure, and you end up maintaining two different operating models for the same server.&lt;/p&gt;
&lt;p&gt;My suggestion is to start planning the migration now. There is no need to rush the new version into production, it is reasonable to let the specification and SDK support mature first, but I would not postpone the planning either.&lt;/p&gt;
&lt;h3 id=&quot;a-new-discovery-method-replaces-the-handshake&quot;&gt;A new discovery method replaces the handshake&lt;/h3&gt;
&lt;p&gt;The new version introduces &lt;code&gt;server/discover&lt;/code&gt;, and every server must implement it. It lets a server advertise the protocol versions it supports, its capabilities, and its identity.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/3.DAuY6ib__WQ0P4.webp&quot; alt=&quot;How browser-based agents work&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1819px) 1819px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1819&quot; height=&quot;865&quot;&gt;&lt;/p&gt;
&lt;p&gt;Clients are treated differently. A client may call &lt;code&gt;server/discover&lt;/code&gt; before making any other request if it wants to select a version in advance, or use it as a backward-compatibility probe on stdio, but it is not required to. If the client already knows which protocol version it is using, it can go straight to a method such as &lt;code&gt;tools/list&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The request carries the client’s capabilities using &lt;code&gt;io.modelcontextprotocol/clientCapabilities&lt;/code&gt;, along with &lt;code&gt;io.modelcontextprotocol/clientInfo&lt;/code&gt; to identify the client.
Client capabilities describe what the client can support, as an example, a client declares elicitation support as follows.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/4.2Asmdrx3_2deMc0.webp&quot; alt=&quot;How browser-based agents work&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1942px) 1942px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1942&quot; height=&quot;809&quot;&gt;&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;server/discover&lt;/code&gt; response carries the server’s &lt;code&gt;capabilities&lt;/code&gt;, much like the information the old &lt;code&gt;initialize&lt;/code&gt; response used to hand over, whether it supports tools, whether it notifies the client when the tool list changes, and so on.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/5.B0j8sl4z_Z1aChE9.webp&quot; alt=&quot;How browser-based agents work&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1774px) 1774px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1774&quot; height=&quot;887&quot;&gt;&lt;/p&gt;
&lt;p&gt;The server’s identity comes back separately, through &lt;code&gt;io.modelcontextprotocol/serverInfo&lt;/code&gt; in the result’s &lt;code&gt;_meta&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&quot;every-request-carries-its-own-capabilities&quot;&gt;Every request carries its own capabilities&lt;/h3&gt;
&lt;p&gt;This is the part that actually replaces the session.&lt;/p&gt;
&lt;p&gt;Because there is no handshake and no session remembering what was agreed earlier, every request has to carry the same &lt;code&gt;_meta&lt;/code&gt; information the old &lt;code&gt;initialize&lt;/code&gt; request sent only once. Three fields do that work:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;io.modelcontextprotocol/protocolVersion&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;io.modelcontextprotocol/clientInfo&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;io.modelcontextprotocol/clientCapabilities&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This applies to &lt;code&gt;tools/list&lt;/code&gt;, &lt;code&gt;resources/list&lt;/code&gt;, tool invocations, everything.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/6.BOtvIqNM_Z1r36Dv.webp&quot; alt=&quot;How browser-based agents work&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1536px) 1536px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1536&quot; height=&quot;1024&quot;&gt;&lt;/p&gt;
&lt;p&gt;Take elicitation again. If a client wants the server to be able to request information from the user during a tool call, it can no longer rely on a capability declared once at the start of the connection, it has to declare elicitation support in the &lt;code&gt;_meta&lt;/code&gt; of that exact request. The server has no stored session information left to check against.&lt;/p&gt;
&lt;p&gt;This is not just bookkeeping. A server is not allowed to request a capability the client has not declared for that request, so with no session, the declaration and the ask have to travel together.&lt;/p&gt;
&lt;p&gt;Carrying the protocol version and capabilities in the JSON-RPC body makes the request stateless, but an ordinary reverse proxy or gateway still cannot use that information for routing unless it parses the full body. So for Streamable HTTP, selected values are also mirrored into HTTP headers.&lt;/p&gt;
&lt;p&gt;Every POST carries an &lt;code&gt;MCP-Protocol-Version&lt;/code&gt; header, &lt;code&gt;Mcp-Method&lt;/code&gt; mirrors the JSON-RPC method name, and for requests such as &lt;code&gt;tools/call&lt;/code&gt;, &lt;code&gt;resources/read&lt;/code&gt;, and &lt;code&gt;prompts/get&lt;/code&gt;, &lt;code&gt;Mcp-Name&lt;/code&gt; mirrors the tool name or resource URI. These are required for protocol compliance, not offered as a convenience, and a missing required header is itself a validation failure. As an example, a request to call a weather tool now looks as follows.&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light nord&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#d8dee9ff;--shiki-light-bg:#fff;--shiki-dark-bg:#2e3440ff;overflow-x:auto;white-space:pre-wrap;word-wrap:break-word&quot; tabindex=&quot;0&quot; data-language=&quot;http&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#81A1C1&quot;&gt;POST&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#D8DEE9FF&quot;&gt; /mcp &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#81A1C1&quot;&gt;HTTP&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#D8DEE9FF&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#B48EAD&quot;&gt;1.1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#22863A;--shiki-dark:#81A1C1&quot;&gt;MCP-Protocol-Version&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#81A1C1&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt; 2026-07-28&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#22863A;--shiki-dark:#81A1C1&quot;&gt;Mcp-Method&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#81A1C1&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt; tools/call&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#22863A;--shiki-dark:#81A1C1&quot;&gt;Mcp-Name&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#81A1C1&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt; get_weather&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;method&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;tools/call&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;params&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;get_weather&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;--shiki-light:#B31D28;--shiki-light-font-style:italic;--shiki-dark:#D8DEE9;--shiki-dark-font-style:inherit&quot;&gt; ...&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt; }&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt; }&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A gateway can now make routing and policy decisions by reading these headers alone, which backend pool should take a weather-tool request, whether a tenant is even allowed to call it, without ever parsing the JSON-RPC body.&lt;/p&gt;
&lt;h2 id=&quot;removing-sessions-did-not-remove-the-need-for-state&quot;&gt;Removing Sessions Did Not Remove the Need for State&lt;/h2&gt;
&lt;p&gt;MCP has removed the protocol-level session. Does that mean an application using MCP can no longer carry information between calls?&lt;/p&gt;
&lt;p&gt;No. Some workflows still need information to survive across requests, the difference is that the application now has to make that state explicit rather than borrowing it from a session. There are two main situations here, and they call for different answers.&lt;/p&gt;
&lt;p&gt;Consider a shopping cart. A model calls one tool to add an item, calls it again to add another, and then calls a third tool to check out. These are separate tool calls, but all of them need to operate on the same cart, and that requirement comes from the application workflow, not from MCP.&lt;/p&gt;
&lt;p&gt;Under the old model, the session absorbed this requirement for you, whatever cart the session referenced was the cart every call touched. Take the session away, and the requirement does not go with it, you still need an answer to “which cart”, MCP just no longer answers it for you automatically.&lt;/p&gt;
&lt;p&gt;The answer here is an ordinary tool result. A &lt;code&gt;create_basket&lt;/code&gt; tool can return a &lt;code&gt;basket_id&lt;/code&gt;, and every call after that takes it as a normal argument, as follows.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/7.C5NwCvQE_Z2uBlqA.webp&quot; alt=&quot;How browser-based agents work&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1774px) 1774px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1774&quot; height=&quot;887&quot;&gt;&lt;/p&gt;
&lt;p&gt;There is no new protocol construct here, no special handle schema anywhere in the spec. It is just a string the server returns and the client passes back, and several remote MCP servers already work this way, a create operation returns an issue ID or a pull request number, and every later call takes that identifier as an argument.&lt;/p&gt;
&lt;p&gt;The specification calls this pattern an &lt;strong&gt;explicit state handle&lt;/strong&gt;, precisely because that’s all a &lt;code&gt;basket_id&lt;/code&gt;, an issue ID, or a PR number really is, a handle the model holds and passes back.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The second situation&lt;/strong&gt; is the replacement for server-initiated requests, and I want to be clear that it is not a niche case. &lt;strong&gt;Multi Round-Trip Requests&lt;/strong&gt; (&lt;strong&gt;MRTR&lt;/strong&gt;), is now how every server-to-client interaction works, sampling, roots, and elicitation all go through it. If your MCP server currently sends its own requests to a client, this is the part of the migration that will affect you.&lt;/p&gt;
&lt;p&gt;This is different from the shopping cart example. Here there is one logical operation, but it cannot complete in a single round trip. As an example, a tool updating a support ticket might discover partway through that a business rule requires information the original request did not include, the operation is interrupted and needs to resume once the user provides it.&lt;/p&gt;
&lt;p&gt;The main requirement is correlation, whatever answers that question eventually has to be reconnected to the exact call that asked it, without the server keeping the incomplete operation sitting in memory the whole time.&lt;/p&gt;
&lt;p&gt;Instead of waiting, or sending its own request over a stream, the server ends the current request immediately with an &lt;code&gt;InputRequiredResult&lt;/code&gt;. Every result in this revision carries a &lt;code&gt;resultType&lt;/code&gt;, and for this case, the value is &lt;code&gt;&amp;quot;input_required&amp;quot;&lt;/code&gt; rather than &lt;code&gt;&amp;quot;complete&amp;quot;&lt;/code&gt;. The response can carry two optional fields, and at least one must be present:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;inputRequests&lt;/code&gt;, a map of server-assigned keys to the requests that must be fulfilled. The values can be &lt;code&gt;ElicitRequest&lt;/code&gt;, &lt;code&gt;CreateMessageRequest&lt;/code&gt;, or &lt;code&gt;ListRootsRequest&lt;/code&gt; objects.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;requestState&lt;/code&gt;, an opaque value understood only by the server. The client must return it exactly as received, without inspecting, parsing, or modifying it.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The client gathers the requested information and retries the original operation. The new request carries an &lt;code&gt;inputResponses&lt;/code&gt; map using the same keys, together with the original &lt;code&gt;requestState&lt;/code&gt; value, and one detail is easy to miss: the retry has to use a different JSON-RPC &lt;code&gt;id&lt;/code&gt;, because this is an independent request, not a continuation of the first one.&lt;/p&gt;
&lt;h2 id=&quot;you-did-not-remove-state-you-moved-it&quot;&gt;You Did Not Remove State, You Moved It&lt;/h2&gt;
&lt;p&gt;At this point, one can ask a very valid question: did MCP actually remove state, or did it just move the responsibility somewhere else?&lt;/p&gt;
&lt;p&gt;Agent workflows are stateful by nature. Removing sessions does not change that, it just relocates some of the complexity, out of server memory and into tool arguments and the model’s context. State handles consume tokens every time they are passed, the model has to remember to include them, and models are not always reliable about it. MRTR can cause a request to execute again from the beginning, so some work gets repeated.&lt;/p&gt;
&lt;p&gt;On that reading, the protocol did not solve the state problem, it handed part of the responsibility to a language model, which is not normally the component you would pick to guarantee correctness.&lt;/p&gt;
&lt;p&gt;Most of that criticism is fair. Handles consume tokens, and retries can repeat work, I am not going to argue with the parts that are true.&lt;/p&gt;
&lt;p&gt;Where I would push back is on the framing. The state in these workflows was always application state. A shopping cart belongs to the application, not to a transport session, the session was never really holding it, it was holding a pointer and creating the impression that the session owned the state. What changed is that the pointer is now visible.&lt;/p&gt;
&lt;p&gt;That visibility is worth something, particularly for audit and access control. A &lt;code&gt;basket_id&lt;/code&gt; sitting in a tool argument shows up in logs, passes through the gateway, and can be used in an authorization decision, an in-memory session tied to one connection gives you none of that. The same goes for &lt;code&gt;requestState&lt;/code&gt;, it is opaque to the client, but it is still an explicit value crossing a defined boundary, which makes it something you can identify, protect, and reason about.&lt;/p&gt;
&lt;p&gt;According to my point of view, I would rather review a system where the state is written down in the request than one that is implied by whichever server instance happened to process it.&lt;/p&gt;
&lt;h2 id=&quot;wrapping-up&quot;&gt;Wrapping Up&lt;/h2&gt;
&lt;p&gt;MCP started as a stateful protocol because it grew out of local, single-process tools. Now that MCP servers are expected to run behind load balancers, gateways, and production infrastructure they were never originally built for, moving to a stateless model is the right call, and among people who have actually had to run this kind of thing at scale, that is not a controversial position.&lt;/p&gt;
&lt;p&gt;Stateless does not mean state-free, though. The handshake is gone, the session ID is gone, but the actual work some applications do, a cart that survives several calls, a tool that has to pause and ask the user something mid-flight, has not gone anywhere. The new model just makes that state explicit through state handles and MRTR instead of borrowing it from a session.&lt;/p&gt;</content:encoded><dc:creator>Sagara Gunathunga</dc:creator><category>MCP</category></item><item><title>Why We Only Catch &quot;Rogue&quot; AI Agents by Accident</title><link>https://sagarag.dev/posts/agent-identity-gap</link><guid isPermaLink="true">https://sagarag.dev/posts/agent-identity-gap</guid><description>Three frontier labs disclosed that their AI agents breached real companies. None were caught in real time. The problem is not model behavior—it is that the agent is using your identity.</description><pubDate>Wed, 12 Aug 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/0.4FR_jSl1_ZPlud3.webp&quot; alt=&quot;When your AI assistant is so nice to you that it hacks a reservation system to book you a gym class, are you liable&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1886px) 1886px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1886&quot; height=&quot;834&quot;&gt;&lt;/p&gt;
&lt;p&gt;As a story broke out in &lt;a href=&quot;https://www.rnz.co.nz/news/world/952663/ai-assistant-hacks-gym-website-in-first-known-australian-autonomous-cyber-attack&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;local news recently&lt;/a&gt;, in Melbourne a man asked his AI assistant to book him a spot in a gym class. An ordinary request, a chore as he thought.&lt;/p&gt;
&lt;p&gt;The assistant (OpenClaw, running on Claude) went and looked at the gym’s booking site, found the API sitting behind it, and noticed something it was never asked to look for: the API performed no authorization checks at all. So it booked him into a class months beyond the window the gym actually allows.&lt;/p&gt;
&lt;p&gt;Then he came back and mentioned he was stuck at number four on the waitlist, and asked if anything could be done. The agent went one step further, it canceled the reservation of the person holding position number one and moved him up. Then he asked it to undo that and it couldn’t, the other person’s spot was simply gone. It’s indeed an interesting story you can read from &lt;a href=&quot;https://www.rnz.co.nz/news/world/952663/ai-assistant-hacks-gym-website-in-first-known-australian-autonomous-cyber-attack&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;there-was-no-attacker-and-there-was-still-a-breach&quot;&gt;There was no attacker, and there was still a breach&lt;/h2&gt;
&lt;p&gt;Nobody at that gym was attacked by a hacker. No malware, no phishing, no criminal. A guy wanted a workout slot.&lt;/p&gt;
&lt;p&gt;But let’s name what happened in the terms your own security team would use. An authorization control was bypassed, a record belonging to another person was destroyed, the affected party was never notified, and the action could not be reversed. That is an incident, and it would be handled as one.&lt;/p&gt;
&lt;p&gt;The user asked for a class, the agent pursued the goal it was given and found a route to it, and it is reasonable to believe the gym operated the booking system for years without such issues. Every party behaved reasonably, and the outcome was still a breach.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/1.CFl4UGTp_ZiaBFH.webp&quot; alt=&quot;Intent mismatch between the human and AI agent&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1971px) 1971px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1971&quot; height=&quot;798&quot;&gt;&lt;/p&gt;
&lt;p&gt;So the missing piece is not the intent. He approved a goal (get me into that class) and he never saw the route, and the route is where the whole problem lived.&lt;/p&gt;
&lt;p&gt;Now you might be thinking the fix is obvious, make the agent confirm each step. It would mask this, and it doesn’t survive contact with reality. Set aside that nobody sits through consent prompts for long, because bulk approval arrives within a week and bulk approval is what we already have. The harder problem is that whoever approves would need to look at a cancellation call carrying a reservation ID that isn’t theirs and recognize it as an authorization flaw.&lt;/p&gt;
&lt;p&gt;Now, you might be tempted to file this under consumer AI gone wrong, a novelty story about a hobbyist assistant and a small business with a sloppy API. I’d like to convince you it isn’t. In the three weeks before it happened:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;OpenAI &lt;a href=&quot;https://openai.com/index/hugging-face-model-evaluation-security-incident/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;disclosed&lt;/a&gt; that an agent running on its frontier models broke out of an evaluation environment and reached into four accounts across four third-party services.&lt;/li&gt;
&lt;li&gt;Anthropic &lt;a href=&quot;https://www.anthropic.com/news/investigating-incidents-cybersecurity-evals&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;disclosed&lt;/a&gt; that three of its models reached the public internet from supposedly isolated environments and compromised three real organizations, using weak passwords, unauthenticated endpoints, and SQL injection. One of them built and published a malicious Python package that ran on fifteen real systems before it was pulled.&lt;/li&gt;
&lt;li&gt;Meta &lt;a href=&quot;https://www.reuters.com/technology/metas-ai-model-hacked-another-company-during-testing-information-reports-2026-08-05/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;disclosed&lt;/a&gt; that one of its models reached the internet through a sandbox misconfiguration at its external evaluation partner, and exploited a vulnerability in a third-party service.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Three disclosures, three weeks, and here is the detail that got far less coverage than the incidents themselves. Not one of them was caught while it was happening.&lt;/p&gt;
&lt;p&gt;Anthropic found theirs by going back and reading 141,006 evaluation records after a competitor’s disclosure prompted them to look, and the earliest incident dated back to April. Meta found out when its evaluation partner told them. And the only reason the gym case became a story at all is that one person happened to be curious enough, and qualified enough, to read what his agent had done.&lt;/p&gt;
&lt;p&gt;Taking the gym hacking incident as a concrete example, we can identify a few things that could have gone wrong.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Broken and insufficient authorization.&lt;/strong&gt; Most authorization in production is a mix of what the API actually checks and what the interface simply does not offer. The gym had both failures in one system (a booking window enforced only in the front-end, and a cancellation endpoint that never asked whose reservation it was). Neither had ever been exploited, because for as long as the only client was the vendor’s own application, no code path existed that would try.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Adaptive clients using a consent model built for deterministic ones.&lt;/strong&gt; When a user approves a client, that client’s behavior was already written, reviewed, tested, and shipped, so consent given today covers actions fixed in the past. An agent inverts the arrow. Its behavior is generated after the consent, in response to a goal, so the user is approving something that does not exist yet and cannot be inspected at the moment they approve it.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Authority granted wider than it is used.&lt;/strong&gt; We routinely grant more scope than a task strictly needs, and it has been safe to do so, because compiled software only ever reaches for what its code asks for. An adaptive client such as an AI agent removes that gap. Given enough steps toward a goal it will eventually attempt everything the grant permits.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;No way to tell a human apart from software on the wire.&lt;/strong&gt; Every control calibrated to human behavior assumes a human. Rate limits, step-up prompts, session timeouts, anomaly thresholds etc. were all tuned against a person’s speed and a person’s error rate. A request from an agent carries nothing that says it came from software.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Recourse assumes a party who can be bound.&lt;/strong&gt; Beneath every technical control sits a legal one. Terms of service, contracts, jurisdiction, and the simple fact that a gym enthusiast who cancels someone else’s booking has breached an agreement and can be banned for it. That layer works because it addresses a party with intent, who can be identified and held to an obligation. An agent has neither intent nor legal standing, so the entire fallback that has quietly absorbed the residual risk in every system we build does not apply.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;you-cannot-prevent-control-or-hold-anyone-accountable-for-something-you-cannot-see&quot;&gt;You cannot prevent, control, or hold anyone accountable for something you cannot see&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/5.DkU36gz5_Z13ABai.webp&quot; alt=&quot;Intent mismatch between the human and AI agent&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 2698px) 2698px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;2698&quot; height=&quot;976&quot;&gt;&lt;/p&gt;
&lt;p&gt;Every one of those five has a known fix, and none of them is hard to describe. But look at what each fix needs before it can work. To prevent something, you have to be able to say what you are preventing. To control it while it runs, you have to be able to point at it. To hold anyone accountable afterward, you have to be able to name who did it.&lt;/p&gt;
&lt;p&gt;All three need the same answer first, and it’s the one answer nobody in that system had. No part of the gym’s system knew an agent was involved, as far as every layer of it could tell, a gym enthusiast booked a class and then a gym enthusiast canceled a reservation. That is the real problem here, not the five items above, and fixing them one at a time will keep leaving the same hole open.&lt;/p&gt;
&lt;h2 id=&quot;how-agents-actually-get-their-access-today&quot;&gt;How agents actually get their access today&lt;/h2&gt;
&lt;p&gt;There are three shapes in production right now, and two of them are the problem.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Agents with no identity at all.&lt;/strong&gt; A conversational agent that reads public pages and answers questions holds nobody’s credentials and reaches nothing that needed permission. There is no identity here and there does not need to be one, whatever these agents get wrong they get wrong in text.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Agents holding your token.&lt;/strong&gt; The user runs a normal OAuth2/OIDC flow, approves a consent screen, and a token comes back. That token carries &lt;code&gt;sub&lt;/code&gt;, and &lt;code&gt;sub&lt;/code&gt; is the user. It also carries &lt;code&gt;client_id&lt;/code&gt;, which is where people usually point when raising this, and &lt;code&gt;client_id&lt;/code&gt; identifies the application that was registered, not the instance now holding the token. In other words it is a public identifier, assigned once at registration, shared by every deployment of that software, and unchanged when the model, the prompt, or the tool set underneath it changes. It answers which product, and the question we need answered is which actor.&lt;/p&gt;
&lt;p&gt;Now here is the part I find genuinely frustrating. This shape has a name and a specification, and both are six years old. &lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc8693&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;OAuth 2.0 Token Exchange
&lt;/a&gt; devotes its Section 1.1 to “Delegation vs. Impersonation Semantics”, and the distinction it draws is exactly ours.&lt;/p&gt;
&lt;p&gt;Impersonation means the token presents one party only, and no downstream system can tell that anybody acted on someone else’s behalf. Delegation means the token keeps both (the subject and the actor) and every system that sees it knows there were two. The spec defined a new  field -  the &lt;code&gt;act&lt;/code&gt; claim, in its own words, “to express that delegation has occurred and identify the acting party to whom authority has been delegated”, and it nests, so a chain of actors stays visible across hops.&lt;/p&gt;
&lt;p&gt;So why is &lt;code&gt;act&lt;/code&gt; missing from nearly every agent deployment shipping today? Look at what goes inside it. A token from that consent flow actually carries the following.&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light nord&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#d8dee9ff;--shiki-light-bg:#fff;--shiki-dark-bg:#2e3440ff;overflow-x:auto;white-space:pre-wrap;word-wrap:break-word&quot; tabindex=&quot;0&quot; data-language=&quot;json&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;  &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;sub&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;user@example.com&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;  &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;client_id&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;openclaw-desktop&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;  &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;scope&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;booking:write booking:cancel&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And the same grant expressed as delegation, the way OAuth 2.0 Token Exchange has allowed, is as follows.&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light nord&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#d8dee9ff;--shiki-light-bg:#fff;--shiki-dark-bg:#2e3440ff;overflow-x:auto;white-space:pre-wrap;word-wrap:break-word&quot; tabindex=&quot;0&quot; data-language=&quot;json&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;  &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;sub&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;user@example.com&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;  &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;act&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;sub&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;???&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt; },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;  &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;scope&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;booking:write booking:cancel&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code&gt;act&lt;/code&gt; claim is an object carrying a &lt;code&gt;sub&lt;/code&gt; of its own, the actor’s subject. To populate it you need an identity for the agent, and there isn’t one. The field has been sitting there since January 2020, correctly designed, waiting for a value that does not exist. We ship impersonation not because delegation was unavailable, but because delegation needs a second party to name, and we never created one.&lt;/p&gt;
&lt;p&gt;And it gets worse the moment there is more than one agent. As an example, a typical setup now has an orchestrator that decomposes a task and calls sub-agents, MCP servers, and APIs to carry the pieces out. Holding a bearer token, that orchestrator has exactly one thing it can pass downward (the whole token). So a sub-agent whose only job is to fetch a document arrives at your resource server carrying the same authority as the orchestrator that called it, and your resource server has no way to tell it was the second hop rather than the first.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/2.DVYq9WhH_Z1168AT.webp&quot; alt=&quot;Token without actclaim can&apos;t be used to identify the agent &quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1710px) 1710px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1710&quot; height=&quot;919&quot;&gt;&lt;/p&gt;
&lt;p&gt;OAuth 2.0 Token Exchange designed for this too. The &lt;code&gt;act&lt;/code&gt; claim nests, the outermost actor is the most recent one, and each exchange can narrow the scope on the way down, so a chain stays both visible and attenuating. It fails here for exactly the same reason as the single-hop case, every nested &lt;code&gt;act&lt;/code&gt; needs a &lt;code&gt;sub&lt;/code&gt;, every hop needs an actor to name, and we have not created one at any layer.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Agents driving your logged-in session.&lt;/strong&gt; Then there is the browser case, which according to my point of view is the most dangerous of the three, because it does not get as far as a token.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/3.rj3y1-k-_ZmLIuL.webp&quot; alt=&quot;How browser-based agents work&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1790px) 1790px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1790&quot; height=&quot;879&quot;&gt;&lt;/p&gt;
&lt;p&gt;As we discussed in &lt;a href=&quot;https://sagarag.dev/posts/browser-based-agents-identity-problem&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;an earlier post&lt;/a&gt;, a browser-based agent waits for you to log in yourself and then drives the interface you left open. No registration, no consent screen, no token, and nothing anywhere that says software is at the controls.&lt;/p&gt;
&lt;p&gt;One important point to highlight here is why that matters more than it first appears. Zero trust tells us to verify every request and trust nothing, but in practice that is far from the reality. An employee has a contract. A customer has accepted terms of service. Both sit inside a jurisdiction, both can be identified, and both can be fired, banned, or sued. That residual trust is what lets us tolerate a session broader than any single task strictly requires.&lt;/p&gt;
&lt;p&gt;An agent inherits the session, and inherits all of that tolerance, and not one of the things that made the tolerance safe applies to it. It has no contract, no employment, no jurisdiction, and no social cost. The gym enthusiast had every reason not to cancel a stranger’s reservation, and it never occurred to him to try. The agent was simply relentless about the goal it was given, and the session could not tell the two apart.&lt;/p&gt;
&lt;h2 id=&quot;the-real-cost-of-borrowed-identity&quot;&gt;The real cost of borrowed identity&lt;/h2&gt;
&lt;p&gt;Now assume none of the above is broken. Your authorization is correct, your tracing is complete, your audit log has no gaps, and your detection rules are well tuned. Every one of them still fails, and for the same reason.&lt;/p&gt;
&lt;p&gt;Detection profiles the party the token named, so an agent operating inside a user’s permissions looks like that user having a busy afternoon. There is nothing anomalous to find, because from the rule’s point of view nothing anomalous happened.&lt;/p&gt;
&lt;p&gt;Tracing captures whatever it is told to capture. Even with perfect instrumentation you get a complete, faithful, high-fidelity record of the wrong actor. Observability is a fidelity problem (are we capturing enough) and this is not that, this is a semantics problem (does what we captured mean what we think it means) and more spans will not fix a wrong subject.&lt;/p&gt;
&lt;p&gt;Auditing is worse than either, because it looks fine. A log with a gap raises a question, a log with the wrong name closes one. And non-repudiation, the single property that makes an audit log worth keeping, is gone the moment a credential is shared, because the named party can now credibly deny anything, and so can everybody else in the same position.&lt;/p&gt;
&lt;p&gt;Then follow that where it goes. When this is normal rather than novel, the party your systems name will be an ordinary person who asked for a gym class, or a meeting room, or a refund. Someone who has never heard the word “hacking” used seriously will be the recorded actor on an unauthorized cancellation, a deleted record, a bypassed control. Your logs will be complete, your process will run correctly, and it will arrive at them. Naming them fixes nothing, because they could not have seen it coming and cannot stop it happening again.&lt;/p&gt;
&lt;h2 id=&quot;agents-need-an-identity-not-an-identifier&quot;&gt;Agents need an identity, not an identifier&lt;/h2&gt;
&lt;p&gt;Let’s be blunt about what we have been looking at. A reservation destroyed without authorization. Four accounts breached across four third-party services. Three organizations compromised. A malicious package published and executed on fifteen real machines. All of that inside three weeks, and all of it real. There was no attacker in a single one of them, and every one of them was an attack.&lt;/p&gt;
&lt;p&gt;So look at what we have standing against that, because it is not nothing. Authentication, authorization, least privilege, consent, rate limiting, anomaly detection, audit logging, incident response, and a legal layer sitting underneath all of it. Decades of work. It is a mature stack and it is not naive.&lt;/p&gt;
&lt;p&gt;And almost every part of it goes incompetent against this class of attack, for one reason. Not because any control is weak, but because every one of them resolves to a party, and the party they resolve to is not the one acting.&lt;/p&gt;
&lt;p&gt;That is why I keep calling this an identity problem rather than a security controls problem. An agent needs an identity of its own, and I mean identity in the sense our field has always meant it, not an identifier. It should be able to prove who it is, uniquely and verifiably, rather than assert a string that anyone could assert. It should have a profile (which model, which version, which tools, which operator). It should have a lifecycle, issued and rotated and suspended and revoked and retired, on its own schedule rather than on some employee’s. And it should hold entitlements of its own, that you can grant, narrow, and withdraw without touching the person it works for.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/4.D_iE3j7n_ZxrXyB.webp&quot; alt=&quot;Agents need an identity, not an identifier&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1824px) 1824px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1824&quot; height=&quot;862&quot;&gt;&lt;/p&gt;
&lt;p&gt;An identifier gives you none of those four, and that distinction deserves its own post, so I’ll come back to it properly in a separate post.&lt;/p&gt;
&lt;p&gt;So here is what you can do this week instead, and it costs nothing. Take one system your agents touch, pull the last thirty days of audit logs, and try to answer one question. When an agent acted, can you tell?&lt;/p&gt;</content:encoded><dc:creator>Sagara Gunathunga</dc:creator><category>Agent Identity</category><category>API Security</category><category>Delegation</category></item><item><title>Browser-Based Agents Are Impersonating You: The Agent Identity Problem</title><link>https://sagarag.dev/posts/browser-based-agents-identity-problem</link><guid isPermaLink="true">https://sagarag.dev/posts/browser-based-agents-identity-problem</guid><description>Browser-based agents inherit your session, your cookies,  and your identity, with no distinction visible to the service provider.  Here&apos;s why that&apos;s a problem we&apos;ve already solved once, and what needs to happen next.</description><pubDate>Sat, 02 May 2026 10:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/9.BpKKIKTY_Z1epiXI.webp&quot; alt=&quot;browser-based-agents-identity-problem&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1774px) 1774px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1774&quot; height=&quot;887&quot;&gt;&lt;/p&gt;
&lt;p&gt;Imagine telling an AI: &lt;em&gt;Review my active subscriptions and cancel the ones I’m not using.&lt;/em&gt; A browser-based agent can now
do exactly that: access your email, identify monthly subscriptions, extract billing amounts and due dates, and, if you decide
to cancel, navigate the provider’s app and complete it on your behalf. &lt;em&gt;&lt;strong&gt;No integrations, no APIs, no special setup. Just your
browser.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;This is a significant shift from how most people have consumed AI capabilities. Conversational agents like ChatGPT were mostly limited
to generating text. Coding agents like GitHub Copilot operate within specific domains and assist with well-defined tasks rather than
end-to-end workflows. Browser-based agents are starting to break that boundary. They move beyond conversation and into execution,
making decisions, navigating interfaces, and completing workflows the same way a human would.&lt;/p&gt;
&lt;p&gt;But before treating this as a silver bullet, it’s worth looking at what’s actually happening under the hood. These agents act with
your level of access. They operate across systems, make decisions, and execute actions on your behalf. That raises a few critical
questions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;What exactly can the agent access, and under whose identity?&lt;/li&gt;
&lt;li&gt;Where do the trust boundaries sit?&lt;/li&gt;
&lt;li&gt;Who is accountable for the actions taken, you or the agent?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The answers will determine whether browser-based agents become a practical productivity layer or a security liability.&lt;/p&gt;
&lt;h2 id=&quot;how-do-they-actually-work&quot;&gt;How do they actually work?&lt;/h2&gt;
&lt;p&gt;Browser-based agents typically fall into two categories: native AI browsers and browser extensions or side panels. Regardless of how
they are built, under the hood they perform the same set of activities.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/1.C36EPaKI_Z1hjs6v.webp&quot; alt=&quot;Native AI browsers like OpenAI Atlas and Perplexity Comet compared with extension and side-panel agents
like Claude for Chrome&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 2051px) 2051px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;2051&quot; height=&quot;767&quot;&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Native AI browsers&lt;/strong&gt;, such as &lt;a href=&quot;https://chatgpt.com/atlas/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;OpenAI Atlas&lt;/a&gt; and &lt;a href=&quot;https://www.perplexity.ai/comet&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Perplexity Comet&lt;/a&gt;,
have agentic capabilities built directly into the browser. These browsers were born in the agentic AI era.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Browser extensions and side panels&lt;/strong&gt; are agents built on top of existing browsers using extension points or side panel APIs. &lt;a href=&quot;https://claude.com/claude-for-chrome&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Claude
for Chrome&lt;/a&gt; is a good example, delivered as a Chrome extension.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The easiest way to understand this is to look at the runtime interactions between the components when executing a task like the
subscription review we discussed earlier.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/2.lTtH0VPs_28S7k1.webp&quot; alt=&quot;Runtime flow of a browser-based agent: the Cowork orchestrator delegating browser tasks to Claude for Chrome&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 2170px) 2170px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;2170&quot; height=&quot;725&quot;&gt;&lt;/p&gt;
&lt;p&gt;It starts with you, the user, providing a prompt to Cowork, which can be available in the Claude Desktop application,
for example: &lt;em&gt;Review my active subscriptions….&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;At this point, Cowork takes the lead as the orchestrator agent. It consults the LLM to interpret your intent and, instead of just
guessing, builds a structured plan. This plan is a structured sequence of actions, such as &lt;em&gt;List emails from the last 30 days&lt;/em&gt;,
&lt;em&gt;Identify billing domains&lt;/em&gt;, and &lt;em&gt;Check account status for each.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Execution of this plan involves delegation. Cowork, as the orchestrator agent, assigns tasks that involve browser interactions to the
browser agent (in this case, Claude running in Chrome). The browser agent is responsible for every interaction inside the browser:
navigating to URLs, reading page content, clicking elements like menus and buttons, filling and submitting forms, and interacting with
web applications.&lt;/p&gt;
&lt;p&gt;One important point to keep in mind: at the start of a task, the browser agent directs you to the relevant application and pauses for
you to log in with your own credentials, just as you normally would. Once authenticated, the agent inherits that session to carry out
its delegated tasks.&lt;/p&gt;
&lt;p&gt;As each step is completed, the browser agent reports the raw data back to Cowork. The orchestrator then iterates. It analyzes the
data, refines the next steps in the plan, or issues new instructions back to the browser. Only once the entire multi-step plan is fully
executed does Cowork synthesize the results and return the final outcome to you.&lt;/p&gt;
&lt;p&gt;The most fascinating aspect of a browser agent is its ability to perform just like us, navigating to URLs, reading content, filling
forms, and interacting with any web application, without any additional tools or credentials. And that is exactly where we need to
focus. Now, let’s break down how this actually works under the hood, because the way a browser agent perceives and acts on a web page
is more fascinating than it might seem. A browser agent gains these abilities by carrying out a &lt;strong&gt;perception-action loop&lt;/strong&gt;, which breaks
down into four distinct phases:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Perception&lt;/li&gt;
&lt;li&gt;Reasoning&lt;/li&gt;
&lt;li&gt;Act&lt;/li&gt;
&lt;li&gt;Feedback&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/3.CuugfN8e_1b8GDc.webp&quot; alt=&quot;The four-phase perception-action loop of a browser agent: perception, reasoning, act, and feedback&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1779px) 1779px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1779&quot; height=&quot;884&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;perception&quot;&gt;Perception&lt;/h3&gt;
&lt;p&gt;Just like a human would use eyes and ears as sensors, a browser agent needs sensors of its own to understand a web application. In the
case of browser-based agents, that perception comes in two forms.&lt;/p&gt;
&lt;p&gt;The first is &lt;strong&gt;structural perception&lt;/strong&gt;. Here, the agent perceives a page by parsing the Document Object Model (DOM), which includes labels,
buttons, inputs, links, and their attributes. However, raw HTML is often cluttered with tracking scripts, hidden divs, and metadata that
are irrelevant to the task. To filter this noise, agents often generate an accessibility tree, a simplified version of the DOM designed
for assistive technologies such as screen readers. It focuses on:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Role:&lt;/strong&gt; Is this a button, a link, or an input field?&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Name:&lt;/strong&gt; What text is associated with this element?&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;State:&lt;/strong&gt; Is this checkbox checked? Is this button disabled?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Additionally, for text-heavy pages, the agent might extract the raw text content separately.&lt;/p&gt;
&lt;p&gt;The second method is much closer to how humans work, and is called &lt;strong&gt;visual perception&lt;/strong&gt; or &lt;strong&gt;visual grounding&lt;/strong&gt;, where the agent takes
actual screenshots. It uses computer vision to identify where a button physically sits on the screen, which is critical for modern,
JavaScript-heavy sites where the HTML doesn’t always match the visual layout. Using this method, it performs state extraction, the process
of identifying interactive elements: &lt;em&gt;There is a ‘Cancel’ button at coordinate (x, y) and an input field labeled ‘Reason’ next to it.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/4.BtZrqYLd_Z2dbziY.webp&quot; alt=&quot;Structural perception via the DOM and accessibility tree versus visual perception via screenshots&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1825px) 1825px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1825&quot; height=&quot;862&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;reasoning&quot;&gt;Reasoning&lt;/h3&gt;
&lt;p&gt;Once the agent perceives the page, it enters the reasoning phase. This is where raw input is turned into decisions. Think of it as the
agent’s internal logic controller.&lt;/p&gt;
&lt;p&gt;The first step is &lt;strong&gt;task decomposition&lt;/strong&gt;. A high-level goal like &lt;em&gt;Audit user login frequency and session duration&lt;/em&gt; is broken down into smaller,
actionable steps: navigate to the admin or security dashboard, locate activity logs, and identify timestamps for session start and end events.&lt;/p&gt;
&lt;p&gt;This process is driven by &lt;strong&gt;chain-of-thought (CoT) reasoning&lt;/strong&gt;. The agent works through intermediate steps internally to decide what to do next.
For example: “I am on the dashboard. I see a ‘Security’ tab. I need to click it to find audit logs.” Each action is based on the current state of
the interface.&lt;/p&gt;
&lt;p&gt;At the same time, the agent performs &lt;strong&gt;constraint checking&lt;/strong&gt; to reduce errors. It does not blindly extract data. Instead, it evaluates what it sees
against the intended task. If it encounters a column labeled &lt;em&gt;Last Password Change&lt;/em&gt; instead of &lt;em&gt;Session Start&lt;/em&gt;, it recognizes the mismatch and continues
searching for the correct data.&lt;/p&gt;
&lt;p&gt;This ability to reason and self-correct is what separates an autonomous agent from a brittle, hard-coded scraper.&lt;/p&gt;
&lt;h3 id=&quot;act&quot;&gt;Act&lt;/h3&gt;
&lt;p&gt;Reasoning is not useful unless it translates into real browser actions. This is the act phase, where the agent moves from internal logic to execution.&lt;/p&gt;
&lt;p&gt;At this stage, the agent interacts with a browser automation engine such as Playwright or Puppeteer for Chromium. It triggers concrete actions (clicks,
typing, and hovers) on specific DOM elements or screen coordinates identified during the perception phase.&lt;/p&gt;
&lt;p&gt;The agent also manages navigation. It can move across pages, follow links, issue direct URL navigations, or refresh the page when the state
becomes inconsistent.&lt;/p&gt;
&lt;p&gt;To operate reliably in real environments, agents need to behave less like scripts and more like users. This is where &lt;strong&gt;human mimicry&lt;/strong&gt; comes in.
The agent introduces realistic delays and non-linear mouse movements instead of executing actions at machine speed.&lt;/p&gt;
&lt;p&gt;This is not just an optimization. Without it, agents are easily flagged by anti-bot systems. A fast, deterministic script
gets blocked. An agent that behaves like a user is far more likely to complete the task.&lt;/p&gt;
&lt;h3 id=&quot;feedback&quot;&gt;Feedback&lt;/h3&gt;
&lt;p&gt;The final stage is feedback, where the agent pauses to evaluate the outcome of its actions. It starts with &lt;strong&gt;observation&lt;/strong&gt;. The agent inspects
the updated browser state: did a confirmation modal appear after a click, or did the page refresh without making progress? This step determines
whether the previous action actually achieved its intended result.&lt;/p&gt;
&lt;p&gt;That feeds directly into &lt;strong&gt;error handling&lt;/strong&gt;. If the agent encounters signals like &lt;em&gt;Access Denied&lt;/em&gt; or &lt;em&gt;Data Not Found&lt;/em&gt;, it doesn’t fail immediately.
The reasoning loop picks this up in the next cycle and adjusts the plan by retrying, taking an alternative path, or skipping a step.&lt;/p&gt;
&lt;p&gt;The loop concludes with &lt;strong&gt;self-reflection&lt;/strong&gt;. The agent compares the current state with the intended goal. If the goal is met, the task ends.
If not, the agent continues by starting a new cycle with fresh perception of the updated UI. This continuous loop of observe, adjust,
and retry is what makes the system resilient rather than brittle.&lt;/p&gt;
&lt;p&gt;But here’s the catch: the same loop that makes these agents powerful also introduces real security and identity implications that
aren’t obvious until you look closely.&lt;/p&gt;
&lt;h2 id=&quot;echoes-of-the-pre-oauth2-era&quot;&gt;Echoes of the pre-OAuth2 era&lt;/h2&gt;
&lt;p&gt;It starts at the perception phase. The browser agent asks you to log in to a web application using your own credentials.
It doesn’t request or store those credentials. Instead, it relies on you to authenticate as usual and then takes over the session.&lt;/p&gt;
&lt;p&gt;From that point on, the agent operates within your authenticated session. Access is technically limited to that session,
but in reality, many applications maintain long-lived sessions, which extends the agent’s effective access window.&lt;/p&gt;
&lt;p&gt;This starts to look familiar.&lt;/p&gt;
&lt;p&gt;Before OAuth 2.0, third-party applications often asked users to share credentials directly. While the mechanics here are
different (the agent never accesses or stores your password), the underlying implication is similar: impersonation.
Another entity is now acting on your behalf, and the party that provides the service to you cannot distinguish between you and the agent.&lt;/p&gt;
&lt;p&gt;That is exactly the class of problem OAuth 2.0 (&lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc6749&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;RFC 6749&lt;/a&gt;) set out to solve.
OAuth 2.0 introduced two key safeguards.&lt;/p&gt;
&lt;p&gt;First, users no longer share credentials with third-party applications. Instead, those applications receive scoped,
short-lived access tokens based on explicit user consent. Users also retain control: they can limit access via scopes
and revoke tokens at any time.&lt;/p&gt;
&lt;p&gt;Second, it relies on the concept of client identity (&lt;code&gt;client_id&lt;/code&gt;). This allows the service-providing party to
distinguish between direct user access and access performed by an external application acting on behalf of the user (the client).&lt;/p&gt;
&lt;p&gt;Going back to browser-based agents.&lt;/p&gt;
&lt;p&gt;Today, these agents effectively operate by inheriting your identity. &lt;strong&gt;Because the browser-based agent unconditionally inherits
your browser session, it can access your cookies, auth tokens, SSO state, and your roles and permissions. From the perspective
of the service provider, every action appears as if it is performed by you. There is no distinction, no explicit delegation,
and no visibility into the fact that an agent is involved.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;None of this is hypothetical. Prompt injection attacks already demonstrate how handing over active sessions to
agents can lead to unintended and potentially dangerous actions. Anthropic’s own testing of
Claude in Chrome &lt;a href=&quot;https://support.claude.com/en/articles/12902428-using-claude-in-chrome-safely&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;documents exactly this&lt;/a&gt;:
scenarios where the agent could be manipulated into extracting and sharing sensitive information or deleting important files.&lt;/p&gt;
&lt;p&gt;A decade ago, we were cautious about letting third-party software impersonate users, and about sharing one app’s password
with relatively simple systems. But today we are handing our sessions to multiple apps, and to autonomous agents that can
reason, adapt, and act non-deterministically, and that send screenshots to third-party cloud services.&lt;/p&gt;
&lt;p&gt;Ideally, we should be able to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Maintain a separate audit trail for actions carried out by agents.&lt;/li&gt;
&lt;li&gt;Set a scoped permission set for an agent that is a subset of your permissions (e.g., the agent can read but not write).&lt;/li&gt;
&lt;li&gt;Limit the agent’s session time separately from the user session (e.g., the agent can access for 10 minutes).&lt;/li&gt;
&lt;li&gt;Revoke an agent’s access independently.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;But without the notion of a unique identity for agents, none of the above is feasible&lt;/strong&gt;. And that is the real issue: we have
already solved this class of identity problem once, just not in this new context.&lt;/p&gt;
&lt;h2 id=&quot;remember-screen-scraping&quot;&gt;Remember screen scraping?&lt;/h2&gt;
&lt;p&gt;Those who used VNC and Citrix a couple of decades ago, streaming pixel buffers to give a remote human operator
visual access to a machine, might find a lot of similarities to how browser-based agents perform visual perception today.
The mechanism has changed, but the underlying model has not: an entity other than you is watching your screen and acting on what it sees.&lt;/p&gt;
&lt;p&gt;Browser agents perform visual perception by taking event-driven screenshots of the browser window and uploading them as base64 images
to the LLM, which is, in most cases, a cloud service. The reasoning process that follows, analyzing page content, accessibility trees,
screenshots, and the full conversation history, all happens remotely. In other words, your browser windows are being streamed to a
third-party server to be interpreted.&lt;/p&gt;
&lt;p&gt;The first time this really hit me was when I tried out a Claude skill that needed access to a couple of cloud services. After logging
in, I watched the agent navigate the interfaces, and that’s when it clicked: the screenshots of my browser windows were being sent
to a remote server to be reasoned about.&lt;/p&gt;
&lt;p&gt;You can opt out of having your data used for training, but once that data leaves your browser, you are no longer in control. A data breach
at the server used to temporarily store these images carries serious implications. The page data can contain session tokens, cookies,
and other internal application state. Ideally, screenshots and page content should never leave your local environment. Beyond that
boundary, you are entirely dependent on your AI provider’s policies and safeguard mechanisms.&lt;/p&gt;
&lt;h2 id=&quot;access-control-full-browser-api-no-identity-boundaries&quot;&gt;Access control: full browser API, no identity boundaries&lt;/h2&gt;
&lt;p&gt;To dig further into the act phase, browser-based agents fundamentally use a combination of two approaches.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Visual coordinate-based:&lt;/strong&gt; the agent clicks by pixel coordinates based on visual perception achieved using screenshots.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Structural DOM-based:&lt;/strong&gt; the agent clicks by element references based on the accessibility tree built using structural perception.&lt;/p&gt;
&lt;p&gt;When an agent decides to act, it reaches for a browser automation API like the Chrome
&lt;a href=&quot;https://chromedevtools.github.io/devtools-protocol/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;DevTools Protocol (CDP)&lt;/a&gt;, a low-level protocol
built into &lt;a href=&quot;https://www.chromium.org/chromium-projects/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Chromium&lt;/a&gt; that &lt;a href=&quot;https://playwright.dev/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Playwright&lt;/a&gt;
and &lt;a href=&quot;https://pptr.dev/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Puppeteer&lt;/a&gt; also rely on. Look at what CDP alone exposes: navigating to URLs, clicking elements,
typing text, executing arbitrary JavaScript, reading the DOM, capturing screenshots, intercepting network calls, and reaching into
logs, cookies, and storage. That is effectively the entire browser. Now notice what is not on that list: any notion of &lt;em&gt;who&lt;/em&gt; is wielding it.&lt;/p&gt;
&lt;p&gt;The &lt;a href=&quot;https://developer.chrome.com/docs/extensions/reference/api&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Chrome Extension API&lt;/a&gt; is similar, and is used when the browser
agent is developed as a browser extension. There are other methods like JavaScript injection and simulated input events, but the
bottom line is the same: browser-based agents gain full access to the page context, network, and storage.&lt;/p&gt;
&lt;p&gt;Unlike deterministic browser extensions, which are quite simple, performing one task and shipping to the extension stores via a
review process, an autonomous, non-deterministic agent with full control over the browser API is obviously too much risk to take.&lt;/p&gt;
&lt;h2 id=&quot;guardrails-improve-browser-based-agent-security-but-dont-fix-the-identity-gap&quot;&gt;Guardrails improve browser-based agent security, but don’t fix the identity gap&lt;/h2&gt;
&lt;p&gt;Like any other agent, browser-based agents have multiple layers of guardrails in place; they don’t have full freedom to do whatever they want.&lt;/p&gt;
&lt;p&gt;First, there are &lt;strong&gt;category restrictions&lt;/strong&gt;, such as domain-level controls that decide whether the agent can access a specific domain. For
instance, in the case of Claude, financial, adult, and crypto sites are not allowed,
the &lt;a href=&quot;https://support.claude.com/en/articles/12902428-using-claude-in-chrome-safely&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;full blocklist&lt;/a&gt; also covers
investment and trading platforms and known pirated-content sites.&lt;/p&gt;
&lt;p&gt;Then there are guardrails to defend against &lt;strong&gt;prompt injection attacks&lt;/strong&gt;. For instance, the content isolation rule makes sure the agent
follows instructions coming from the user via the chat and ignores any instructions found in the page content. Other approaches, like
a classifier model, flag suspicious patterns in page content before they reach the LLM.&lt;/p&gt;
&lt;p&gt;Then there are &lt;strong&gt;action permission gates&lt;/strong&gt;, where the user can define what actions can be performed and when, based on action type.
For instance, the agent always asks the user explicitly whenever it tries to purchase or delete something.&lt;/p&gt;
&lt;p&gt;Most importantly, the agent performs an &lt;strong&gt;irreversibility check&lt;/strong&gt;. If an action is irreversible, the agent has to stop execution and
get explicit confirmation before proceeding.&lt;/p&gt;
&lt;p&gt;These guardrails do an excellent job: preventing obvious runaway behaviors, giving the user visibility and control, protecting
against prompt injection, and adding safeguards around high-risk activities. But they are not able to address the identity,
access control, and security implications of visual grounding via screenshots. &lt;strong&gt;So guardrails are absolutely required, but they
are not adequate.&lt;/strong&gt;&lt;/p&gt;
&lt;h2 id=&quot;what-about-mcp&quot;&gt;What about MCP?&lt;/h2&gt;
&lt;p&gt;If we go to first principles and ask why browser agents use structural and visual perception, it’s because there is no universally
common API exposed by all web applications. On the other hand, web pages rendered as HTML are universally common for any human to access.
So for now, agents like Claude Cowork are restricted to using the interface that the web application exposes for humans, and have to
implement complex processes like building accessibility trees and visual grounding. There are RESTful and other types of APIs exposed
by web applications, but there is no common standard among them, so it’s not practical for AI agents to build proprietary integrations
for every API imaginable.&lt;/p&gt;
&lt;p&gt;Isn’t MCP designed for this problem? That’s exactly what it’s designed to do. &lt;strong&gt;The design goal of MCP is to provide a universal
integration protocol that bridges LLM-based applications such as AI agents with real-world data and services.&lt;/strong&gt; MCP promises to
eliminate the need for an AI agent to adopt web interfaces designed for humans. Instead, agents can learn the available
capabilities and resources, then retrieve resources and consume capabilities via the MCP interface.&lt;/p&gt;
&lt;p&gt;This drastically reduces today’s complexity and solves most of the security implications. Users no longer need to share their sessions.
Instead, the same OAuth 2.0-based short-lived tokens we’ve been using with web APIs apply here too, and OAuth 2.0 scopes, along
with other access control policies, can control the level of access.&lt;/p&gt;
&lt;p&gt;The &lt;a href=&quot;https://modelcontextprotocol.io/specification/draft/basic/authorization&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;MCP authorization spec&lt;/a&gt; is also mature enough now compared
to last year, and has gradually stabilized.&lt;/p&gt;
&lt;p&gt;So why did Anthropic develop Claude in Chrome when MCP, which also originated at Anthropic, is designed for exactly this problem?
This is not because MCP is a bad technology. Rather, MCP is not yet widely deployed in production, and with ongoing AI competition,
Anthropic can’t wait for MCP to find momentum. They are forced to find a solution that works with current mainstream technology.&lt;/p&gt;
&lt;p&gt;One reason organizations hold back from production-grade MCP servers is simple: it’s another system to build and own.
Like any API, an MCP server has to be designed, governed, secured, and run on real infrastructure.&lt;/p&gt;
&lt;p&gt;For teams that already have mature REST or GraphQL APIs, the cost is incremental. They can add an MCP gateway and reuse
the OAuth 2.0 identity infrastructure they already run. But for most small organizations, especially end-user-facing ones,
a web application with pages is already enough. Asking them to stand up and maintain a parallel system just to serve agents
is a hard sell.&lt;/p&gt;
&lt;p&gt;Although it would be a good idea to have two different interfaces for humans and machines, that shouldn’t require building
and maintaining two parallel systems. We need a better solution. On top of that, the MCP development workflow is, as of now,
distant from some web application developers and their workflows.&lt;/p&gt;
&lt;p&gt;This is exactly where WebMCP gets interesting, by making MCP more accessible for web developers and making it much more
affordable and maintainable to provide MCP server capabilities alongside the human-oriented web interface.&lt;/p&gt;
&lt;h2 id=&quot;webmcp-purpose-built-agent-interfaces-for-the-web&quot;&gt;WebMCP: purpose-built agent interfaces for the web&lt;/h2&gt;
&lt;p&gt;If the main goal of MCP is to provide universal pluggability for LLM-based applications, the proposed
&lt;a href=&quot;https://webmachinelearning.github.io/webmcp/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;WebMCP&lt;/a&gt; tries to make it part of a standard browser API,
much more approachable for web application developers, and, most importantly, available via a standard
browser context for browser-based agents.&lt;/p&gt;
&lt;p&gt;With &lt;a href=&quot;https://webmachinelearning.github.io/webmcp/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;WebMCP&lt;/a&gt;, a web developer can define a set of MCP tool declarations
for the current page by calling the &lt;code&gt;modelContext.registerTool()&lt;/code&gt; method in JavaScript. This method accepts metadata
describing the underlying tool, along with a callback function that is executed when the tool is invoked.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/5.BWvDCjqi_1K19fm.webp&quot; alt=&quot;WebMCP registering MCP tools on a web page using modelContext.registerTool&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 2017px) 2017px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;2017&quot; height=&quot;780&quot;&gt;&lt;/p&gt;
&lt;p&gt;As shown in the example below, this is a straightforward addition for most web developers.&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light nord&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#d8dee9ff;--shiki-light-bg:#fff;--shiki-dark-bg:#2e3440ff;overflow-x:auto;white-space:pre-wrap;word-wrap:break-word&quot; tabindex=&quot;0&quot; data-language=&quot;js&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#81A1C1&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#D8DEE9&quot;&gt; weatherTool&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#81A1C1&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#D8DEE9&quot;&gt; navigator&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#D8DEE9&quot;&gt;modelContext&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;--shiki-light:#6F42C1;--shiki-dark:#88C0D0&quot;&gt;registerTool&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#D8DEE9FF&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#88C0D0&quot;&gt;  name&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;weather&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#88C0D0&quot;&gt;  description&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;Get weather information for a location&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#88C0D0&quot;&gt;  inputSchema&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#88C0D0&quot;&gt; type&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;object&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#88C0D0&quot;&gt; properties&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#88C0D0&quot;&gt; location&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#88C0D0&quot;&gt; type&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt; }&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt; }&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt; },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#81A1C1&quot;&gt;  async&lt;/span&gt;&lt;span style=&quot;--shiki-light:#6F42C1;--shiki-dark:#88C0D0&quot;&gt; execute&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;({&lt;/span&gt;&lt;span style=&quot;--shiki-light:#E36209;--shiki-dark:#D8DEE9&quot;&gt; location&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt; })&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#81A1C1&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#88C0D0&quot;&gt;      content&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#D8DEE9FF&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#88C0D0&quot;&gt; type&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;text&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#88C0D0&quot;&gt; text&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; `&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;Weather for &lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#81A1C1&quot;&gt;${&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#D8DEE9&quot;&gt;location&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#81A1C1&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#81A1C1&quot;&gt;${&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#D8DEE9&quot;&gt;weather&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#81A1C1&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt; }]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;    };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;});&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When a browser navigates to a web page that includes WebMCP declarations, it automatically registers
these tools within a higher-level browser context (e.g., the tab context). A browser-based agent can
then discover and invoke these MCP tools through that context, similar to standard MCP tool invocation,
which in turn executes the associated JavaScript callback functions.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/6.TgpjtQW4_2cN5aI.webp&quot; alt=&quot;A browser agent discovering and invoking WebMCP tools through the browser tab context&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1985px) 1985px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1985&quot; height=&quot;792&quot;&gt;&lt;/p&gt;
&lt;p&gt;These callback functions can run on the main thread or be delegated to a worker. They may return results
synchronously or return a Promise that resolves asynchronously. In relation to our discussion, WebMCP solves several problems:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Clean, agent-specific interfaces.&lt;/strong&gt; WebMCP lets developers define a clear, purpose-built interface for agents that is
separate from the human-facing UI. Using familiar JavaScript, developers expose functionality through tool declarations
and callbacks directly within the same web page. This gives developers full control over what capabilities and resources
are exposed to agents, how they are exposed, what inputs are expected, and what outputs are returned, all in a concise,
well-defined interface. It reinforces a design principle of separating interfaces for humans and agents.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Eliminating reliance on DOM interpretation.&lt;/strong&gt; Browser-based agents no longer need to rely on the DOM, an interface
designed primarily for humans, to build accessibility trees or perform expensive LLM-based reasoning to infer available
functionality. Instead, agents can directly discover capabilities through the browser context as structured MCP tools,
with explicit definitions of inputs, outputs, and intent.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Direct and efficient tool execution.&lt;/strong&gt; Once discovered, agents can execute tools directly via the browser context.
For example, a browser-based agent implemented as a Chrome extension can use underlying browser APIs to invoke registered
tools, which in turn execute the corresponding JavaScript callbacks defined by the page. This removes the need for fragile
browser automation techniques such as simulating user interactions or relying on screenshots to determine application state.
Instead, agents interact with purpose-built, reliable interfaces designed specifically for them.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;While WebMCP introduces a few additional steps to the developer workflow and may increase infrastructure requirements, this is
more of an extension of existing systems rather than the need to build and maintain a completely separate system solely for MCP.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/7.CnvGrZgK_1jacSa.webp&quot; alt=&quot;WebMCP exposing agent-specific tool interfaces alongside the human-facing web UI&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 2171px) 2171px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;2171&quot; height=&quot;724&quot;&gt;&lt;/p&gt;
&lt;p&gt;If you want to explore this hands-on, I recommend trying out the &lt;a href=&quot;https://webmcp.sh/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;WebMCP Playground&lt;/a&gt; project
or &lt;a href=&quot;https://mcp-b.ai/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;MCP-B&lt;/a&gt; with a sample application.&lt;/p&gt;
&lt;p&gt;Standardizing WebMCP is a significant step in the right direction. However, there are still open questions, particularly
around identity and authorization.&lt;/p&gt;
&lt;p&gt;In practice, most JavaScript callback functions behind MCP tools need to either retrieve or modify state via backend APIs.
These APIs are typically protected, and for good reason, they obviously cannot be publicly exposed. As a result, browser-based
agents often rely on the logged-in user’s session or access tokens to perform these operations, effectively introducing another
layer of impersonation.&lt;/p&gt;
&lt;p&gt;While requests originating from MCP tools can be distinguished from direct user actions, the lack of a distinct agent identity
remains a key limitation. Without a unique identity, agents cannot properly identify themselves to backend systems.&lt;/p&gt;
&lt;p&gt;There are emerging approaches to address this. The OpenID Foundation’s &lt;a href=&quot;https://openid.net/wp-content/uploads/2025/10/Identity-Management-for-Agentic-AI.pdf&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;em&gt;Identity Management for Agentic AI&lt;/em&gt;&lt;/a&gt;
whitepaper, published in late 2025, is one industry effort mapping out exactly this gap. On the mechanics, OAuth 2.0 token
exchange (&lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc8693&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;RFC 8693&lt;/a&gt;) and related specifications can enable issuing separate
tokens for agents. However, this still assumes that the agent has its own identity to begin with.&lt;/p&gt;
&lt;p&gt;Although browser-based agents typically obtain user consent before executing tools, backend systems still perceive
these actions as being performed by the user. This makes it difficult to enforce access control policies specifically
for agents. Consenting to an agent acting on your behalf is not the same as granting scoped, revocable, auditable
delegation. OAuth 2.0 taught us exactly this distinction a decade ago: user consent alone is what the pre-OAuth2 world relied on too.&lt;/p&gt;
&lt;p&gt;Given that WebMCP is still in an early stage, it will be interesting to see how the ecosystem evolves to address these
challenges, whether through enhancements in authorization models or complementary specifications.&lt;/p&gt;
&lt;p&gt;One practical challenge remains: not every application has OAuth 2.0 infrastructure in place. For smaller organizations,
deploying and maintaining such infrastructure can be a barrier, which needs to be considered when designing future solutions in this space.&lt;/p&gt;
&lt;h2 id=&quot;the-browser-agent-identity-problem-agents-that-borrow-yours&quot;&gt;The browser agent identity problem: agents that borrow yours&lt;/h2&gt;
&lt;p&gt;The most fundamental limitation of current browser-based agents, also inherited by WebMCP, is the absence of a distinct identity for agents.
Today, agents operate by impersonating the human user, effectively hijacking (with user consent) the user’s session to interact with
web applications.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;This model is fundamentally flawed&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;As autonomous agents become more sophisticated, they must be treated as independent actors with their own identities.
The assumption that user &lt;em&gt;&lt;strong&gt;identity == agent identity&lt;/strong&gt;&lt;/em&gt;, and &lt;em&gt;&lt;strong&gt;user session == agent session&lt;/strong&gt;&lt;/em&gt;, in the context of accessing
business applications, is incorrect and needs to be addressed early.&lt;/p&gt;
&lt;p&gt;This isn’t a new idea. We decided years ago that non-human actors deserve their own identities. Workloads and services
already get their own credentials through models like &lt;a href=&quot;https://spiffe.io/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;SPIFFE&lt;/a&gt; and service accounts, precisely so
we can authorize and audit them separately from the people who run them. We have gone even further with workload identity federation,
which gives us an even more secure execution model. Agents are simply the next class of non-human actor, and they deserve the same treatment.
But fundamentally, agents are not as dumb as traditional workloads. They reason, adapt, and act, which puts them somewhere
closer to humans, and that makes a distinct identity for them even more important.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;To be clear, MCP is an API interaction model. It is not responsible for defining identity.&lt;/strong&gt; Its role is to standardize
how tools are invoked and how authorization is applied at the protocol level. The current MCP authorization model
provides a solid baseline for enforcing access control during tool invocation.&lt;/p&gt;
&lt;p&gt;However, the question of who or what is invoking those tools, human or agent, must be handled at the identity layer, outside of MCP.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://www.identityblog.com/?p=352&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;The internet was built without a native identity layer&lt;/a&gt;, and we continue to deal with the
consequences of that decision. &lt;strong&gt;We cannot afford to repeat the same mistake when building the agentic web.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;An agentic ecosystem without a clear notion of identity will lead to ambiguity in accountability, weak access control,
and increased security risks. Establishing a proper identity model for agents is not optional. It is foundational.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;If you see this differently, I’d genuinely like to know, especially if you’re solving this in production.
Find me on &lt;a href=&quot;https://www.linkedin.com/in/ssagara/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;LinkedIn&lt;/a&gt;; I’d love to continue the conversation there.&lt;/p&gt;</content:encoded><dc:creator>Sagara Gunathunga</dc:creator><category>Agent Identity</category><category>MCP</category></item><item><title>Unwrapping MCP Security: A Walkthrough with the PayPal MCP Server</title><link>https://sagarag.dev/posts/walkthrough-with-the-paypal-mcp-server</link><guid isPermaLink="true">https://sagarag.dev/posts/walkthrough-with-the-paypal-mcp-server</guid><description>A walkthrough of connecting Claude Desktop to PayPal’s remote MCP server over HTTP, highlighting the full OAuth 2.0 flow with Postman from discovery to authorization</description><pubDate>Mon, 12 May 2025 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/0.BD5rhaMZ_Z1VJpDb.webp&quot; alt=&quot;Claude Desktop with Paypal MCP server tools&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1672px) 1672px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1672&quot; height=&quot;941&quot;&gt;&lt;/p&gt;
&lt;p&gt;In the &lt;a href=&quot;https://sagarag.dev/posts/walkthrough-with-the-github-mcp-server&quot;&gt;previous post&lt;/a&gt;, we walked through the GitHub MCP server using STDIO transport which keeps things local and sidesteps most security concerns. This post takes the next step: connecting Claude Desktop to PayPal’s remote MCP server, which runs over HTTP and requires real authorization handling.&lt;/p&gt;
&lt;p&gt;That shift from local to remote is where MCP security gets interesting. And PayPal, a platform handling real accounts, real transactions, and real money is exactly the right example to learn it from.&lt;/p&gt;
&lt;p&gt;I’ll extend the same layered approach from the &lt;a href=&quot;https://sagarag.dev/posts/walkthrough-with-the-github-mcp-server&quot;&gt;previous post&lt;/a&gt;: start with what the user experiences, then gradually unwrap what’s happening underneath. If you haven’t read the GitHub MCP walkthrough yet, I’d recommend starting there before diving into this one.&lt;/p&gt;
&lt;div class=&quot;block-default info&quot;&gt;&lt;p&gt;
This post is based on the 2025-03-26 revision of the MCP protocol and authorization spec changes introduced on 2025-04-26. Details may change in future revisions. (Published: 12 May 2025)&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;This post focuses specifically on PayPal’s remote MCP server, hosted on PayPal’s infrastructure and communicating over HTTP/SSE. For context, PayPal also offers a local MCP server that behaves similarly to the GitHub server from the previous post.&lt;/p&gt;
&lt;a href=&quot;https://sagarag.dev/posts/walkthrough-with-the-github-mcp-server&quot; class=&quot;post-link-card&quot;&gt; &lt;span class=&quot;post-link-card__icon&quot;&gt; &lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;24&quot; height=&quot;24&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;1.75&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt; &lt;path d=&quot;M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z&quot;&gt;&lt;/path&gt; &lt;polyline points=&quot;14 2 14 8 20 8&quot;&gt;&lt;/polyline&gt; &lt;line x1=&quot;16&quot; y1=&quot;13&quot; x2=&quot;8&quot; y2=&quot;13&quot;&gt;&lt;/line&gt; &lt;line x1=&quot;16&quot; y1=&quot;17&quot; x2=&quot;8&quot; y2=&quot;17&quot;&gt;&lt;/line&gt; &lt;line x1=&quot;10&quot; y1=&quot;9&quot; x2=&quot;8&quot; y2=&quot;9&quot;&gt;&lt;/line&gt; &lt;/svg&gt; &lt;/span&gt; &lt;span class=&quot;post-link-card__body&quot;&gt; &lt;span class=&quot;post-link-card__title&quot;&gt;Unwrapping MCP: A Walkthrough with the GitHub MCP Server&lt;/span&gt; &lt;span class=&quot;post-link-card__desc&quot;&gt;MCP explained from the inside out, starting with a real developer workflow then unwrapping the protocol layer by layer: roles, messages, connection lifecycle, and STDIO transport&lt;/span&gt; &lt;/span&gt; &lt;span class=&quot;post-link-card__arrow&quot;&gt; &lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;18&quot; height=&quot;18&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt; &lt;path d=&quot;M5 12h14&quot;&gt;&lt;/path&gt; &lt;path d=&quot;m12 5 7 7-7 7&quot;&gt;&lt;/path&gt; &lt;/svg&gt; &lt;/span&gt; &lt;/a&gt;
&lt;h2 id=&quot;the-experience&quot;&gt;The experience&lt;/h2&gt;
&lt;p&gt;To get started, I added the configuration snippet from PayPal’s MCP documentation into Claude Desktop’s settings file and restarted the application.&lt;/p&gt;
&lt;p&gt;On launch, Claude Desktop automatically opened a browser window, which redirected me to PayPal’s login page. After completing the login flow, I was redirected back to Claude Desktop — where a new interface element appeared confirming a successful connection to the PayPal MCP server. Clicking that element showed the tools exposed by the server, confirming that Claude Desktop had established a session tied to my PayPal account.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/1.CQNpJX_R_ZpY74B.webp&quot; alt=&quot;Claude Desktop with Paypal MCP server tools&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1400px) 1400px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1400&quot; height=&quot;822&quot;&gt;&lt;/p&gt;
&lt;p&gt;With the setup complete, I sent a simple query:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;How do you compare my expenses during last February and this February using PayPal?&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Claude Desktop, with the help of the LLM, identified the appropriate tool &lt;code&gt;listTransactions&lt;/code&gt; from the PayPal MCP server and prompted me for consent before executing it. Same pattern as VS Code in the previous walkthrough.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/2.CNEuOWlS_2p85v8.webp&quot; alt=&quot;Claude Desktop prompts for consent&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1400px) 1400px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1400&quot; height=&quot;950&quot;&gt;&lt;/p&gt;
&lt;p&gt;After I granted consent, the tool was executed and the results came back as a well-structured natural language summary comparing my expenses across the two months.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/3.Bv-4g4Hk_Z21kyn7.webp&quot; alt=&quot;Claude Desktop showing comparison of my Paypal transactions&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1400px) 1400px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1400&quot; height=&quot;1071&quot;&gt;&lt;/p&gt;
&lt;p&gt;This is what a remote MCP server looks like from the user’s perspective seamless, conversational, and operating across real financial data. Now let’s look at what actually happened under the hood.&lt;/p&gt;
&lt;hr/&gt;
&lt;h2 id=&quot;the-security-flow&quot;&gt;The security flow&lt;/h2&gt;
&lt;p&gt;Let’s start by understanding how each component connects. Claude Desktop runs locally on your machine. It’s configured to connect to the PayPal remote MCP server, which is hosted on PayPal’s infrastructure. The PayPal MCP server in turn connects to PayPal’s backend APIs.&lt;/p&gt;
&lt;p&gt;Claude Desktop communicates with the PayPal MCP server over HTTP which means two things: the connection uses TLS (HTTPS) for transport security, and the HTTP endpoint requires application-level security on top of that. This requirement is fundamentally not different from how we secure any API endpoint. The MCP host, Claude Desktop in our case — handles most of this complexity behind the scenes and only surfaces interactions that require the end user.&lt;/p&gt;
&lt;p&gt;In this section, let’s unwrap that security layer using Postman so we can observe exactly what’s happening.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/4.cx0J4is8_2t2pHx.webp&quot; alt=&quot;Paypal MCP server configuration&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 2171px) 2171px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;2171&quot; height=&quot;724&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;step-1-what-happens-without-a-token&quot;&gt;Step 1: What happens without a token&lt;/h3&gt;
&lt;p&gt;As a first exercise, let’s assume there are no security requirements and make a direct call to the PayPal MCP server endpoint. You can find the MCP endpoint URL in the Claude Desktop configuration file.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/5.QY2_vlrU_Z1GuMTW.webp&quot; alt=&quot;How Claude Desktop integrated with Paypal MCP server&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1683px) 1683px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1683&quot; height=&quot;935&quot;&gt;&lt;/p&gt;
&lt;p&gt;Send an HTTP request to that endpoint using Postman or cURL — without any authorization header.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/6.D13lR0xp_2ohW4.webp&quot; alt=&quot;Accessing MCP server endpoint without any token&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1400px) 1400px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1400&quot; height=&quot;583&quot;&gt;&lt;/p&gt;
&lt;p&gt;The response is an HTTP &lt;code&gt;401 Unauthorized&lt;/code&gt; stating that either no access token was provided, or the one provided is invalid. In our case, we know no token was provided.&lt;/p&gt;
&lt;p&gt;So we need an access token from PayPal before any MCP messages will go through. Now you might be wondering: Claude Desktop figured this out and obtained a valid token without any manual setup, how?&lt;/p&gt;
&lt;h3 id=&quot;step-2-metadata-discovery&quot;&gt;Step 2: Metadata discovery&lt;/h3&gt;
&lt;div class=&quot;block-default info&quot;&gt;&lt;p&gt;
This section is based on the 2025–03–26 revision of the MCP protocol and changes introduced to the auth spec on 2025–04–26. Details may change in future revisions of the MCP protocol. (Date — 12/05/2025)&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;This is where the MCP specification’s metadata discovery mechanism comes in.
Section 2.3.2 of the MCP Authorization spec explains how an MCP client determines the server metadata endpoint — the URL that describes everything needed to obtain an access token. Claude Desktop uses the following procedure to construct it:&lt;/p&gt;
&lt;p&gt;Take the MCP server URL and discard any path components to get the base URL
Append /.well-known/oauth-authorization-server to construct the metadata endpoint, as defined by the OAuth 2.0 Authorization Server Metadata specification (RFC 8414)&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/7.-IyhV5Gs_I2zns.webp&quot; alt=&quot;Construction of the metadata endpoint&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1790px) 1790px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1790&quot; height=&quot;879&quot;&gt;&lt;/p&gt;
&lt;p&gt;With that endpoint in hand, send a GET request to it using Postman.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/8.BG1dmWfQ_lBtid.webp&quot; alt=&quot;Authorization Server metadata&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1326px) 1326px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1326&quot; height=&quot;1154&quot;&gt;&lt;/p&gt;
&lt;p&gt;The response is the server metadata document. From this, you can read off everything needed for the next steps:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Client registration endpoint&lt;/strong&gt; — OAuth 2.0 requires clients to register and obtain credentials before requesting tokens&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Authorization endpoint&lt;/strong&gt; — where Claude Desktop sends the user for authentication and consent&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Token endpoint&lt;/strong&gt; — where Claude Desktop exchanges the authorization code for an access token&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The document also includes supported grant types, client types, and client authentication methods. As per the MCP specification, MCP servers should and MCP clients must support the OAuth 2.0 Authorization Server Metadata specification.&lt;/p&gt;
&lt;p&gt;When a server doesn’t support Authorization Server Metadata, the MCP spec defines a fallback mechanism for determining the required endpoints.&lt;/p&gt;
&lt;h3 id=&quot;a-note-on-how-this-is-changing-in-future-revisions&quot;&gt;&lt;em&gt;A note on how this is changing in future revisions&lt;/em&gt;&lt;/h3&gt;
&lt;p&gt;Shortly after the 2025-03-26 revision, significant discussions emerged around the authorization spec design. It’s worth pausing on this, because the change reflects an important architectural shift.
In the current revision, all authorization capabilities returning AS metadata, dynamic client registration, authorization, and token endpoints — are defined as part of the MCP server role. In other words, authorization is tightly coupled with the MCP server itself.&lt;/p&gt;
&lt;p&gt;OAuth 2.0 takes a different approach: it defines the Authorization Server (AS) and the Resource Server (RS) as two distinct roles. The spec allows a single entity to play both roles, but keeping them separate gives implementers meaningful flexibility,  particularly in enterprise environments where authorization infrastructure already exists independently of the services it protects.&lt;/p&gt;
&lt;p&gt;Mapping OAuth 2.0 terminology to MCP: the tools, prompts, and resources exposed by an MCP server map to the Resource Server role, while the authorization capabilities map to the Authorization Server role. The current design conflates them, which limits flexibility and creates unnecessary coupling.&lt;/p&gt;
&lt;p&gt;The tightly-coupled design was likely a pragmatic choice, it allows metadata discovery to work from the MCP server URL alone, with no additional configuration. But based on feedback from identity experts and implementers, this is being reconsidered.&lt;/p&gt;
&lt;p&gt;The draft specification has moved to use the OAuth 2.0 Protected Resource Metadata (PRM) specification (RFC 9728) for metadata discovery instead. PRM defines a standard mechanism for a Resource Server to return a pointer to its metadata as part of the initial 401 response. Future revisions of the MCP specification will require both servers and clients to support PRM. I’ve written a dedicated post on how PRM works and why it matters.&lt;/p&gt;
&lt;a href=&quot;https://sagarag.dev/posts/protected-resource-metadata-oauth2-dynamic-discovery&quot; class=&quot;post-link-card&quot;&gt; &lt;span class=&quot;post-link-card__icon&quot;&gt; &lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;24&quot; height=&quot;24&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;1.75&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt; &lt;path d=&quot;M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z&quot;&gt;&lt;/path&gt; &lt;polyline points=&quot;14 2 14 8 20 8&quot;&gt;&lt;/polyline&gt; &lt;line x1=&quot;16&quot; y1=&quot;13&quot; x2=&quot;8&quot; y2=&quot;13&quot;&gt;&lt;/line&gt; &lt;line x1=&quot;16&quot; y1=&quot;17&quot; x2=&quot;8&quot; y2=&quot;17&quot;&gt;&lt;/line&gt; &lt;line x1=&quot;10&quot; y1=&quot;9&quot; x2=&quot;8&quot; y2=&quot;9&quot;&gt;&lt;/line&gt; &lt;/svg&gt; &lt;/span&gt; &lt;span class=&quot;post-link-card__body&quot;&gt; &lt;span class=&quot;post-link-card__title&quot;&gt;Protected Resource Metadata Is the Missing Piece in OAuth 2.0 Discovery&lt;/span&gt; &lt;span class=&quot;post-link-card__desc&quot;&gt;OAuth 2.0 could automate client registration and AS discovery, but clients still had to hardcode which authorization server protects a given resource. Protected Resource Metadata fixes that. Here&amp;#39;s how PRM completes the dynamic integration story&lt;/span&gt; &lt;/span&gt; &lt;span class=&quot;post-link-card__arrow&quot;&gt; &lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;18&quot; height=&quot;18&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt; &lt;path d=&quot;M5 12h14&quot;&gt;&lt;/path&gt; &lt;path d=&quot;m12 5 7 7-7 7&quot;&gt;&lt;/path&gt; &lt;/svg&gt; &lt;/span&gt; &lt;/a&gt;
&lt;h3 id=&quot;step-3-client-registration&quot;&gt;Step 3: Client registration&lt;/h3&gt;
&lt;p&gt;With the metadata document in hand, we can register an OAuth 2.0 client application by sending a request to the registration endpoint, as defined by the OAuth 2.0 Dynamic Client Registration protocol (RFC 7591).&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/9.HhM_m9qf_Z2vtptB.webp&quot; alt=&quot;Registering OAuth2 client&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1400px) 1400px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1400&quot; height=&quot;926&quot;&gt;&lt;/p&gt;
&lt;p&gt;In the example above, we registered a confidential client and received client_id and client_secret in response. I’ve covered DCR in more detail in a previous post.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Let’s quickly recap where we are:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;We derived the metadata endpoint from the MCP server URL — the only URL we had to start with&lt;/li&gt;
&lt;li&gt;We discovered the registration, authorization, and token endpoints from the server metadata&lt;/li&gt;
&lt;li&gt;We registered an OAuth 2.0 client and received the necessary credentials&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;One important point: you typically only need to do this once per MCP server — when first adding it to your host application. Once registration is complete and metadata is retrieved, the host application can persist these securely for use in future token requests.&lt;/p&gt;
&lt;p&gt;Two additional things worth noting at this stage:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Depending on whether your client application can securely store and manage client secrets, you need to choose between a public client and a confidential client.&lt;/li&gt;
&lt;li&gt;The MCP specification uses OAuth 2.1 draft, not OAuth 2.0 — which means regardless of client type, you must use PKCE. I’ve covered PKCE in detail here.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;step-4-authorization-code-flow&quot;&gt;Step 4: Authorization code flow&lt;/h3&gt;
&lt;p&gt;Now let’s run the actual OAuth 2.0 authorization code flow. For this walkthrough, I’m using Postman’s built-in OAuth 2.0 configuration — filling in the authorization and token endpoints from the server metadata, and the client_id, client_secret, grant type, and redirect URI from the DCR response.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/10.o5NEwgws_1783Uq.webp&quot; alt=&quot;Paypal login screen&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1400px) 1400px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1400&quot; height=&quot;904&quot;&gt;&lt;/p&gt;
&lt;p&gt;When you press Get Access Token, Postman constructs an authorization request and opens it in a browser. If everything is configured correctly, you’ll see the PayPal login screen — no different from a standard login flow.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/11.CpGwnDTS_kzrFQ.webp&quot; alt=&quot;Postman OAuth2 configuration&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1400px) 1400px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1400&quot; height=&quot;897&quot;&gt;&lt;/p&gt;
&lt;p&gt;Once the user logs in and consents to share the token, PayPal returns an authorization code to the client via the browser. The client then exchanges this code at the token endpoint to obtain an access token.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/12.r1aXVAt__ZgCwzf.webp&quot; alt=&quot;Token call to Paypal&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1400px) 1400px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1400&quot; height=&quot;400&quot;&gt;&lt;/p&gt;
&lt;p&gt;In this walkthrough we used Postman’s embedded browser — but in a real application, the flow works differently. Here’s how a real-world implementation handles it:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/13.Cy02Id0p_1k6Qde.webp&quot; alt=&quot;Full authorization code flow from client to PayPal IdP and back&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 2171px) 2171px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;2171&quot; height=&quot;724&quot;&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;During registration, the application registers either a custom URL scheme (e.g. appname://auth/callback) with the OS, or a port on a temporary local web server (e.g. &lt;a href=&quot;http://localhost:3000/auth/callback&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;http://localhost:3000/auth/callback&lt;/a&gt;) that it starts before the authorization flow begins.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The application constructs the authorization request and opens the system’s default browser programmatically — on macOS and Windows, using system calls like open or start.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The browser sends the authorization request. The server validates it and returns the login page.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;After authentication and consent, the server redirects the user back to the registered redirect URI with the authorization code. If a custom URL scheme is used, the browser detects it and opens the registered application.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The application processes the code, constructs a token request, and sends it to the token endpoint.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The application receives and stores the access token.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;step-5-connecting-with-the-token&quot;&gt;Step 5: Connecting with the token&lt;/h3&gt;
&lt;p&gt;With the access token in hand, we can now send the original MCP message — this time with the token attached. The client connects to the MCP server and a session is established.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/14.DaTrBJDc_1Jvuo5.webp&quot; alt=&quot;Screenshot: Successful MCP session with tokenn&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1400px) 1400px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1400&quot; height=&quot;628&quot;&gt;
[Screenshot: Successful MCP session with token]&lt;/p&gt;
&lt;p&gt;The following sequence diagram illustrates the complete security flow we walked through in this section.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/15.CIXWAyjr_ZHoOU9.webp&quot; alt=&quot;Full sequence diagram: metadata discovery → client registration → authorization code flow → MCP session&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1862px) 1862px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1862&quot; height=&quot;845&quot;&gt;&lt;/p&gt;
&lt;p&gt;For completeness, here’s the MCP request message for the listTransactions tool call:&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light nord&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#d8dee9ff;--shiki-light-bg:#fff;--shiki-dark-bg:#2e3440ff;overflow-x:auto;white-space:pre-wrap;word-wrap:break-word&quot; tabindex=&quot;0&quot; data-language=&quot;json&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;  &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;method&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;tools/call&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;  &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;params&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;    &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;listTransactions&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;    &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;arguments&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;      &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;start_date&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;2025-04-07T10:29:00Z&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;      &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;end_date&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;2025-04-27T10:29:00Z&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;      &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;page_size&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#B48EAD&quot;&gt; 10&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;      &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;page&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#B48EAD&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;    },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;    &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;_meta&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;      &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;progressToken&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#B48EAD&quot;&gt; 12&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And the corresponding response:&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light nord&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#d8dee9ff;--shiki-light-bg:#fff;--shiki-dark-bg:#2e3440ff;overflow-x:auto;white-space:pre-wrap;word-wrap:break-word&quot; tabindex=&quot;0&quot; data-language=&quot;json&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;  &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;transaction_details&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt; [],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;  &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;account_number&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;fgdgt34413r4&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;  &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;start_date&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;2025-04-07T10:29:00+0000&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;  &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;end_date&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;2025-04-27T10:29:00+0000&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;  &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;last_refreshed_datetime&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;2025-05-07T08:29:59+0000&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;  &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;page&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#B48EAD&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;  &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;total_items&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#B48EAD&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;  &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;total_pages&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#B48EAD&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;  &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;links&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt; [&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;    {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;      &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;href&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;https://api.paypal.com/v1/reporting/transactions?end_date=2025-04-27T10%3A29%3A00Z&amp;amp;start_date=2025-04-07T10%3A29%3A00Z&amp;amp;page_size=10&amp;amp;page=1&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;      &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;rel&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;      &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;method&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;GET&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;  ]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I’ve skipped the MCP message flows beyond this point. I covered those in detail in the GitHub MCP Server walkthrough.&lt;/p&gt;
&lt;h2 id=&quot;wrap-up&quot;&gt;Wrap up&lt;/h2&gt;
&lt;p&gt;The primary goal of this post was to make the MCP security flow concrete showing exactly what MCP server developers and MCP host/client developers need to implement when using HTTP transport.&lt;/p&gt;
&lt;p&gt;Here’s the current compliance picture based on the 2025-03-26 revision:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;MCP Servers must:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Support OAuth 2.1 Draft&lt;/li&gt;
&lt;li&gt;Should support OAuth 2.0 Authorization Server Metadata (RFC 8414)&lt;/li&gt;
&lt;li&gt;Should support OAuth 2.0 Dynamic Client Registration (RFC 7591)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;MCP Clients must:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Support OAuth 2.1 Draft&lt;/li&gt;
&lt;li&gt;Support OAuth 2.0 Authorization Server Metadata (RFC 8414)&lt;/li&gt;
&lt;li&gt;Should support OAuth 2.0 Dynamic Client Registration (RFC 7591)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Coming in future revisions (both MCP Servers and Clients):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Must support OAuth 2.0 Protected Resource Metadata (RFC 9728)&lt;/li&gt;
&lt;/ul&gt;
&lt;hr/&gt;
&lt;p&gt;Hope this gives you a practical picture of what MCP security looks like end to end, and what you’ll need to implement if you’re building an MCP server or host application. Stay tuned for the next post!&lt;/p&gt;</content:encoded><dc:creator>Sagara Gunathunga</dc:creator><category>MCP</category></item><item><title>Unwrapping MCP: A Walkthrough with the GitHub MCP Server</title><link>https://sagarag.dev/posts/walkthrough-with-the-github-mcp-server</link><guid isPermaLink="true">https://sagarag.dev/posts/walkthrough-with-the-github-mcp-server</guid><description>MCP explained from the inside out, starting with a real developer workflow then unwrapping the protocol layer by layer: roles, messages, connection lifecycle, and STDIO transport.</description><pubDate>Wed, 07 May 2025 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/0.CMN_84th_R9iK2.webp&quot; alt=&quot;Screenshot: VS Code consent prompt for get_me tool&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1894px) 1894px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1894&quot; height=&quot;830&quot;&gt;&lt;/p&gt;
&lt;p&gt;We’re seeing MCP servers pop up from organizations across software development, retail, finance, healthcare, and entertainment at an unprecedented pace. And there’s no shortage of content covering the protocol: the good, the bad, and every opinion in between.&lt;/p&gt;
&lt;p&gt;In this post, I’m taking a slightly different approach. Rather than jumping straight into the protocol itself, I’ll unwrap MCP layer by layer, starting from the user experience, then moving into the protocol internals. The GitHub MCP Server is our example today, which makes this very much a developer-focused walkthrough.&lt;/p&gt;
&lt;p&gt;So, without any further ado, let’s start our walk.&lt;/p&gt;
&lt;div class=&quot;block-default info&quot;&gt;&lt;p&gt;
This post is based on the 2025-03-26 version of the MCP protocol.&lt;/p&gt;&lt;/div&gt;
&lt;h2 id=&quot;the-experience&quot;&gt;The experience&lt;/h2&gt;
&lt;p&gt;To begin, I created a simple React application in VS Code using GitHub Copilot, purely through natural language instructions:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Create a React web application using the default Vite template&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Other than the prompt, I didn’t touch the code at all. My next step was to create a proper README file, set up a GitHub repo, and commit and push the project, again, all through natural language. To do this, I installed the GitHub MCP Server as a Docker container running locally by adding this configuration snippet into the VS Code user settings file.&lt;/p&gt;
&lt;p&gt;The GitHub MCP Server requires two things:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A Docker runtime (Docker Desktop or Rancher Desktop)&lt;/li&gt;
&lt;li&gt;A GitHub PAT token with permission to create repositories and commit/push&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;
&lt;p&gt;What is my GitHub id?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;At this point, GitHub Copilot understood it needed to run a tool called &lt;code&gt;get_me&lt;/code&gt;, exposed by the GitHub MCP Server. And here’s where an important principle of the MCP protocol shows up in action: the agent explicitly tells you what it’s about to do and asks for your consent before proceeding.&lt;/p&gt;
&lt;p&gt;This is a core design principle of MCP. Users should always know what is happening with their data, and they should control what is shared and what actions are taken. Host applications must surface clear prompts that let users review and approve before anything executes.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/1.BOM3Cggv_ZiKXJk.webp&quot; alt=&quot;Screenshot: VS Code consent prompt for get_me tool&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 862px) 862px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;862&quot; height=&quot;578&quot;&gt;&lt;/p&gt;
&lt;p&gt;Once I gave permission, Copilot ran the tool and returned the result in natural language.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/2.BdFKXGY3_ECF2q.webp&quot; alt=&quot;Screenshot: get_me result showing GitHub username&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 862px) 862px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;862&quot; height=&quot;520&quot;&gt;&lt;/p&gt;
&lt;p&gt;Next, I asked it to create a new repository:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Create a GitHub repo caleld unwrapping-mcp-github&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;em&gt;(Well, it wasn’t intentional, but I made a spelling mistake there — yet the LLM still understood exactly what I wanted.)&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;GitHub Copilot asked for consent to run &lt;code&gt;create_repository&lt;/code&gt; tool.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/3.DGKZz9PU_TBFQz.webp&quot; alt=&quot;Screenshot: create_repository consent prompt&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 864px) 864px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;864&quot; height=&quot;544&quot;&gt;&lt;/p&gt;
&lt;p&gt;Once I confirmed, it returned the URL of the newly created repo.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/4.DriaiTod_Z1pEaFs.webp&quot; alt=&quot;Screenshot: Newly created repo URL in response&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 840px) 840px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;840&quot; height=&quot;612&quot;&gt;&lt;/p&gt;
&lt;p&gt;Finally, I gave one instruction to wrap everything up:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Create a proper README file, commit and push this code into the newly created repo&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This time, Copilot had to perform multiple tasks and asked for explicit approval at each step. At the end, it confirmed everything was pushed. You can see the final result  &lt;a href=&quot;https://github.com/sagara-gunathunga/unwrapping-mcp-github&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;here.&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/5.BdfvV3Fe_1Mq1yc.webp&quot; alt=&quot;Screenshot: Multi-step approval and success confirmation&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 852px) 852px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;852&quot; height=&quot;864&quot;&gt;&lt;/p&gt;
&lt;p&gt;That’s a complete React application — created, documented, and published to GitHub, entirely through natural language. And along the way, we saw the consent model that sits at the heart of MCP’s design.&lt;/p&gt;
&lt;hr/&gt;
&lt;h2 id=&quot;mcp-roles-hosts-clients-and-servers&quot;&gt;MCP roles: hosts, clients, and servers&lt;/h2&gt;
&lt;p&gt;Before moving into the protocol internals, let’s look at the three roles MCP defines, because understanding these makes the rest of the walkthrough much easier to follow.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/6.1HVNhqr7_Z1MDrol.webp&quot; alt=&quot;Diagram: MCP roles overview&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 2167px) 2167px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;2167&quot; height=&quot;726&quot;&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Hosts&lt;/strong&gt; - the agent applications that create and manage client instances. They handle connections, apply security policies, aggregate context across multiple clients, and manage user authorization decisions. In our example, VS Code is the host. Other examples include Claude Desktop, Cursor, and Windsurf.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Clients&lt;/strong&gt; — connectors within the host application. Each client connects to a specific MCP server and maintains a 1:1 stateful session with it. Clients route protocol messages in both directions between the host and the server.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Servers&lt;/strong&gt; — provide context and capabilities via the MCP protocol. These can live in the local environment (accessing your file system or a local database) or offer remote access (like the GitHub MCP Server communicating with GitHub’s APIs).&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/7.CcnhL5Ak_Z2isTUg.webp&quot; alt=&quot;Diagram: MCP Server Features&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 2170px) 2170px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;2170&quot; height=&quot;725&quot;&gt;&lt;/p&gt;
&lt;p&gt;The diagram below shows how all the components work together in our example use case at runtime.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/8.DkQWHg-v_apKts.webp&quot; alt=&quot;Diagram: How all components work together in our example at runtime&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1581px) 1581px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1581&quot; height=&quot;995&quot;&gt;&lt;/p&gt;
&lt;p&gt;At this point, one can ask a very valid question: given that the GitHub API is being called at the end of the day, why not just call it directly? Why invent a new protocol like MCP when GitHub SDKs and even Terraform modules already make these integrations relatively straightforward?&lt;/p&gt;
&lt;p&gt;It’s a fair question. The answer comes down to three things MCP provides over direct API integration:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Standardization&lt;/strong&gt; — MCP acts as a universal connector, much like USB-C. Instead of building and maintaining separate connectors for every proprietary API, you integrate once with MCP and reuse that across multiple projects and models. In the exercise above, we didn’t write a single line of code or touch any SDK.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Capability discovery for LLMs&lt;/strong&gt; — MCP enables LLMs to automatically discover what capabilities a server offers. This means AI applications can dynamically understand and use new functionality without manual prompt engineering or hardcoding. The result is applications that are more adaptive and extensible out of the box.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;**Security and maintenance **— With authentication, access control, and data retrieval managed centrally through MCP, there’s no need to scatter credentials or intermediary data across different systems. Compliance and security posture improve as a result.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The spec summarizes the purpose of MCP this way:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Model Context Protocol (MCP) is an open protocol that enables seamless integration between LLM applications and external data sources and tools. Whether you’re building an AI-powered IDE, enhancing a chat interface, or creating custom AI workflows, MCP provides a standardized way to connect LLMs with the context they need.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;the-messages-and-the-flow&quot;&gt;The messages and the flow&lt;/h2&gt;
&lt;p&gt;Now let’s move one layer deeper looking at the actual messages exchanged and how the protocol flow works.&lt;/p&gt;
&lt;p&gt;To do this, I connected the GitHub MCP Server to MCP Inspector, a debugging tool that lets us observe message-level interactions clearly. You can run both locally. Instructions for configuring and connecting them are here if you want to try it yourself.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/9.CMKSfqOC_ZNHPEU.webp&quot; alt=&quot;Screenshot: MCP Inspector connected to GitHub MCP Server&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1213px) 1213px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1213&quot; height=&quot;661&quot;&gt;&lt;/p&gt;
&lt;h2 id=&quot;resources-prompts-and-tools&quot;&gt;Resources, prompts, and tools&lt;/h2&gt;
&lt;p&gt;An MCP server exposes three types of capabilities: Resources, Prompts, and Tools.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/10.CP9Urgqx_hkq68.webp&quot; alt=&quot;Screenshot: Resources, Prompts, and Tools shown in MCP Inspector&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 2095px) 2095px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;2095&quot; height=&quot;751&quot;&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Resources&lt;/strong&gt; (structured data for context) — application-controlled data sources that servers expose to clients, giving LLMs access to external content as context. These can be files, database records, API responses, logs, images, or anything else the model might need. In our case, the GitHub MCP Server exposes resource templates for interacting with GitHub artefacts.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/11.lR_3Yoti_ZEX90E.webp&quot; alt=&quot;Screenshot: Resource templates in MCP Inspector&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1400px) 1400px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1400&quot; height=&quot;517&quot;&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Prompts&lt;/strong&gt; (predefined templates for optimal use) — user-controlled templates that guide how LLMs interact with tools or resources. They let developers ensure the AI uses external data or functions in the most effective, structured way.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Tools&lt;/strong&gt; (model-controlled functionality) — functions that LLMs can call to perform specific actions, similar to function calling or API invocation. The GitHub MCP Server exposes a significant number of tools — we used several of them in the experience section above.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/12.BvUBhTh3_Z11NcWh.webp&quot; alt=&quot;Screenshot: Tools list in MCP Inspector&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1400px) 1400px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1400&quot; height=&quot;595&quot;&gt;&lt;/p&gt;
&lt;h2 id=&quot;the-connection-lifecycle&quot;&gt;The connection lifecycle&lt;/h2&gt;
&lt;p&gt;MCP is a stateful protocol. It defines a connection lifecycle between client and server in three phases.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/13.DOOMimvl_2bDTzc.webp&quot; alt=&quot;Diagram: MCP connection lifecycle — initialization, operation, close&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1663px) 1663px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1663&quot; height=&quot;945&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;phase-1--initialization&quot;&gt;Phase 1 — Initialization&lt;/h3&gt;
&lt;p&gt;The client and server agree on a protocol version and exchange capabilities. The server declares what it supports: resource subscriptions, tool support, prompt templates. The client declares its own capabilities: sampling support, notification handling. Both parties must respect the declared capabilities for the entire session. MCP uses JSON-RPC as its messaging format.&lt;/p&gt;
&lt;p&gt;Here is the initialize request MCP Inspector sent to the GitHub MCP Server. Since Inspector is a testing tool rather than a production client, it sent no capabilities:&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light nord&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#d8dee9ff;--shiki-light-bg:#fff;--shiki-dark-bg:#2e3440ff;overflow-x:auto;white-space:pre-wrap;word-wrap:break-word&quot; tabindex=&quot;0&quot; data-language=&quot;json&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;  &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;method&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;initialize&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The GitHub MCP Server responds with its capabilities and version information:&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light nord&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#d8dee9ff;--shiki-light-bg:#fff;--shiki-dark-bg:#2e3440ff;overflow-x:auto;white-space:pre-wrap;word-wrap:break-word&quot; tabindex=&quot;0&quot; data-language=&quot;json&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;  &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;capabilities&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;    &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;logging&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt; {},&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;    &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;resources&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;      &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;subscribe&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#81A1C1&quot;&gt; true&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;      &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;listChanged&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#81A1C1&quot;&gt; true&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;    },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;    &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;tools&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;      &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;listChanged&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#81A1C1&quot;&gt; true&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;  },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;  &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;serverInfo&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;    &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;github-mcp-server&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;    &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;version&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;v0.2.1&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;phase-2--operation&quot;&gt;Phase 2 — Operation.&lt;/h3&gt;
&lt;p&gt;Once the session is established, the client and server exchange messages based on the negotiated capabilities.&lt;/p&gt;
&lt;p&gt;To see available tools, invoke the &lt;code&gt;tools/list&lt;/code&gt; method:&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light nord&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#d8dee9ff;--shiki-light-bg:#fff;--shiki-dark-bg:#2e3440ff;overflow-x:auto;white-space:pre-wrap;word-wrap:break-word&quot; tabindex=&quot;0&quot; data-language=&quot;json&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;  &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;method&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;tools/list&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;  &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;params&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt; {}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The server returns the full list of tools. The GitHub MCP Server exposes quite a large number of tools and the response below is truncated:&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light nord&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#d8dee9ff;--shiki-light-bg:#fff;--shiki-dark-bg:#2e3440ff;overflow-x:auto;white-space:pre-wrap;word-wrap:break-word&quot; tabindex=&quot;0&quot; data-language=&quot;json&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;  &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;tools&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt; [&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;    {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;      &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;get_me&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;      &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;description&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;Get details of the authenticated GitHub user. Use this when a request includes &amp;#39;me&amp;#39;, &amp;#39;my&amp;#39;...&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;      &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;inputSchema&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;        &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;object&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;        &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;properties&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;          &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;reason&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;            &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;description&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;Optional: reason the session was created&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;            &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;          }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;      }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;  ]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To call a specific tool, invoke &lt;code&gt;tools/call&lt;/code&gt; with the tool name as a parameter:&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light nord&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#d8dee9ff;--shiki-light-bg:#fff;--shiki-dark-bg:#2e3440ff;overflow-x:auto;white-space:pre-wrap;word-wrap:break-word&quot; tabindex=&quot;0&quot; data-language=&quot;json&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;  &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;method&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;tools/call&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;  &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;params&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;    &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;get_me&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;    &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;arguments&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt; {}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;  },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;  &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;jsonrpc&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;2.0&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;  &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#B48EAD&quot;&gt; 5&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The GitHub MCP Server returns your GitHub username and account details.&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light nord&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#d8dee9ff;--shiki-light-bg:#fff;--shiki-dark-bg:#2e3440ff;overflow-x:auto;white-space:pre-wrap;word-wrap:break-word&quot; tabindex=&quot;0&quot; data-language=&quot;json&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;  &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;method&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;tools/call&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;  &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;    &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;content&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt; [&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;      {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;        &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;text&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;        &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#8FBCBB&quot;&gt;text&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#EBCB8B&quot;&gt;\&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;login&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#EBCB8B&quot;&gt;\&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#EBCB8B&quot;&gt;\&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;sagara-gunathunga&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#EBCB8B&quot;&gt;\&amp;quot;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;, …}&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;      }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;    ]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#ECEFF4&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;phase-3--close&quot;&gt;Phase 3 — Close.&lt;/h3&gt;
&lt;p&gt;One of the parties closes the connection to terminate the session.&lt;/p&gt;
&lt;p&gt;Just to be clear: with production host applications like VS Code or Claude Desktop, you never need to craft these messages manually or invoke tools yourself. When you provide a prompt, the application, with the help of the LLM, automatically selects the right tool, constructs the messages, and manages the entire client-server session. What we’ve done here is lift the hood to see what’s happening underneath.&lt;/p&gt;
&lt;h2 id=&quot;mcp-transports&quot;&gt;MCP transports&lt;/h2&gt;
&lt;p&gt;MCP uses JSON-RPC to encode messages, and all messages must be UTF-8 encoded. The protocol currently defines two standard transport mechanisms:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;STDIO — communication over standard input and output&lt;/li&gt;
&lt;li&gt;Streamable HTTP and SSE&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Custom transports are also possible in a pluggable fashion.&lt;/p&gt;
&lt;p&gt;Both exercises in this post:  VS Code and MCP Inspector used STDIO transport. Let’s look at how it works. HTTP transport is a separate discussion, covered in the next post in this series.&lt;/p&gt;
&lt;p&gt;STDIO stands for standard input/output, the fundamental way processes communicate by reading and writing through streams provided by the operating system. Standard input (stdin) reads data; standard output (stdout) writes it.&lt;/p&gt;
&lt;p&gt;When an MCP server runs as a subprocess, it reads client requests from stdin and writes responses to stdout. The client and server exchange messages directly through these streams.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/14.CTEog5WX_ecx2n.webp&quot; alt=&quot;Diagram: STDIO client-server communication model&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1641px) 1641px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1641&quot; height=&quot;958&quot;&gt;&lt;/p&gt;
&lt;p&gt;STDIO is generally recommended over HTTP/SSE for local integrations because it’s simpler, more efficient, and more secure. It gives you direct, low-latency, bidirectional communication between two processes on the same machine with no network overhead, no server setup, and no OAuth requirements. It’s the right choice for tightly coupled local environments where the client and server run side by side.&lt;/p&gt;
&lt;h2 id=&quot;wrap-up&quot;&gt;Wrap up&lt;/h2&gt;
&lt;p&gt;We started by watching MCP in action by creating a complete React application and pushing it to GitHub entirely through natural language in VS Code. Then we connected the GitHub MCP Server to MCP Inspector to observe exactly what happens at the message level: the initialization handshake, capability exchange, tool discovery, and tool invocation. Finally, we covered the transport layer and why STDIO is the natural fit for local integrations.&lt;/p&gt;
&lt;p&gt;Everything we discussed is common to any MCP server, and GitHub was just our example. The protocol, messages, lifecycle, and transport mechanisms work the same way regardless of which server you’re connecting to. That’s the whole point of MCP.&lt;/p&gt;
&lt;p&gt;Hope this is helpful and stay tuned for the next post where we take the next step: connecting to a remote MCP server over HTTP, where security gets real.&lt;/p&gt;</content:encoded><dc:creator>Sagara Gunathunga</dc:creator><category>MCP</category></item><item><title>Protected Resource Metadata Is the Missing Piece in OAuth 2.0 Discovery</title><link>https://sagarag.dev/posts/protected-resource-metadata-oauth2-dynamic-discovery</link><guid isPermaLink="true">https://sagarag.dev/posts/protected-resource-metadata-oauth2-dynamic-discovery</guid><description>OAuth 2.0 could automate client registration and AS discovery, but clients still had to hardcode which authorization server protects a given resource. Protected Resource Metadata fixes that. Here&apos;s how PRM completes the dynamic integration story, and why AI agents made it urgent.</description><pubDate>Sun, 04 May 2025 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/0.DqfKxf6g_Z1vc8U2.webp&quot; alt=&quot; &quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1672px) 1672px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1672&quot; height=&quot;941&quot;&gt;&lt;/p&gt;
&lt;p&gt;Think about how an AI agent would access a protected API it has never seen before. It needs to know which authorization server issues tokens for that resource, what scopes to request, what token format the resource expects, and how to send the token. Today, in most implementations, that information is either hardcoded or buried in documentation someone has to read and configure manually.&lt;/p&gt;
&lt;p&gt;That has worked for applications built by developers who can read a wiki. It does not work for autonomous agents that need to discover everything at runtime.&lt;/p&gt;
&lt;p&gt;OAuth 2.0 had a piece missing and that piece finally arrived as a standard in early 2025. It’s called &lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc9728&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Protected Resource Metadata (PRM)&lt;/a&gt;, defined in &lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc9728&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;RFC 9728&lt;/a&gt;, and it completes a dynamic integration story that has been building for nearly a decade.&lt;/p&gt;
&lt;p&gt;Let’s break down what was already there, what was missing, and why PRM matters now.&lt;/p&gt;
&lt;h2 id=&quot;the-dynamic-integration-story-so-far&quot;&gt;The dynamic integration story so far&lt;/h2&gt;
&lt;p&gt;Auth 2.0 defines three roles:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;client&lt;/strong&gt; (the application acting on behalf of the user)&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;authorization server&lt;/strong&gt; (which issues access tokens)&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;resource server&lt;/strong&gt; (which hosts the protected resource).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/1.Cq7oiQFJ_Z15H6kD.webp&quot; alt=&quot; &quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1583px) 1583px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1583&quot; height=&quot;994&quot;&gt;&lt;/p&gt;
&lt;p&gt;What makes modern OAuth 2.0 powerful is that much of the integration between these roles can be automated at runtime. Two specifications laid the groundwork for this.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/2.B_-GaUL6_2wJhMQ.webp&quot; alt=&quot; &quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1521px) 1521px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1521&quot; height=&quot;1034&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc8414&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Authorization Server Metadata (RFC 8414)&lt;/a&gt;&lt;/strong&gt; allows a client to discover everything it needs to know about an authorization server by fetching a JSON document from a well-known URL. Supported grant types, token endpoints, authorization endpoints, PKCE support without hardcoding.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc7591&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Dynamic Client Registration (RFC 7591)&lt;/a&gt;&lt;/strong&gt; takes this further. A client that has never interacted with a particular authorization server can register itself programmatically, receive a &lt;code&gt;client_id&lt;/code&gt; and credentials, and start requesting tokens all at runtime.&lt;/p&gt;
&lt;p&gt;Together, these two specifications make the &lt;strong&gt;Client ↔ Authorization Server&lt;/strong&gt; relationship fully automatable. A client can discover an authorization server, register with it, and obtain tokens without any manual configuration.&lt;/p&gt;
&lt;p&gt;But here’s where it fell short.&lt;/p&gt;
&lt;h2 id=&quot;the-piece-that-was-missing&quot;&gt;The piece that was missing&lt;/h2&gt;
&lt;p&gt;Once a client has a token, it presents it to the resource server. The resource server validates it, either by calling the introspection endpoint (for opaque tokens) or verifying the signature using the JWKS endpoint (for JWTs). Both of these can be automated.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/3.BXA6lxpy_Z1luNYp.webp&quot; alt=&quot; &quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1628px) 1628px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1628&quot; height=&quot;966&quot;&gt;&lt;/p&gt;
&lt;p&gt;But there’s a question that neither of the above specifications answers: &lt;strong&gt;how does the client know which authorization server protects a given resource in the first place?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Traditionally, the answer has been: read the documentation. A developer looks up which identity provider an API uses, configures the authorization server URL, and hardcodes it. For an application a human developer builds once and ships, this is manageable. For an AI agent that needs to dynamically access dozens of third-party tools including MCP servers it’s never interacted with before, this is a fundamental blocker.&lt;/p&gt;
&lt;p&gt;This is the gap that Protected Resource Metadata fills.&lt;/p&gt;
&lt;h2 id=&quot;what-protected-resource-metadata-does&quot;&gt;What Protected Resource Metadata does&lt;/h2&gt;
&lt;p&gt;PRM is a mechanism that allows a protected resource(typically an API) to publish a machine-readable JSON document describing its authorization requirements. This document tells clients:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Which authorization servers the resource trusts&lt;/li&gt;
&lt;li&gt;What scopes clients need to request&lt;/li&gt;
&lt;li&gt;How tokens should be delivered (header, body, or query)&lt;/li&gt;
&lt;li&gt;Whether sender-constrained tokens (DPoP or certificate-bound) are required&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/4.B5NEFPSz_1Q8DDJ.webp&quot; alt=&quot; &quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1683px) 1683px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1683&quot; height=&quot;934&quot;&gt;&lt;/p&gt;
&lt;p&gt;The first draft of this specification appeared in 2016. It only recently became a priority because the use cases that requires fully automated, dynamic third-party integration has become urgent. AI agents and MCP are exactly why.&lt;/p&gt;
&lt;p&gt;Together with Authorization Server Metadata and Dynamic Client Registration, PRM completes the full picture. A client can now discover everything it needs from resource requirements to authorization server details to registration entirely at runtime. No documentation, no hardcoded configuration.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works-in-practice&quot;&gt;How it works in practice&lt;/h2&gt;
&lt;p&gt;Let’s walk through the flow.&lt;/p&gt;
&lt;p&gt;When a client accesses a protected resource without providing any security details, the resource server responds with an &lt;code&gt;HTTP 401 Unauthorized&lt;/code&gt; as usual. In a PRM-compliant resource server, this response includes a &lt;code&gt;WWW-Authenticate&lt;/code&gt; header with a &lt;code&gt;resource_metadata&lt;/code&gt; field pointing to the resource metadata URL:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/5.Dc-Y7rdS_ZkVLHy.webp&quot; alt=&quot; &quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1962px) 1962px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1962&quot; height=&quot;801&quot;&gt;&lt;/p&gt;
&lt;p&gt;An actual HTTP response would look like this:&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light nord&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#d8dee9ff;--shiki-light-bg:#fff;--shiki-dark-bg:#2e3440ff;overflow-x:auto;white-space:pre-wrap;word-wrap:break-word&quot; tabindex=&quot;0&quot; data-language=&quot;http&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#81A1C1&quot;&gt;HTTP&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#D8DEE9FF&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#B48EAD&quot;&gt;1.1&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#B48EAD&quot;&gt; 401&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt; Unauthorized&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#22863A;--shiki-dark:#81A1C1&quot;&gt;WWW-Authenticate&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#81A1C1&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt; Bearer resource_metadata=&amp;quot;https://resource.example.com/**.well-known/oauth-protected-resource&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The client then makes a simple HTTP GET request to that URL to retrieve the resource metadata. This is the &lt;strong&gt;Protected Resource Metadata Request&lt;/strong&gt;,  nothing more than a GET to a well-known endpoint.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/6.DXrtccQ0_THQLz.webp&quot; alt=&quot; &quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1681px) 1681px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1681&quot; height=&quot;936&quot;&gt;&lt;/p&gt;
&lt;p&gt;The metadata response tells the client which authorization server issues tokens for this resource (&lt;code&gt;authorization_servers)&lt;/code&gt;, what scopes to request (&lt;code&gt;scopes_supported&lt;/code&gt;), and how to send the token (&lt;code&gt;bearer_methods_supported&lt;/code&gt;). The client uses the authorization server issuer identifier to construct the AS metadata URL from there, the existing Authorization Server Metadata flow takes over.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/7.xvZj9qye_215H9.webp&quot; alt=&quot; &quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1569px) 1569px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1569&quot; height=&quot;1003&quot;&gt;&lt;/p&gt;
&lt;p&gt;One important detail to highlight here: at any point, a resource server can return a fresh &lt;code&gt;WWW-Authenticate&lt;/code&gt; challenge to signal that its metadata has changed. When a client receives this, it should re-fetch the resource metadata and update accordingly. This keeps the entire integration adaptive, if an authorization server changes or new security requirements are introduced, clients pick it up automatically without reconfiguration.&lt;/p&gt;
&lt;h3 id=&quot;key-metadata-parameters&quot;&gt;Key metadata parameters&lt;/h3&gt;
&lt;p&gt;Below are the core parameters defined by the PRM specification.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Mandatory:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;resource&lt;/code&gt; — The unique identifier of the protected resource. Must use HTTPS, must not include a fragment, and ideally should not include a query string.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Strongly recommended:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;authorization_servers&lt;/code&gt; — A list of authorization server issuer identifiers trusted by this resource. Technically optional per the spec, but without it the client has nowhere to go.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;scopes_supported&lt;/code&gt; — The OAuth 2.0 scopes clients must request to access this resource.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;bearer_methods_supported&lt;/code&gt; — How access tokens should be delivered: &lt;code&gt;header&lt;/code&gt;, &lt;code&gt;body&lt;/code&gt;, or &lt;code&gt;query&lt;/code&gt;. An empty array means no bearer methods are supported.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;jwks_uri&lt;/code&gt; — The HTTPS URL pointing to the resource’s JSON Web Key Set, used for verifying signed responses.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Additional security parameters:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;resource_signing_alg_values_supported&lt;/code&gt; — JWS algorithms supported for signing resource responses. The value none is explicitly not permitted.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;authorization_details_types_supported&lt;/code&gt; — Supported authorization_details types when Rich Authorization Requests are in use.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;For DPoP-bound tokens:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;dpop_bound_access_tokens_required&lt;/code&gt; — Boolean. If true, the resource requires all tokens to be DPoP-bound.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;dpop_signing_alg_values_supported&lt;/code&gt; — Supported JWS algorithms for validating DPoP proofs.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;For certificate-bound tokens:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;tls_client_certificate_bound_access_tokens&lt;/code&gt; — Boolean. Indicates whether the resource supports mutual-TLS client certificate-bound tokens. Defaults to false if omitted.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Human-readable parameters (all optional):&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;resource_name&lt;/code&gt; — A display name for the resource, with internationalization support.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;resource_documentation&lt;/code&gt; — URL to developer documentation.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;resource_policy_uri&lt;/code&gt; — URL describing usage policy or restrictions.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;resource_tos_uri&lt;/code&gt; — URL to the resource’s terms of service.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;All human-readable values support language tags (e.g. &lt;code&gt;#en&lt;/code&gt;, &lt;code&gt;#it&lt;/code&gt;) for localization. It’s recommended to also include a default version without a tag for broader compatibility.&lt;/p&gt;
&lt;h3 id=&quot;signed-metadata&quot;&gt;Signed metadata&lt;/h3&gt;
&lt;p&gt;Beyond the standard JSON document, PRM supports delivering resource metadata as a signed JWT. This bundles the same metadata values into a cryptographically signed format that is useful in scenarios where metadata integrity needs to be verifiable.&lt;/p&gt;
&lt;p&gt;The JWT must be signed or MACed using JSON Web Signature (JWS) and must include an &lt;code&gt;iss&lt;/code&gt; (issuer) claim identifying who is asserting the metadata. Systems that support signed metadata must treat it as authoritative over the plain JSON values. The signed metadata is included using the &lt;code&gt;signed_metadata&lt;/code&gt; parameter in the resource metadata response.&lt;/p&gt;
&lt;h3 id=&quot;the-protected_resources-parameter-for-authorization-servers&quot;&gt;The &lt;code&gt;protected_resources&lt;/code&gt; parameter for authorization servers&lt;/h3&gt;
&lt;p&gt;PRM also introduces a new metadata parameter for authorization servers: &lt;code&gt;protected_resources&lt;/code&gt;. This allows an authorization server’s own metadata document to list the resources it protects enabling cross-checking between AS metadata and resource metadata.&lt;/p&gt;
&lt;p&gt;In simple terms: the resource can say &lt;em&gt;I trust this authorization server&lt;/em&gt; and the authorization server can say &lt;em&gt;I protect this resource.&lt;/em&gt; Both sides can independently assert the relationship, which gives clients a way to verify the integrity of the integration.&lt;/p&gt;
&lt;h2 id=&quot;why-this-matters-right-now&quot;&gt;Why this matters right now&lt;/h2&gt;
&lt;p&gt;The sequence diagram below illustrates the full end-to-end flow across all three specifications - &lt;strong&gt;Protected Resource Metadata, Authorization Server Metadata, and Dynamic Client Registration&lt;/strong&gt; working together. While PRM highlights DCR as one possible approach for client registration, it doesn’t mandate it. DCR is included here to show what a fully automated, zero-hardcoding flow looks like.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/8.COlLIKnu_Z2uL4zo.webp&quot; alt=&quot; &quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1774px) 1774px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1774&quot; height=&quot;887&quot;&gt;&lt;/p&gt;
&lt;p&gt;The reason this became urgent is worth stating directly. For years, the gap in dynamic discovery was tolerable as developers could read documentation and configure things once. But AI agents change the equation. An agent that needs to access a set of third-party MCP servers it has never seen before cannot stop and ask a developer to configure each one. It needs to discover authorization requirements, register if necessary, obtain a token, and access the resource — entirely autonomously.&lt;/p&gt;
&lt;p&gt;PRM is what makes that possible. Without it, every dynamic integration still requires a hardcoded authorization server URL somewhere. With it, the full OAuth 2.0 flow — from resource discovery to token acquisition can be driven by the client at runtime, based entirely on machine-readable metadata.
This is the spec that completes the picture. It took nine years from the first draft to standard status. The reason it finally crossed the finish line is sitting right in front of us.&lt;/p&gt;
&lt;hr/&gt;
&lt;p&gt;If you’re building MCP servers or designing AI agent authorization flows, PRM is worth reading directly,  the spec is concise and the parameter reference is clear. You can find it at &lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc9728&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;RFC 9728.&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If you found this useful, I’d love to hear how you’re thinking about dynamic discovery in your own integrations, find me on LinkedIn.&lt;/p&gt;
&lt;h2 id=&quot;related&quot;&gt;Related&lt;/h2&gt;
&lt;a href=&quot;https://sagarag.dev/posts/how-do-you-discover-the-oauth2-server-configuration&quot; class=&quot;post-link-card&quot;&gt; &lt;span class=&quot;post-link-card__icon&quot;&gt; &lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;24&quot; height=&quot;24&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;1.75&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt; &lt;path d=&quot;M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z&quot;&gt;&lt;/path&gt; &lt;polyline points=&quot;14 2 14 8 20 8&quot;&gt;&lt;/polyline&gt; &lt;line x1=&quot;16&quot; y1=&quot;13&quot; x2=&quot;8&quot; y2=&quot;13&quot;&gt;&lt;/line&gt; &lt;line x1=&quot;16&quot; y1=&quot;17&quot; x2=&quot;8&quot; y2=&quot;17&quot;&gt;&lt;/line&gt; &lt;line x1=&quot;10&quot; y1=&quot;9&quot; x2=&quot;8&quot; y2=&quot;9&quot;&gt;&lt;/line&gt; &lt;/svg&gt; &lt;/span&gt; &lt;span class=&quot;post-link-card__body&quot;&gt; &lt;span class=&quot;post-link-card__title&quot;&gt;How do you discover the OAuth2 server configuration?&lt;/span&gt; &lt;span class=&quot;post-link-card__desc&quot;&gt;A deep-dive into Authorization Server Metadata (RFC 8414) — how clients discover endpoints, grant types, and capabilities at runtime without hardcoding a thing.&lt;/span&gt; &lt;/span&gt; &lt;span class=&quot;post-link-card__arrow&quot;&gt; &lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;18&quot; height=&quot;18&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt; &lt;path d=&quot;M5 12h14&quot;&gt;&lt;/path&gt; &lt;path d=&quot;m12 5 7 7-7 7&quot;&gt;&lt;/path&gt; &lt;/svg&gt; &lt;/span&gt; &lt;/a&gt;</content:encoded><dc:creator>Sagara Gunathunga</dc:creator><category>MCP</category><category>OAuth 2.0</category></item><item><title>Certificate-Bound Access Tokens: How mTLS Makes Stolen Tokens Useless</title><link>https://sagarag.dev/posts/mtls-and-oauth2-certificate-bound-tokens</link><guid isPermaLink="true">https://sagarag.dev/posts/mtls-and-oauth2-certificate-bound-tokens</guid><description>Bearer tokens are usable by anyone who possesses them. Certificate-bound tokens, defined in RFC 8705, bind the access token to the client certificate used in the mTLS handshake, so even if a token is intercepted, it&apos;s cryptographically worthless without the matching certificate.</description><pubDate>Sat, 26 Apr 2025 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/0.BO-U1x2L_Znr5lz.webp&quot; alt=&quot;Diagram: Authorization response with opaque token&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1672px) 1672px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1672&quot; height=&quot;941&quot;&gt;&lt;/p&gt;
&lt;p&gt;In the previous post, we explored how the certificate-based mutual authentication that happens during the TLS handshake can be applied directly to OAuth2 client authentication, a stronger alternative to shared secrets, particularly in system-to-system communication where mTLS is already in use.&lt;/p&gt;
&lt;p&gt;This post takes it a step further. We’ll explore how that same client certificate can be used to bind the access token to the client that requested it so that even if someone intercepts or steals the token, they can’t use it. This is the second part of a two-post series on  &lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc8705&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mutual-TLS Client Authentication and Certificate-Bound Access Tokens (RFC 8705)&lt;/a&gt;. If you haven’t read the first part, I’d recommend starting there.&lt;/p&gt;
&lt;p&gt;Let’s start by making sure we’re clear on OAuth2 token types because the certificate binding mechanism works differently depending on what kind of token you’re dealing with.&lt;/p&gt;
&lt;h2 id=&quot;chapter-1-oauth2-token-types&quot;&gt;Chapter 1: OAuth2 token types&lt;/h2&gt;
&lt;h3 id=&quot;token-format-opaque-vs-jwt&quot;&gt;Token format: opaque vs. JWT&lt;/h3&gt;
&lt;p&gt;There are two main token formats in OAuth2.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Opaque (reference-type) tokens&lt;/strong&gt;  store the actual authorization details exclusively on the authorization server. The client receives only a reference value — a randomly generated string with no embedded data. This offers a security advantage: if the token is exposed, nothing meaningful can be extracted from it. When a resource server needs to verify the token and retrieve the authorization data, it calls the authorization server’s introspection endpoint. Opaque tokens were the dominant format in OAuth2’s early days and are still widely used in scenarios where token confidentiality is a priority.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/1.DkufoXGJ_Z2vNVqr.webp&quot; alt=&quot;Diagram: Authorization response with opaque token&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 2170px) 2170px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;2170&quot; height=&quot;725&quot;&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;JWT (value-type) tokens&lt;/strong&gt; embed authorization details and metadata directly in the token itself, encoded in JSON. This allows clients and resource servers to validate and extract token information locally without a round-trip to the authorization server. That’s the key efficiency advantage of JWTs over opaque tokens. In real-world OAuth2 deployments, you won’t typically see plain unsigned JWTs. What you’ll encounter is one of two secured forms:
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;JWS (JSON Web Signature)&lt;/strong&gt; — JWTs digitally signed by the token issuer&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;JWE (JSON Web Encryption)&lt;/strong&gt; — JWTs encrypted by the token issuer&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/2.9EWEMvIz_Z18XuyT.webp&quot; alt=&quot;Diagram: Authorization response with opaque token&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 2170px) 2170px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;2170&quot; height=&quot;725&quot;&gt;&lt;/p&gt;
&lt;p&gt;This is what it looks like when the token is decoded.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/3.Cw9DROiG_Z22kuNB.webp&quot; alt=&quot;Diagram: Authorization response with JWT access token and decoded claim set&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1962px) 1962px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1962&quot; height=&quot;801&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;token-usage-bearer-vs-sender-constrained&quot;&gt;Token usage: bearer vs. sender-constrained&lt;/h3&gt;
&lt;p&gt;Now let’s classify tokens by how a client presents them when accessing a protected resource. This classification is where certificate binding becomes relevant.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Bearer tokens&lt;/strong&gt; work like cash. When you pay with a banknote, the merchant checks whether the note is authentic, but they don’t verify whether it’s actually yours. You could have found it on the street. If you possess it, you can use it. Bearer tokens work the same way: the resource server validates the token itself, but not the party presenting it. They’re widely adopted because of their simplicity, pass the token as an HTTP Authorization header, and you’re done.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Proof-of-Possession (PoP) tokens&lt;/strong&gt;, also known as &lt;strong&gt;sender-constrained tokens&lt;/strong&gt;, work more like a credit card. Simply presenting the card isn’t enough — you may need to sign for it, and the merchant might verify your identity against the name printed on it. Possession alone doesn’t prove legitimacy. PoP tokens bind the token to something only the legitimate client can prove ownership of. Someone who steals a PoP token can’t use it — they don’t have the private key or certificate needed to prove they’re the authorized holder.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/4.inzUbVA3_1F7v0R.webp&quot; alt=&quot;Diagram: Bearer vs. PoP token analogy&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1628px) 1628px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1628&quot; height=&quot;966&quot;&gt;&lt;/p&gt;
&lt;p&gt;PoP tokens offer a significantly stronger security posture than bearer tokens. The honest reason they’re not yet as widely adopted is implementation complexity, but for high-assurance scenarios, they’re the right choice. This is exactly the direction the industry is moving, especially as AI agents and autonomous systems start accessing APIs at scale.&lt;/p&gt;
&lt;h2 id=&quot;chapter-2-certificate-bound-tokens&quot;&gt;Chapter 2: Certificate-bound tokens&lt;/h2&gt;
&lt;p&gt;Now let’s connect the two posts.&lt;/p&gt;
&lt;p&gt;In the previous post, we walked through how the mTLS handshake includes a &lt;code&gt;CertificateVerify&lt;/code&gt; message where the client signs a hash of the handshake messages using its private key, proving it actually possesses the private key corresponding to its certificate. This is already a built-in proof-of-possession mechanism.&lt;/p&gt;
&lt;p&gt;Now you might be wondering: when an OAuth2 client establishes an mTLS connection with the authorization server, it has already demonstrated ownership of its private key during the handshake. &lt;strong&gt;Can we use that same proof to bind the access token to the client certificate?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;That’s exactly what the second part of &lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc8705&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mutual-TLS Client Authentication and Certificate-Bound Access Tokens (RFC 8705)&lt;/a&gt; introduces: &lt;em&gt;&lt;strong&gt;Certificate-Bound Access Tokens&lt;/strong&gt;&lt;/em&gt;.&lt;/p&gt;
&lt;h3 id=&quot;how-the-binding-works&quot;&gt;How the binding works&lt;/h3&gt;
&lt;p&gt;A &lt;strong&gt;certificate-bound token&lt;/strong&gt; is an access token that the authorization server binds to the client certificate presented during the mTLS handshake. To use the token, the client must establish an mTLS connection with the resource server using the exact same certificate. The resource server verifies that the certificate associated with the token matches the certificate in the current connection.&lt;/p&gt;
&lt;p&gt;Instead of storing or transmitting the full certificate, the binding is done using the certificate fingerprint, a unique, lightweight identifier for the certificate.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/5.Bg_JkGpa_2rl9xl.webp&quot; alt=&quot;Diagram: Certificate fingerprint calculation&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1570px) 1570px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1570&quot; height=&quot;1002&quot;&gt;&lt;/p&gt;
&lt;p&gt;In the first post, we covered how fingerprints are calculated. To recap:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Convert the certificate to DER binary format (from PEM, if needed).&lt;/li&gt;
&lt;li&gt;Apply SHA-256 to the DER binary data.&lt;/li&gt;
&lt;li&gt;Apply Base64 URL encoding to the resulting hash.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/6.BXSXGqaN_PHwY5.webp&quot; alt=&quot;Diagram: Certificate fingerprint calculation&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 2171px) 2171px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;2171&quot; height=&quot;724&quot;&gt;&lt;/p&gt;
&lt;p&gt;Once the authorization server calculates the fingerprint, it establishes the binding in one of two ways depending on the token type:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;For opaque tokens&lt;/strong&gt; — the association between the token and the certificate fingerprint is stored in the authorization server’s database. When a resource server needs to validate the token, it calls the introspection endpoint and retrieves the fingerprint from the response.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;For JWT tokens&lt;/strong&gt;— the fingerprint is embedded directly in the token using the &lt;strong&gt;Confirmation Claim&lt;/strong&gt; (&lt;code&gt;cnf&lt;/code&gt;), defined in RFC 7800 (Proof-of-Possession Key Semantics for JWTs). RFC 8705 introduces a new JWT confirmation method member: &lt;code&gt;x5t#S256&lt;/code&gt; representing the certificate’s SHA-256 fingerprint, Base64 URL-encoded. This allows resource servers to verify the binding locally without contacting the authorization server.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/7.-WMJuY7A_Z4FIfD.webp&quot; alt=&quot;Diagram: JWT access token with cnf claim containing x5t#S256&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1725px) 1725px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1725&quot; height=&quot;912&quot;&gt;&lt;/p&gt;
&lt;p&gt;An authorization server signals support for certificate-bound tokens by including &lt;code&gt;tls_client_certificate_bound_access_tokens&lt;/code&gt; in its server metadata. A client can request certificate-bound tokens by including this same parameter in its Dynamic Client Registration request.&lt;/p&gt;
&lt;h3 id=&quot;validation-at-the-resource-server&quot;&gt;Validation at the resource server&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;For JWT tokens:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Extract the fingerprint from the &lt;code&gt;cnf&lt;/code&gt; claim (&lt;code&gt;x5t#S256&lt;/code&gt;) in the JWT.&lt;/li&gt;
&lt;li&gt;Obtain the client certificate from the current mTLS connection.&lt;/li&gt;
&lt;li&gt;Calculate the SHA-256 fingerprint of that certificate using Base64 URL encoding.&lt;/li&gt;
&lt;li&gt;Compare the calculated fingerprint with the one in the &lt;code&gt;cnf&lt;/code&gt; claim.&lt;/li&gt;
&lt;li&gt;If they match, the client is the legitimate token holder. If not, return &lt;code&gt;invalid_token&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/8.D_vbCOR4_YplgA.webp&quot; alt=&quot;Diagram: JWT certificate-bound token validation flow&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1806px) 1806px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1806&quot; height=&quot;871&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;For opaque tokens:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Call the authorization server’s introspection endpoint with the token.&lt;/li&gt;
&lt;li&gt;Retrieve the certificate fingerprint from the introspection response.&lt;/li&gt;
&lt;li&gt;Obtain the client certificate from the current mTLS connection.&lt;/li&gt;
&lt;li&gt;Calculate the SHA-256 fingerprint of that certificate.&lt;/li&gt;
&lt;li&gt;Compare the calculated fingerprint with the one from the introspection response.&lt;/li&gt;
&lt;li&gt;If they match, the token is valid. If not, return invalid_token.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/9.C_QlkcdV_2cTlxc.webp&quot; alt=&quot;Diagram: Opaque certificate-bound token validation flow&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1683px) 1683px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1683&quot; height=&quot;934&quot;&gt;&lt;/p&gt;
&lt;h2 id=&quot;chapter-3-certificate-bound-tokens-and-public-clients&quot;&gt;Chapter 3: Certificate-bound tokens and public clients&lt;/h2&gt;
&lt;p&gt;One important clarification before we close, because this is where RFC 8705 is frequently misread.&lt;/p&gt;
&lt;p&gt;When an mTLS connection is established between an OAuth2 client and the authorization server, the verified certificate can serve as a client authentication method for confidential clients, server-side applications that can securely manage a private key. This was the focus of the first post.&lt;/p&gt;
&lt;p&gt;However, a public client such as a browser-based or mobile application can also establish an mTLS connection and complete the handshake. The key point here: &lt;strong&gt;the authorization server should not authenticate a public client using mTLS or any other client authentication method.&lt;/strong&gt; Public clients use mechanisms like PKCE instead, which are better suited for environments where the client cannot securely hold a private key. I’ve covered PKCE in detail in a previous post.&lt;/p&gt;
&lt;p&gt;The second important clarification: mTLS client authentication and certificate-bound tokens are independent features. RFC 8705 defines both, but they don’t require each other. Specifically:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;A client can authenticate using mTLS (Part 1 of this series) but still use bearer tokens — simpler to implement, lower security bar.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;A public client with no client authentication method can still use certificate-bound tokens, as long as it’s capable of establishing mTLS connections with both the authorization server and the resource server.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This independence is what makes RFC 8705 practical across a wide range of OAuth2 deployment scenarios, you can adopt the pieces that fit your security requirements without being forced into an all-or-nothing approach.&lt;/p&gt;
&lt;h3 id=&quot;wrapping-up&quot;&gt;Wrapping up&lt;/h3&gt;
&lt;p&gt;Across these two posts, we’ve walked through how mTLS can be applied to OAuth2 in two distinct but complementary ways. First, using the certificate-based authentication that happens during the mTLS handshake to authenticate the OAuth2 client itself, a stronger alternative to client_secret. Second, using the client certificate to bind the access token to the presenting client, so that the token is cryptographically tied to its legitimate holder and useless to anyone who intercepts it.&lt;/p&gt;
&lt;p&gt;The underlying insight from RFC 8705 is straightforward: mTLS already does a lot of the hard security work during the handshake. The specification essentially says, let’s not throw that away. Let’s reuse it for client authentication and token binding.&lt;/p&gt;
&lt;a href=&quot;https://sagarag.dev/posts/mtls-and-oauth2-client-authentication&quot; class=&quot;post-link-card&quot;&gt; &lt;span class=&quot;post-link-card__icon&quot;&gt; &lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;24&quot; height=&quot;24&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;1.75&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt; &lt;path d=&quot;M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z&quot;&gt;&lt;/path&gt; &lt;polyline points=&quot;14 2 14 8 20 8&quot;&gt;&lt;/polyline&gt; &lt;line x1=&quot;16&quot; y1=&quot;13&quot; x2=&quot;8&quot; y2=&quot;13&quot;&gt;&lt;/line&gt; &lt;line x1=&quot;16&quot; y1=&quot;17&quot; x2=&quot;8&quot; y2=&quot;17&quot;&gt;&lt;/line&gt; &lt;line x1=&quot;10&quot; y1=&quot;9&quot; x2=&quot;8&quot; y2=&quot;9&quot;&gt;&lt;/line&gt; &lt;/svg&gt; &lt;/span&gt; &lt;span class=&quot;post-link-card__body&quot;&gt; &lt;span class=&quot;post-link-card__title&quot;&gt;mTLS for OAuth2 Client Authentication: A Stronger Alternative to Shared Secrets&lt;/span&gt; &lt;span class=&quot;post-link-card__desc&quot;&gt;Learn how to apply TLS handshake–based authentication to meet OAuth 2.0 client authentication requirements&lt;/span&gt; &lt;/span&gt; &lt;span class=&quot;post-link-card__arrow&quot;&gt; &lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;18&quot; height=&quot;18&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt; &lt;path d=&quot;M5 12h14&quot;&gt;&lt;/path&gt; &lt;path d=&quot;m12 5 7 7-7 7&quot;&gt;&lt;/path&gt; &lt;/svg&gt; &lt;/span&gt; &lt;/a&gt;</content:encoded><dc:creator>Sagara Gunathunga</dc:creator><category>OAuth 2.0</category><category>mTLS</category></item><item><title>mTLS for OAuth2 Client Authentication: A Stronger Alternative to Shared Secrets</title><link>https://sagarag.dev/posts/mtls-and-oauth2-client-authentication</link><guid isPermaLink="true">https://sagarag.dev/posts/mtls-and-oauth2-client-authentication</guid><description>Shared secrets can be stolen, leaked, or brute-forced. mTLS-based client authentication uses certificates to prove private key possession. Learn how to apply TLS handshake–based authentication to meet OAuth 2.0 client authentication requirements.</description><pubDate>Fri, 25 Apr 2025 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/0.DX_MfGU__20lqux.webp&quot; alt=&quot;Diagram: X.509 certificate structure&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 2564px) 2564px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;2564&quot; height=&quot;1116&quot;&gt;&lt;/p&gt;
&lt;p&gt;Most OAuth2 deployments authenticate clients using a &lt;code&gt;client_secret&lt;/code&gt; which is a shared secret exchanged between the client and the authorization server at registration time. It works, and it’s simple to implement. But shared secrets have a fundamental weakness: &lt;strong&gt;they can be stolen, leaked, or brute-forced, and once compromised, there’s no way for the server to distinguish a legitimate client from an attacker holding the same secret&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;There’s a stronger approach, one that’s been proven in system-to-system communication for over two decades, especially in regulated industries like finance and healthcare. It’s called mutual TLS, or mTLS, and it replaces shared secrets with cryptographic certificate-based authentication.&lt;/p&gt;
&lt;p&gt;In this post, we’ll explore how mTLS authentication works at the TLS level, and how that same mechanism can be directly applied to satisfy the OAuth2 client authentication requirement giving you stronger security and better interoperability with systems where mTLS is already in use. This is the first part of a two-post series on
&lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc8705&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mutual-TLS Client Authentication and Certificate-Bound Access Tokens (RFC 8705)&lt;/a&gt;. The second part covers certificate-bound access tokens.&lt;/p&gt;
&lt;p&gt;Given the depth of this topic, I’ve broken it into three chapters.&lt;/p&gt;
&lt;h2 id=&quot;chapter-1-handshake&quot;&gt;Chapter 1: Handshake&lt;/h2&gt;
&lt;h3 id=&quot;x509-certificates&quot;&gt;X.509 certificates&lt;/h3&gt;
&lt;p&gt;Although we commonly call them “certificates,” the technically accurate term is X.509 certificates, named after the X.509 standard introduced by the International Telecommunication Union (ITU) as part of the X.500 directory services in 1988.&lt;/p&gt;
&lt;p&gt;The diagram below shows a simplified view of a typical certificate, highlighting the key elements relevant to this discussion.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/1.cmQfv25f_Z1hjd9J.webp&quot; alt=&quot;Diagram: X.509 certificate structure&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 2148px) 2148px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;2148&quot; height=&quot;732&quot;&gt;&lt;/p&gt;
&lt;p&gt;One important concept to understand upfront is the &lt;strong&gt;Distinguished Name (DN)&lt;/strong&gt; — a string composed of attribute-value pairs that acts as a unique identifier for entities such as certificate authorities, servers, or applications within X.509 certificates.&lt;/p&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light nord&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#d8dee9ff;--shiki-light-bg:#fff;--shiki-dark-bg:#2e3440ff;overflow-x:auto;white-space:pre-wrap;word-wrap:break-word&quot; tabindex=&quot;0&quot; data-language=&quot;txt&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;CN = DigiCert Global G2 TLS RSA SHA256 2020 CA, O = DigiCert Inc, C = US&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This DN is made up of three key attributes: &lt;strong&gt;CN (Common Name), O (Organization), and C (Country)&lt;/strong&gt;. Together, they form a unique identifier that can represent the issuer or subject in a certificate.&lt;/p&gt;
&lt;p&gt;Let’s break down the key components:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;🏷️ Issuer&lt;/strong&gt; — identifies the entity that issued the certificate, represented as a Distinguished Name (DN) following the LDAP protocol.&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light nord&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#d8dee9ff;--shiki-light-bg:#fff;--shiki-dark-bg:#2e3440ff;overflow-x:auto;white-space:pre-wrap;word-wrap:break-word&quot; tabindex=&quot;0&quot; data-language=&quot;txt&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;CN = DigiCert Global G2 TLS RSA SHA256 2020 CA, O = DigiCert Inc, C = US&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;CN = GTS CA 1C3, O = Google Trust Services LLC, C = US&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;🧾 Subject&lt;/strong&gt; — identifies the entity the certificate was issued to. Like the issuer, this is typically a DN or a &lt;strong&gt;Subject Alternative Name (SAN)&lt;/strong&gt;.&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light nord&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#d8dee9ff;--shiki-light-bg:#fff;--shiki-dark-bg:#2e3440ff;overflow-x:auto;white-space:pre-wrap;word-wrap:break-word&quot; tabindex=&quot;0&quot; data-language=&quot;txt&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;CN = *.wso2.com, O = WSO2, Inc, L = Mountain View, ST = California, C = US&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;CN = *.google.com&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;🔑 Public Key&lt;/strong&gt; — the public key corresponding to the private key held by the subject. Used in the TLS handshake for encryption and key exchange.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;🖋️ Signature&lt;/strong&gt; — the certificate’s digital signature, created by the issuer using its private key. The certificate content is encoded, hashed, and that hash is signed ensuring both integrity and authenticity.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Most certificates you encounter in the wild are issued by a &lt;strong&gt;Certificate Authority (CA)&lt;/strong&gt; as part of Public Key Infrastructure (PKI). But it’s also straightforward to generate &lt;strong&gt;self-signed certificates&lt;/strong&gt;, particularly for internal use or server-to-server communication. The key difference: with self-signed certificates, the issuer and subject are the same entity.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;🔎 Example 1 — PKI-issued certificate (from the WSO2 website):&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Issuer&lt;/strong&gt;: &lt;code&gt;CN = DigiCert Global, O = DigiCert Inc, C = US&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Subject&lt;/strong&gt;: &lt;code&gt;CN = *.wso2.com, O = WSO2, Inc, L = Mountain View, ST = California, C = US&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;🔎 Example 2 — Self-signed certificate (from WSO2 Identity Server):&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Issuer&lt;/strong&gt;: &lt;code&gt;CN = localhost, OU = WSO2, O = WSO2, L = Mountain View, ST = CA, C = US&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Subject&lt;/strong&gt;: &lt;code&gt;CN = localhost, OU = WSO2, O = WSO2, L = Mountain View, ST = CA, C = US&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;certificate-validation&quot;&gt;Certificate validation&lt;/h3&gt;
&lt;p&gt;The approach to validating a certificate depends on whether it’s CA-issued or self-signed.
For CA-issued certificates, the process is certificate chain validation. The certificate’s signature is verified using the issuer’s public key, and the issuer’s DN in the current certificate is checked against the subject’s DN in the next certificate in the chain. Validation starts at the leaf certificate and works up through intermediate certificates to the root certificate, which provides the trust anchor for the entire chain. Root certificates come from a small number of highly trusted CAs recognized by browsers and operating systems.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/2.M5WiY5VU_ZKK90n.webp&quot; alt=&quot;Diagram: Certificate chain validation&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1891px) 1891px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1891&quot; height=&quot;831&quot;&gt;&lt;/p&gt;
&lt;p&gt;For self-signed certificates, there’s no universal validation method, the approach depends on the use case. Web browsers warn users when they encounter a self-signed certificate and may allow manual inspection and acceptance. Tools like cURL offer &lt;code&gt;--insecure&lt;/code&gt; (&lt;code&gt;-k&lt;/code&gt;) to bypass verification, though this should be used with care.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/3.w9IqL3Zz_29EC8I.webp&quot; alt=&quot;Screenshot: Browser self-signed certificate warning&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 663px) 663px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;663&quot; height=&quot;584&quot;&gt;&lt;/p&gt;
&lt;p&gt;Non-browser applications, such as those involved in system-to-system communication, can explicitly trust a self-signed certificate by presenting a copy of it before initiating communication, either by directly uploading the certificate in PEM or another format, or by providing a URL where the certificate content can be retrieved. In OAuth 2.0 and OpenID Connect, the JWKS endpoint is commonly used for this purpose, exposing an entity’s public keys through a network-accessible URL.&lt;/p&gt;
&lt;h2 id=&quot;certificate-fingerprints&quot;&gt;Certificate fingerprints&lt;/h2&gt;
&lt;p&gt;Before moving to the handshake, one more concept worth covering: the &lt;strong&gt;certificate fingerprint&lt;/strong&gt; (or &lt;strong&gt;thumbprint&lt;/strong&gt;). If you’ve ever viewed a certificate in a browser, you’ve likely seen this small string. Importantly, it’s not part of the certificate itself, and calculated externally and used to uniquely reference a certificate. The calculation process:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;If the certificate is in PEM format (Base64-encoded ASCII), convert it to DER format (binary encoding).&lt;/li&gt;
&lt;li&gt;Apply a hash function such as SHA-256 to the DER binary data.&lt;/li&gt;
&lt;li&gt;Format the resulting hash into a human-readable fingerprint.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This fingerprint concept becomes central in the second part of this series when we cover certificate-bound tokens.&lt;/p&gt;
&lt;h3 id=&quot;tls-and-mtls-handshakes&quot;&gt;TLS and mTLS handshakes&lt;/h3&gt;
&lt;p&gt;The first step in establishing a secure, encrypted channel between two entities is the &lt;strong&gt;TLS handshake&lt;/strong&gt;. Let’s break it down into two roles: the client (the entity initiating communication to obtain a service) and the server (the entity listening on a network port to provide it).&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/4.D3DhNoqO_Z27ouEo.webp&quot; alt=&quot;Diagram: TLS vs mTLS handshake comparison&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1707px) 1707px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1707&quot; height=&quot;921&quot;&gt;&lt;/p&gt;
&lt;p&gt;In a standard TLS handshake, the server sends its certificate to the client in step 3 using the Certificate message. The client validates the server’s certificate and confirms the server’s identity, this is one-way verification.
mTLS adds a second layer. In step 5, after the client has verified the server’s certificate, the server sends a &lt;code&gt;CertificateRequest&lt;/code&gt; message asking the client to present its own certificate. The client responds with its certificate, and the server validates it using the same methods discussed earlier. After step 7, the server has authenticated the client, and the client’s identity is now established.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/5.C5U_4_My_Z20pwDl.webp&quot; alt=&quot;Diagram: mTLS handshake&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1774px) 1774px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1774&quot; height=&quot;887&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;In short: TLS authenticates the server. mTLS authenticates both parties.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;One additional message in the mTLS flow deserves attention: the &lt;strong&gt;CertificateVerify&lt;/strong&gt; message sent in step 9. Its purpose is to prove that the client actually possesses the private key corresponding to the certificate it presented, not just a copy of someone else’s certificate. The process:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Collect all handshake messages exchanged between client and server up to this point.&lt;/li&gt;
&lt;li&gt;Apply SHA-256 to those messages to generate a hash value.&lt;/li&gt;
&lt;li&gt;Sign the hash using the client’s private key, this signed value becomes the CertificateVerify message.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/6.DMg1STuE_YjVvW.webp&quot; alt=&quot;Diagram: CertificateVerify message generation&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 2171px) 2171px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;2171&quot; height=&quot;724&quot;&gt;&lt;/p&gt;
&lt;p&gt;When the server receives this message, it uses the client’s public key (from the client’s certificate) to verify the signature. If the signature is valid, the server confirms the client holds the correct private key. This proof-of-possession mechanism is exactly what we’ll build on in the certificate-bound tokens post.&lt;/p&gt;
&lt;h2 id=&quot;chapter-2-oauth2-client-authentication&quot;&gt;Chapter 2: OAuth2 client authentication&lt;/h2&gt;
&lt;p&gt;In OAuth2, a client is an entity that obtains an access token from an authorization server on behalf of an end user. Clients fall into two categories:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Confidential clients&lt;/strong&gt; — such as server-side web applications that can securely store and manage credentials.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Public clients&lt;/strong&gt; — such as browser-based or mobile applications that cannot securely store and manage credentials.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The OAuth2 specification requires authorization servers to authenticate confidential clients before issuing tokens. The spec defines client authentication as an abstract requirement, giving implementers flexibility in how they meet it, but it also defines one concrete method: a shared secret called &lt;code&gt;client_secret&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;During client registration, the client and authorization server agree on the client_secret value. When the client makes a token request, it authenticates by providing this secret, most commonly via the &lt;strong&gt;HTTP Authorization&lt;/strong&gt; header.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/7.zUtRKDiu_Z1zproy.webp&quot; alt=&quot;Diagram: client_secret-based authentication flow&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1507px) 1507px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1507&quot; height=&quot;1044&quot;&gt;&lt;/p&gt;
&lt;p&gt;Despite its widespread adoption, shared secret authentication has limitations. Secrets can be leaked through logs, intercepted in transit, or exposed in code repositories. For use cases requiring higher assurance, particularly in system-to-system communication in regulated environments.&lt;/p&gt;
&lt;h2 id=&quot;chapter-3-mtls-for-oauth2-client-authentication&quot;&gt;Chapter 3: mTLS for OAuth2 client authentication&lt;/h2&gt;
&lt;p&gt;Here’s where the two threads come together.&lt;/p&gt;
&lt;p&gt;When an OAuth2 client communicates with an authorization server, it should use HTTP over TLS, the OAuth2 client acts as the TLS client, and the authorization server acts as the TLS server. When mTLS is used, the client has already been authenticated during the handshake via its certificate at the TLS layer.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The question is: can we use that authentication, already established at the TLS level, to satisfy the OAuth2 client authentication requirement?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The answer is yes, and that’s exactly what the first part of R &lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc8705&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mutual-TLS Client Authentication and Certificate-Bound Access Tokens (RFC 8705)&lt;/a&gt; addresses. mTLS-based OAuth2 client authentication is more secure than shared secret authentication because it relies on asymmetric cryptography and proof of private key possession, rather than a reusable secret that can be stolen.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/8.C8AdRUWO_1Ti4wW.webp&quot; alt=&quot;Diagram: mTLS-based OAuth2 client authentication flow&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1694px) 1694px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1694&quot; height=&quot;929&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;pki-certificate-based-authentication&quot;&gt;PKI certificate-based authentication&lt;/h3&gt;
&lt;p&gt;When a PKI certificate is used in the mTLS handshake, the authorization server has already verified the certificate through certificate chain validation. It can then compare the subject of that certificate against the subject information registered by the OAuth2 client during registration.&lt;/p&gt;
&lt;p&gt;Just as a client registers its name and redirect URI during client registration, it can also register its &lt;strong&gt;Distinguished Name (DN)&lt;/strong&gt; or &lt;strong&gt;Subject Alternative Name (SAN)&lt;/strong&gt;. The authorization server uses this registered value to authenticate the client by matching it against the subject in the presented certificate. One subject value should map to exactly one OAuth2 client.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/9.HSJlEYKQ_Ay8ID.webp&quot; alt=&quot;Diagram: mTLS based client Authentication&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1833px) 1833px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1833&quot; height=&quot;858&quot;&gt;&lt;/p&gt;
&lt;p&gt;A key advantage of PKI certificates is that clients can rotate certificates freely, as long as the new certificate carries the same subject value. Authorization servers may optionally check certificate revocation status as well.&lt;/p&gt;
&lt;p&gt;Here is a sample token request using mTLS client authentication:&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light nord&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#d8dee9ff;--shiki-light-bg:#fff;--shiki-dark-bg:#2e3440ff;overflow-x:auto;white-space:pre-wrap;word-wrap:break-word&quot; tabindex=&quot;0&quot; data-language=&quot;bash&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#6F42C1;--shiki-dark:#88C0D0&quot;&gt;curl&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#A3BE8C&quot;&gt; --location&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#A3BE8C&quot;&gt; --request&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt; POST&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;https://localhost:9443/oauth2/token&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#EBCB8B&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#A3BE8C&quot;&gt;  --header&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;Content-Type: application/x-www-form-urlencoded&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#EBCB8B&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#A3BE8C&quot;&gt;  --data-urlencode&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;code=be728f21-8b3b-3c90-98e3-66188a647407&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#EBCB8B&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#A3BE8C&quot;&gt;  --data-urlencode&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;grant_type=authorization_code&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#EBCB8B&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#A3BE8C&quot;&gt;  --data-urlencode&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;client_id=QGR5np4F_OYGSH8L5F3klJJPrUEa&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#EBCB8B&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#A3BE8C&quot;&gt;  --data-urlencode&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#A3BE8C&quot;&gt;redirect_uri=https://myapp/login&lt;/span&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#ECEFF4&quot;&gt;&amp;#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;An authorization server advertises support for PKI certificate-based mTLS authentication by including &lt;code&gt;tls_client_auth&lt;/code&gt; in its server metadata.&lt;/p&gt;
&lt;p&gt;RFC 8705 defines the following registration parameters for specifying the subject identity the authorization server should match against during authentication:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;tls_client_auth_subject_dn&lt;/code&gt; — matches the full Subject DN of the client certificate. Use this when the client is identified by its full Distinguished Name.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;tls_client_auth_san_dns&lt;/code&gt; — matches a DNS SAN entry in the client certificate. Useful for matching domain names tied to the client identity.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;tls_client_auth_san_uri&lt;/code&gt; — matches a URI SAN entry. Often used when the client is identified by a service URL.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;tls_client_auth_san_ip&lt;/code&gt; — matches an IP address SAN entry. Common in internal network setups where services are identified by IP.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;tls_client_auth_san_email&lt;/code&gt; — matches an email address SAN entry. Useful when the client identity is tied to an email address.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;self-signed-certificate-based-authentication&quot;&gt;Self-signed certificate-based authentication&lt;/h3&gt;
&lt;p&gt;When self-signed certificates are used, the authorization server can allow the OAuth2 client to upload its certificate directly in PEM or JWKS format, or provide a JWKS endpoint URL during registration. When the client initiates a token request over mTLS, the authorization server matches the certificate from the mTLS connection against the registered certificate details.&lt;/p&gt;
&lt;p&gt;If the full certificate is registered directly, the authorization server compares it against the mTLS client certificate. If a JWKS endpoint URL is registered instead, the server fetches the certificate from that endpoint for comparison.&lt;/p&gt;
&lt;p&gt;One practical consideration: if the certificate is uploaded directly, any rotation requires updating the registration in the authorization server. If registered as a JWKS endpoint URL reference, certificate rotation can happen transparently without any changes to the client registration.&lt;/p&gt;
&lt;p&gt;An authorization server advertises support for self-signed certificate mTLS authentication by including &lt;code&gt;self_signed_tls_client_auth&lt;/code&gt; in its server metadata. RFC 8705 uses the existing &lt;code&gt;jwks&lt;/code&gt; and &lt;code&gt;jwks_uri&lt;/code&gt; DCR parameters for certificate registration, and no new registration parameters are introduced for the self-signed case.&lt;/p&gt;
&lt;h2 id=&quot;deployment-considerations&quot;&gt;Deployment considerations&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc8705&quot; target=&quot;_blank&quot; rel=&quot;noopener noreferrer&quot;&gt;Mutual-TLS Client Authentication and Certificate-Bound Access Tokens (RFC 8705)&lt;/a&gt; doesn’t prescribe a deployment architecture, but there are two scenarios you’ll encounter in practice, and the second one has a challenge worth understanding.&lt;/p&gt;
&lt;h3 id=&quot;scenario-1-direct-mtls-connection&quot;&gt;Scenario 1: Direct mTLS connection&lt;/h3&gt;
&lt;p&gt;The OAuth2 client establishes a direct mTLS connection to the authorization server. This is straightforward, especially with Identity-as-a-Service (IDaaS) providers, and relies on pre-configured TLS settings on both ends.&lt;/p&gt;
&lt;h3 id=&quot;scenario-2-mtls-terminated-at-a-reverse-proxy&quot;&gt;Scenario 2: mTLS terminated at a reverse proxy&lt;/h3&gt;
&lt;p&gt;This is the more common pattern in on-premise authorization server deployments. A reverse proxy (such as Nginx) handles the mTLS handshake and terminates the mTLS connection. Only clients that successfully complete the mTLS handshake can reach the authorization server behind it. The reverse proxy typically sits in a DMZ zone while the authorization server is in a restricted zone, but both are within the same trust domain. The reverse proxy can logically be considered an internal component of the authorization server deployment.&lt;/p&gt;
&lt;p&gt;The challenge here: the authorization server never participates in the mTLS handshake directly, so it doesn’t have native access to the client certificate.&lt;/p&gt;
&lt;p&gt;The solution that has become common across IAM vendors is simple and practical: after terminating the mTLS connection, the reverse proxy forwards the client certificate to the authorization server as an HTTP header. Most modern reverse proxies support this natively. The specific header name isn’t standardized, for example, WSO2 Identity Server defaults to &lt;code&gt;x-wso2-mtls-cert&lt;/code&gt;, which is configurable. The authorization server reads this header and treats it as the authenticated client certificate.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sagarag.dev/_astro/10.D7FUNXTy_VkYPF.webp&quot; alt=&quot;Diagram: Reverse proxy mTLS termination with certificate forwarding&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; fetchpriority=&quot;auto&quot; sizes=&quot;(min-width: 1858px) 1858px, 100vw&quot; style=&quot;--fit: cover; --pos: center;&quot; data-astro-image=&quot;constrained&quot; width=&quot;1858&quot; height=&quot;846&quot;&gt;&lt;/p&gt;
&lt;h2 id=&quot;where-this-leads&quot;&gt;Where this leads&lt;/h2&gt;
&lt;p&gt;In this post, we covered how authentication works in the mTLS protocol and how that same mechanism can be applied directly to OAuth2 client authentication giving you a more secure and more interoperable alternative to shared secrets.&lt;/p&gt;
&lt;p&gt;In Part 2, we go further: exploring how the client certificate used in mTLS can be used to bind the access token itself to the presenting client, making it useless to anyone who intercepts or steals it. That’s the certificate-bound tokens story.&lt;/p&gt;
&lt;a href=&quot;https://sagarag.dev/posts/mtls-and-oauth2-certificate-bound-tokens&quot; class=&quot;post-link-card&quot;&gt; &lt;span class=&quot;post-link-card__icon&quot;&gt; &lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;24&quot; height=&quot;24&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;1.75&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt; &lt;path d=&quot;M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z&quot;&gt;&lt;/path&gt; &lt;polyline points=&quot;14 2 14 8 20 8&quot;&gt;&lt;/polyline&gt; &lt;line x1=&quot;16&quot; y1=&quot;13&quot; x2=&quot;8&quot; y2=&quot;13&quot;&gt;&lt;/line&gt; &lt;line x1=&quot;16&quot; y1=&quot;17&quot; x2=&quot;8&quot; y2=&quot;17&quot;&gt;&lt;/line&gt; &lt;line x1=&quot;10&quot; y1=&quot;9&quot; x2=&quot;8&quot; y2=&quot;9&quot;&gt;&lt;/line&gt; &lt;/svg&gt; &lt;/span&gt; &lt;span class=&quot;post-link-card__body&quot;&gt; &lt;span class=&quot;post-link-card__title&quot;&gt;Certificate-Bound Access Tokens: How mTLS Makes Stolen Tokens Useless&lt;/span&gt; &lt;span class=&quot;post-link-card__desc&quot;&gt;Certificate-bound tokens bind the access token to the client certificate used in the mTLS handshake, so even if a token is intercepted, it&amp;#39;s worthless.&lt;/span&gt; &lt;/span&gt; &lt;span class=&quot;post-link-card__arrow&quot;&gt; &lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;18&quot; height=&quot;18&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt; &lt;path d=&quot;M5 12h14&quot;&gt;&lt;/path&gt; &lt;path d=&quot;m12 5 7 7-7 7&quot;&gt;&lt;/path&gt; &lt;/svg&gt; &lt;/span&gt; &lt;/a&gt;</content:encoded><dc:creator>Sagara Gunathunga</dc:creator><category>OAuth 2.0</category><category>mTLS</category></item><item><title>PKCE Explained: How It Stops OAuth Code Interception</title><link>https://sagarag.dev/posts/secure-oauth2-a-simple-story-of-two-keys-pkce</link><guid isPermaLink="true">https://sagarag.dev/posts/secure-oauth2-a-simple-story-of-two-keys-pkce</guid><description>How PKCE (RFC 7636) stops authorization code interception in OAuth 2.0: code_verifier, code_challenge, S256, and a hands-on walkthrough for public clients.</description><pubDate>Wed, 23 Apr 2025 23:21:33 GMT</pubDate><content:encoded>&lt;p&gt;This is the final post in my &lt;em&gt;Secure OAuth2&lt;/em&gt; blog series. I &lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;began&lt;/a&gt; this series by examining the security gaps in the OAuth2 authorization code grant type, with the goal of introducing and advocating for a set of complementary specifications that have been developed over time to strengthen the flow — namely JAR, PAR, and JARM. Over the last four posts, we looked into each of these specs in detail, along with hands-on examples to help you apply them in practice using &lt;a href=&quot;https://wso2.com/asgardeo/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Asgardeo&lt;/a&gt; — cloud identity solution.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Secure OAuth2 : Is Authorization Code Grant Type Secure Enough?&lt;/strong&gt;&lt;br&gt;
_The authorization code grant type is generally considered as the most secure, widely used and commonly recommended…_sagarag.medium.com&lt;/a&gt;&lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In this final post, I want to talk about &lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc7636&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Proof Key for Code Exchange (PKCE)&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;You’re probably already familiar with how the OAuth2 authorization code flow works: it involves two calls to the authorization server. First, the client application sends an authorization request via the user agent (typically a browser or app), and in return, it receives an authorization code. Then, in the second call, the client exchanges that code for tokens — such as an access token or ID token. The important point here is that &lt;strong&gt;without a valid authorization code, the client cannot obtain tokens&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*m3aguRQJ3Txo5P42jHqdMw.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;_Now, here’s the key question:&lt;br&gt;
_&lt;strong&gt;What if a malicious actor somehow gets hold of that authorization code — could they use it to get a token?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The short answer is: &lt;em&gt;it depends&lt;/em&gt;. And we can’t completely rule out the possibility.&lt;/p&gt;
&lt;p&gt;Let’s break it down.&lt;/p&gt;
&lt;p&gt;If the application is a traditional server-side app — what we call a &lt;strong&gt;confidential client&lt;/strong&gt; — it must authenticate itself when making the token request. Without the proper credentials, it won’t get a token. So even if someone manages to steal an authorization code, they wouldn’t be able to do much without the app’s credentials, making this a relatively safe scenario.&lt;/p&gt;
&lt;p&gt;But that’s not the case for &lt;strong&gt;public clients&lt;/strong&gt; — like mobile apps or single-page applications (SPAs) that run in the browser. These apps can’t securely store credentials, and therefore aren’t expected to authenticate themselves when calling the token endpoint. If an authorization code from such an app is intercepted, the attacker &lt;em&gt;could&lt;/em&gt; exchange it for tokens using information like the &lt;code&gt;client_id&lt;/code&gt; and &lt;code&gt;redirect_uri&lt;/code&gt;, which are often publicly visible in the original authorization request.&lt;/p&gt;
&lt;p&gt;For instance, if you build mobile apps on Android or iOS, you’ll often register a custom URI scheme — such as &lt;code&gt;myapp://callback&lt;/code&gt;— so your application can receive the authorization code after a user signs in. It’s a convenient feature, but it has a critical weakness: &lt;strong&gt;multiple apps can register the same URI&lt;/strong&gt;. An attacker could publish a malicious app that also claims &lt;code&gt;myapp://callback&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Here’s how the attack plays out:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Your real app initiates the OAuth flow, sending the user to the authorization server.&lt;/li&gt;
&lt;li&gt;After login, the server redirects to &lt;code&gt;myapp://callback?code=…&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Because two apps both handle that URI, the operating system prompts the user (or defaults) to choose which app should open the link.&lt;/li&gt;
&lt;li&gt;If the malicious app is selected, it receives the authorization code instead of your app.&lt;/li&gt;
&lt;li&gt;The attacker’s app then calls the token endpoint — using its own credentials if required — to exchange the stolen code for valid tokens.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;By the time your legitimate app sees the callback, the attacker already holds the tokens and can impersonate the user.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*VgDBnRs4arbozMhHSGKF7w.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;You can mitigate this with features like &lt;a href=&quot;https://developer.android.com/training/app-links&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Android App Links&lt;/a&gt; or &lt;a href=&quot;https://developer.apple.com/documentation/xcode/allowing-apps-and-websites-to-link-to-your-content/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;iOS Universal Links&lt;/a&gt; but the best approach would be to harden the OAuth2 flow itself to be resistant to such issues.&lt;/p&gt;
&lt;h4 id=&quot;so-what-can-wedo&quot;&gt;&lt;strong&gt;So what can we do?&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;One intuitive idea would be to somehow &lt;strong&gt;ensure that the same application that made the original authorization request is also the one making the token reques&lt;/strong&gt;t — using some kind of a secret. But again, public clients can’t securely store secrets, which is the core issue here.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;That’s exactly the problem that&lt;/strong&gt; &lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc7636&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;PKCE&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;(pronounced “pixy”) is designed to solve based on cryptographic hashing.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;At the heart of PKCE is the use of a hash function. Hash functions take an input and produce a fixed-length string of characters — called a hash — that appears random and is unique to that input. A key property of hash functions is that even a small change in the input produces a completely different hash, and most importantly, they are one-way functions — meaning you can’t reverse-engineer the original input from the hash.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*3RLOJ5jZ63V6UOfoD9MzKg.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;PKCE works by requiring the client application to first generate a cryptographically random string typically between 43 to 128 characters that’s hard to guess. Then this random string is encoded using base64url schema to derive a string known as the &lt;strong&gt;code verifier&lt;/strong&gt;. The client then applies a secure hash algorithm like SHA-256 to the code verifier and encodes the result using Base64 URL encoding. This final value is called the &lt;strong&gt;code challenge&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*t0lUsA5Avg-oz5Wpc54rpg.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;At this point, the client holds two values: the &lt;strong&gt;code verifier&lt;/strong&gt; and the &lt;strong&gt;code challenge.&lt;/strong&gt; The authorization request begins with the client sending the code challenge to the authorization server. For this, the PKCE specification introduces an authorization request parameter called &lt;code&gt;code_challenge&lt;/code&gt;. A simplified example of such a request is shown below.&lt;/p&gt;
&lt;p&gt;Note that to keep things simple, I’ve used the standard authorization request here. But it’s entirely possible — and recommended in high-security environments — &lt;strong&gt;to include this parameter inside a signed Request Object (as per the JAR specification) or within a PAR request&lt;/strong&gt;, both of which we’ve already discussed in previous posts.&lt;/p&gt;
&lt;p&gt;Once the authorization server receives the request, it processes it and stores the &lt;code&gt;code_challenge&lt;/code&gt; value. If everything is valid and the user successfully authenticates, the server issues an authorization code to the client application. In the following diagram, I’ve given a sample authorization request with the &lt;code&gt;code_challenge&lt;/code&gt; parameter. In addition to that, you can also see the optional &lt;code&gt;code_challenge_method&lt;/code&gt; parameter in the request. This parameter is used to specify the code verifier transformation method, which is usually set to &lt;code&gt;S256&lt;/code&gt; implying SHA-256 hash algorithm.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*IANQrjoAf5EBIaDRpLuzOg.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;One important point to highlight here is that the PKCE spec defines another transformation method called &lt;code&gt;&quot;plain&quot;&lt;/code&gt;. In that case, &lt;code&gt;code_challenge = code_verifier&lt;/code&gt;. You shouldn’t use the &lt;code&gt;&quot;plain&quot;&lt;/code&gt; transformation, as it doesn’t use the hash algorithm discussed above and doesn’t provide adequate security strengthening to the flow.&lt;/p&gt;
&lt;p&gt;In the next phase — during the token request — the client sends the authorization code &lt;em&gt;along with&lt;/em&gt; the previously generated code verifier. For this, the PKCE specification introduces another parameter, &lt;code&gt;code_verifier&lt;/code&gt;, in the token request. A sample token request showing how to include this parameter is provided below.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*FuApiLk5TCOSnwWDXg-I1A.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Once PKCE is enabled, the complete authorization code grant flow looks like the following diagram.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*0WFkEnVpdzpQhC2ELO_2dg.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Here’s where the interesting validation step happens. The authorization server now hashes the &lt;code&gt;code_verifier&lt;/code&gt; using the same algorithm and compares it against the stored &lt;code&gt;code_challenge&lt;/code&gt; from the initial authorization request. If the values match, it confirms that the same client made both the authorization and token requests. Even if an attacker intercepted the authorization code, they wouldn’t be able to use it—because they wouldn’t have access to the original code verifier, which was never shared at that point.&lt;/p&gt;
&lt;h4 id=&quot;pkce-metadata-parameters-anddcr&quot;&gt;PKCE Metadata Parameters and DCR&lt;/h4&gt;
&lt;p&gt;The next question we should find an answer to is how does a client application discover whether a particular authorization server supports the PKCE extension — and if so, which method should be used. The OAuth 2.0 Authorization Server Metadata specification defines a metadata parameter called &lt;code&gt;code_challenge_methods_supported&lt;/code&gt; to imply PKCE support, and this parameter can be set to either S256 or plain.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/how-do-you-discover-the-oauth2-server-configuration&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;How do you discover the OAuth2 server configuration?&lt;/strong&gt;&lt;br&gt;
_This is the 2nd post of my blog series about the OAuth2; reading the first post may help you to understand this current…_sagarag.medium.com&lt;/a&gt;&lt;a href=&quot;https://sagarag.dev/posts/how-do-you-discover-the-oauth2-server-configuration&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Once the authorization server’s support for PKCE is discovered by the client application, it can use the &lt;code&gt;enforce_pkce&lt;/code&gt; and &lt;code&gt;code_challenge_method&lt;/code&gt; DCR parameters during the client registration to inform the authorization server that the client expects to enforce PKCE and which transformation method it supports.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/how-to-register-and-manage-oauth2-clients&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;How to register and manage OAuth2 clients?&lt;/strong&gt;&lt;br&gt;
_In the first post of this blog series about the OAuth2, I provided a comprehensive overview of the OAuth2 core…_sagarag.medium.com&lt;/a&gt;&lt;a href=&quot;https://sagarag.dev/posts/how-to-register-and-manage-oauth2-clients&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Compared to the other specifications I’ve discussed in this series, PKCE stands out as the most widely adopted. The good news is that support for PKCE is already built into most modern languages, frameworks, and SDKs. In many cases, it’s enabled by default or can be turned on with just a simple configuration. For instance, the &lt;a href=&quot;https://github.com/asgardeo/asgardeo-auth-spa-sdk&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Asgardeo React SDK&lt;/a&gt; has PKCE enabled by default, making it easier for developers to follow best practices without much extra effort. What’s also worth noting is that the OAuth 2.1 draft specification goes even further — it recommends using PKCE for &lt;em&gt;all&lt;/em&gt; types of applications, not just public clients. This shows how important PKCE has become in securing the authorization code flow.&lt;/p&gt;
&lt;h3 id=&quot;pkce-inaction&quot;&gt;PKCE in Action&lt;/h3&gt;
&lt;p&gt;For this demo, I’ll be using &lt;a href=&quot;https://wso2.com/asgardeo/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Asgardeo&lt;/strong&gt;&lt;/a&gt; — a cloud identity service by WSO2 which comes with a generous free tier, making it a great option to try out your identity use cases. &lt;a href=&quot;https://wso2.com/asgardeo/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Asgardeo&lt;/strong&gt;&lt;/a&gt; fully supports the &lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc7636&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;PKCE&lt;/a&gt; extension and enable it by default in &lt;a href=&quot;https://wso2.com/identity-and-access-management/developer/applications/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Asgardeo SDKs&lt;/a&gt; so you don’t need to put any extra step to use PKCE with your applications.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*poeiTeO2RTB7CDjg.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step 1 — Configure Asgardeo&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;If you don’t already have an Asgardeo account, you can sign up &lt;a href=&quot;https://wso2.com/asgardeo/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;. Once you’re logged in:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create a new &lt;strong&gt;Traditional Web Application&lt;/strong&gt; from the left-side menu and Keep &lt;strong&gt;OpenID Connect&lt;/strong&gt; selected as the protocol (this is the default). For the &lt;strong&gt;Authorized redirect URLs&lt;/strong&gt;, enter &lt;code&gt;[https://myapp.io/login](https://myapp.io/login)&lt;/code&gt; as the value. Then save the application settings.&lt;/li&gt;
&lt;li&gt;Next follow &lt;a href=&quot;https://wso2.com/asgardeo/docs/guides/users/manage-users/#onboard-single-user&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;this guide&lt;/a&gt; to create a test user, which you’ll use later in this flow.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Step 2 — Set Up Postman&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Next, you’ll need to configure Postman. First, Download &lt;a href=&quot;https://www.postman.com/warped-eclipse-61593/workspace/public/collection/25632817-3c15b3bb-1892-41d1-b273-379471c24cb9?action=share&amp;#x26;creator=25632817&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;this Postman collection&lt;/a&gt; for this demo. Open the collection and update the collection variables with the following values, which you can copy from your Asgardeo application:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;[authorize_ep](https://myapp.io/login)&lt;/code&gt; — Token Endpoint URL from the &lt;strong&gt;Info&lt;/strong&gt; tab.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;token_ep&lt;/code&gt; — Authorization Endpoint URL from the &lt;strong&gt;Info&lt;/strong&gt; tab.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;client_id&lt;/code&gt; — Client ID &lt;strong&gt;protocol&lt;/strong&gt; tab.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;client_secret&lt;/code&gt; — Client Secret &lt;strong&gt;protocol&lt;/strong&gt; tab.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Step 3 — Execute the Flow&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;First, execute the “Generate-PKCE” request in the above Postman collection, this call would’t go anywhere, it just uses to generate c&lt;strong&gt;ode verifier&lt;/strong&gt; and &lt;strong&gt;code challenge&lt;/strong&gt; to be used in the next step.&lt;/li&gt;
&lt;li&gt;Since Postman can’t simulate browser-based redirects, we’ll take a small manual step here. Open the &lt;strong&gt;Code Snippet&lt;/strong&gt; tab for each request &lt;em&gt;( e.g — pkce-authz-code-grant-Browser&lt;/em&gt; &lt;em&gt;)&lt;/em&gt; from the right-hand menu in Postman and select &lt;strong&gt;cURL&lt;/strong&gt; from the dropdown. Then copy the &lt;code&gt;location&lt;/code&gt; value from the cURL snippet. Finally paste that URL into your browser’s address bar and hit Enter.&lt;/li&gt;
&lt;li&gt;You should now be redirected to Asgardeo’s login screen. Enter the credentials of the test user you created earlier. If authentication is successful, you’ll be redirected to the callback URL with JWT authorization response which you can decode from your prefred JWT decoder tool.&lt;/li&gt;
&lt;li&gt;Go back to Postman and open the &lt;em&gt;pkce-authz-code-token&lt;/em&gt; request. Paste the copied &lt;code&gt;code&lt;/code&gt; into the &lt;code&gt;code&lt;/code&gt; parameter in the request body and send the request. If everything is set up correctly, you should receive a valid token from Asgardeo.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Note&lt;/em&gt;&lt;/strong&gt; — as an exercise create a public client application in Asgardeo and try out the PKCE , you can refer &lt;a href=&quot;https://wso2.com/asgardeo/docs/guides/authentication/oidc/implement-auth-code-with-pkce/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Asgardeo docs&lt;/a&gt; as well.&lt;/p&gt;
&lt;p&gt;With that, we’re reaching the end of this blog series where we discussed the security implications of the OAuth2 authorization code grant type and how complementary specifications developed over time can be used to mitigate these issues. Stay tuned for the next post with a new topic!&lt;/p&gt;
&lt;h3 id=&quot;other-posts-in-the-secure-oauth2series&quot;&gt;Other posts in the secure OAuth2 series&lt;/h3&gt;
&lt;p&gt;Read the other posts in &lt;strong&gt;Secure OAuth2&lt;/strong&gt; series.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Secure OAuth2 : Is Authorization Code Grant Type Secure Enough?&lt;/strong&gt;&lt;br&gt;
_The authorization code grant type is generally considered as the most secure, widely used and commonly recommended…_sagarag.medium.com&lt;/a&gt;&lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/jwt-secured-authorization-request&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Secure OAuth2 (Part -2): Put it in a JAR (JWT-Secured Authorization Request)&lt;/strong&gt;&lt;br&gt;
_In my last post — which I published almost a year ago — I explored whether the authorization code grant type truly…_sagarag.medium.com&lt;/a&gt;&lt;a href=&quot;https://sagarag.dev/posts/jwt-secured-authorization-request&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/push-authorization-request-par-to-rescue&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Secure OAuth2 (Part -3) : Push Authorization Request (PAR) to Rescue&lt;/strong&gt;&lt;br&gt;
_In the very first post of this series, I explored whether the authorization code grant type truly provides the highest…_sagarag.medium.com&lt;/a&gt;&lt;a href=&quot;https://sagarag.dev/posts/push-authorization-request-par-to-rescue&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/securing-response-using-jwt-secured-authorization-response-mode-jarm&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Secure OAuth2 (Part -4) : Securing Response Using JWT Secured Authorization Response Mode (JARM)&lt;/strong&gt;&lt;br&gt;
_So far in this blog series, we’ve explored whether the OAuth2 authorization code grant type has any security…_sagarag.medium.com&lt;/a&gt;&lt;a href=&quot;https://sagarag.dev/posts/securing-response-using-jwt-secured-authorization-response-mode-jarm&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;/a&gt;&lt;/p&gt;</content:encoded><dc:creator>Sagara Gunathunga</dc:creator><category>OAuth 2.0</category></item><item><title>JARM Explained: Signed OAuth 2.0 Authorization Responses</title><link>https://sagarag.dev/posts/securing-response-using-jwt-secured-authorization-response-mode-jarm</link><guid isPermaLink="true">https://sagarag.dev/posts/securing-response-using-jwt-secured-authorization-response-mode-jarm</guid><description>JARM signs OAuth 2.0 authorization responses as JWTs to stop tampering and mix-up attacks. Covers response modes, claims, validation, and a working demo.</description><pubDate>Sat, 19 Apr 2025 21:25:01 GMT</pubDate><content:encoded>&lt;p&gt;So far in this blog series, we’ve explored whether the OAuth2 authorization code grant type has any security imperfections. We’ve already covered how to strengthen the &lt;strong&gt;authorization request&lt;/strong&gt; using &lt;a href=&quot;https://sagarag.dev/posts/jwt-secured-authorization-request&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;JWT-Secured Authorization Request (JAR)&lt;/strong&gt;&lt;/a&gt; and &lt;a href=&quot;https://sagarag.dev/posts/push-authorization-request-par-to-rescue&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Pushed Authorization Request (PAR)&lt;/strong&gt;&lt;/a&gt; specifications to address several key issues. In this post, I’d like to shift our focus to the &lt;strong&gt;authorization response&lt;/strong&gt; — and specifically, how we can enhance its security using the &lt;a href=&quot;https://openid.net/specs/oauth-v2-jarm.html&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;JWT Secured Authorization Response Mode (JARM)&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Secure OAuth2 : Is Authorization Code Grant Type Secure Enough?&lt;/strong&gt;&lt;br&gt;
_The authorization code grant type is generally considered as the most secure, widely used and commonly recommended…_sagarag.medium.com&lt;/a&gt;&lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;But before we dive into the details of &lt;a href=&quot;https://openid.net/specs/oauth-v2-jarm.html&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;JWT Secured Authorization Response Mode (JARM)&lt;/strong&gt;&lt;/a&gt;, let’s quickly recap the potential security concerns related to the &lt;strong&gt;authorization response&lt;/strong&gt; in the standard authorization code flow. If you haven’t read the &lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;first post&lt;/a&gt; in this series, I’d highly recommend checking it out before diving into this one.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;P5&lt;/a&gt; &lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;—&lt;/a&gt; &lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Server integrity protection failure&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;P6 — Client confidentiality failure&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;P7 — Mixed-up attack&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now, let’s begin our discussion by looking at the following diagram. It shows how the &lt;code&gt;code&lt;/code&gt; parameter—which represents the authorization grant—is returned to the client application. This is typically done by appending it as a parameter to the registered redirect URL, and it’s passed through the user agent, such as a browser. The key issue here is that there’s no built-in mechanism for the client application &lt;strong&gt;to verify whether the authorization response was altered or tampered with during transit&lt;/strong&gt;, or &lt;strong&gt;even to confirm that it genuinely originated from the legitimate authorization server&lt;/strong&gt;. From the client’s perspective, this lack of validation represents an integrity protection failure. Moreover, there’s no way to apply cryptographic protections—like &lt;em&gt;signing or encryption&lt;/em&gt;—to the authorization response in this standard flow.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*wqdz0gUNSmMfwAFhdsiKNQ.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;If you recall the second post in this series, we explored how the &lt;a href=&quot;https://sagarag.dev/posts/jwt-secured-authorization-request&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;JWT-Secured Authorization Request&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;(JAR)&lt;/strong&gt; specification addresses similar issues on the request side. JAR introduces the concept of a Request Object, which wraps the request parameters inside a signed and optionally encrypted JWT to ensure integrity, confidentiality, and source authentication.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/jwt-secured-authorization-request&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Secure OAuth2 (Part -2): Put it in a JAR (JWT-Secured Authorization Request)&lt;/strong&gt;&lt;br&gt;
_In my last post — which I published almost a year ago — I explored whether the authorization code grant type truly…_sagarag.medium.com&lt;/a&gt;&lt;a href=&quot;https://sagarag.dev/posts/jwt-secured-authorization-request&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Applying the same principle to the authorization response makes a lot of sense — and that’s exactly what the &lt;a href=&quot;https://openid.net/specs/oauth-v2-jarm.html&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;JWT-Secured Authorization Response Mode (JARM)&lt;/strong&gt;&lt;/a&gt; specification does. &lt;a href=&quot;https://openid.net/specs/oauth-v2-jarm.html&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;JWT Secured Authorization Response Mode (JARM)&lt;/strong&gt;&lt;/a&gt; was developed by OpenID Foundation’s FAPI working group and became a stable specification in 2021. &lt;strong&gt;In a nutshell, just as the &lt;em&gt;JAR&lt;/em&gt; secures the authorization&lt;/strong&gt; &lt;strong&gt;request, &lt;em&gt;JARM&lt;/em&gt; secures the authorization&lt;/strong&gt; &lt;strong&gt;response by encapsulating it in a signed (and optionally encrypted) JWT.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;One important point to highlight here is that when we talk about the &lt;em&gt;authorization server response&lt;/em&gt; in the context of &lt;a href=&quot;https://openid.net/specs/oauth-v2-jarm.html&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;JWT Secured Authorization Response Mode (JARM)&lt;/strong&gt;&lt;/a&gt;, it includes &lt;strong&gt;both success and error responses&lt;/strong&gt;. That means even an error message is encoded inside a JWT, and generally, we refer to this as the &lt;strong&gt;&lt;em&gt;JWT response document&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;h4 id=&quot;response-mode-and-responsetype&quot;&gt;Response Mode and Response Type&lt;/h4&gt;
&lt;p&gt;To put &lt;a href=&quot;https://openid.net/specs/oauth-v2-jarm.html&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;JWT Secured Authorization Response Mode (JARM)&lt;/strong&gt;&lt;/a&gt; into action, the client application simply needs to indicate — in the authorization request — that it expects the authorization server to return the response in a JWT format. This is done using a request parameter called &lt;code&gt;response_mode&lt;/code&gt;, which comes from another specification by the OpenID Foundation: &lt;a href=&quot;https://openid.net/specs/oauth-v2-multiple-response-types-1_0.html#ResponseModes&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;em&gt;OAuth 2.0 Multiple Response Type Encoding Practices&lt;/em&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;response_mode&lt;/code&gt; parameter tells the authorization server &lt;strong&gt;&lt;em&gt;how&lt;/em&gt;&lt;/strong&gt; to return the authorization response from the authorization endpoint. This makes it a perfect fit for what &lt;a href=&quot;https://openid.net/specs/oauth-v2-jarm.html&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;JWT Secured Authorization Response Mode (JARM)&lt;/strong&gt;&lt;/a&gt; is trying to achieve. While &lt;a href=&quot;https://openid.net/specs/oauth-v2-jarm.html&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;JWT Secured Authorization Response Mode (JARM)&lt;/strong&gt;&lt;/a&gt; still uses the same redirection mechanism to send the user back to the client application using the registered redirect URI, it introduces a new parameter called &lt;code&gt;response&lt;/code&gt;, which carries the JWT response document as part of that redirect. To provide more flexibility, &lt;a href=&quot;https://openid.net/specs/oauth-v2-jarm.html&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;JWT Secured Authorization Response Mode (JARM)&lt;/strong&gt;&lt;/a&gt; defines &lt;strong&gt;four&lt;/strong&gt; &lt;code&gt;**response_mode**&lt;/code&gt; &lt;strong&gt;values&lt;/strong&gt; that let developers choose how the JWT should be delivered to the client application. These are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;**query.jwt**&lt;/code&gt; – The JWT response is added as a query parameter to the redirect URI.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;**fragment.jwt**&lt;/code&gt; – The JWT response is added as a URI fragment.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;**form_post.jwt**&lt;/code&gt; – The JWT response is embedded as an HTML form field and auto-submitted via an HTTP POST.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;**jwt**&lt;/code&gt; – A shorthand value that uses the default mechanism (query or fragment) based on the &lt;code&gt;response_type&lt;/code&gt;paramter discssed below.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now, what exactly goes inside the JWT response document depends on another authorization request parameter called &lt;code&gt;response_type&lt;/code&gt;. This one should be familiar—it’s defined in the core &lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc6749#section-3.1.1&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;OAuth2 specification ( section 3.1.1)&lt;/a&gt; and used to distinguish between different grant types supported by the authorization endpoint. Due to it’s extensibility, the above-mentioned &lt;a href=&quot;https://openid.net/specs/oauth-v2-multiple-response-types-1_0.html#MultiValueResponseTypes&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;OAuth 2.0 Multiple Response Type Encoding Practices&lt;/a&gt; specification from OpenID foundation extends the use of &lt;code&gt;response_type&lt;/code&gt; by defining multiple and new response types to be used with the OpenID Connect protocol.For this blog series, though, we’re sticking with the &lt;strong&gt;authorization code grant type&lt;/strong&gt;, where the &lt;code&gt;response_type&lt;/code&gt; is set to &lt;code&gt;code&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;As you can see in the following sample request, other than adding query &lt;code&gt;query.jwt&lt;/code&gt; as the value of response type there is no change to the authorization request.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*y30lxB6KswFzfz6gyfU86g.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Now, let’s look at the authorization server’s response for the above request. You can see that the JWT response is added as a query parameter using the &lt;code&gt;response.&lt;/code&gt; Note that, given we stick with &lt;code&gt;response_type=code&lt;/code&gt; as the scope of this post, passing &lt;code&gt;response_mode=jwt&lt;/code&gt; also returns the same result.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*mKX8XRysS2VhyhxNPUwuHw.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;If we use &lt;code&gt;fragment.jwt&lt;/code&gt;as the value of the &lt;code&gt;response_mode&lt;/code&gt; parameter, the authorisation request will looks likes the following.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*WfhY2hCJHOCUC783hELkqQ.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;In this case, the authorization response will be modified as shown in the following example. As you can see, the JWT response is appended as a fragment to the redirect URI.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*bi_2CVXNIAhdtqvHjHvstA.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Finally, if we use &lt;code&gt;form_post.jwt&lt;/code&gt; as the value of the &lt;code&gt;response_mode&lt;/code&gt; parameter, the authorization request would look like the example below.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*s2GzXSN1w-UuLaygeYnhgA.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Unlike the previous two cases, here the authorization server submits the JWT authorization response to the client application using an HTTP POST. As a result, the JWT response won’t be visible in the browser URL. Instead, the application receives it as part of a form submission, similar to the one shown below.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*gkYuDSZKSkLNgkRtfyFXqA.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;One important point to mention here is that, in the examples above, I used the authorization request as in the standard authorization code grant type — mainly to keep things simple and easier to follow. However, the &lt;a href=&quot;https://openid.net/specs/oauth-v2-jarm.html&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;JWT Secured Authorization Response Mode (JARM)&lt;/strong&gt;&lt;/a&gt; specification can absolutely be used alongside the &lt;a href=&quot;https://sagarag.dev/posts/jwt-secured-authorization-request&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;JWT-Secured Authorization Request (JAR)&lt;/strong&gt;&lt;/a&gt; and &lt;a href=&quot;https://sagarag.dev/posts/push-authorization-request-par-to-rescue&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Pushed Authorization Request (PAR)&lt;/strong&gt;&lt;/a&gt; specifications, which significantly enhance the security of the authorization request phase. If you want to use &lt;a href=&quot;https://openid.net/specs/oauth-v2-jarm.html&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;JWT Secured Authorization Response Mode (JARM)&lt;/strong&gt;&lt;/a&gt; along with&lt;a href=&quot;https://sagarag.dev/posts/jwt-secured-authorization-request&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;JWT-Secured Authorization Request (JAR)&lt;/strong&gt;&lt;/a&gt; and &lt;a href=&quot;https://sagarag.dev/posts/push-authorization-request-par-to-rescue&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Pushed Authorization Request (PAR)&lt;/strong&gt;&lt;/a&gt;, you just need to include the &lt;code&gt;response_mode&lt;/code&gt; and &lt;code&gt;response_type&lt;/code&gt; parameters within the Request Object or the PAR request—nothing else changes.&lt;/p&gt;
&lt;p&gt;No matter how the client application receives the JWT-encoded authorization response, once you decode it, you’ll see a JWT that looks something like the example below. As with any JWT, there are a few standard claims you’ll always find:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;iss&lt;/code&gt;: the issuer URL of the authorization server&lt;/li&gt;
&lt;li&gt;&lt;code&gt;aud&lt;/code&gt;: the &lt;code&gt;client_id&lt;/code&gt; of the client application&lt;/li&gt;
&lt;li&gt;&lt;code&gt;exp&lt;/code&gt;: the expiration time of the JWT that is usually less than o10 minutes&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*lg7ZKo5Q7rEmP2pZmNmcMQ.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;As mentioned earlier, the exact claims included in the JWT will depend on the value of the &lt;code&gt;response_type&lt;/code&gt; parameter. For example, when &lt;code&gt;response_type=code&lt;/code&gt;, you’ll find the &lt;code&gt;code&lt;/code&gt; claim (which is the authorization code) along with the &lt;code&gt;state&lt;/code&gt; value originally sent by the client.&lt;/p&gt;
&lt;p&gt;If the authorization response indicates an error, the JWT will contain an &lt;code&gt;error&lt;/code&gt; claim representing the error code. It may also include optional claims like &lt;code&gt;error_description&lt;/code&gt;, &lt;code&gt;error_uri&lt;/code&gt;, and &lt;code&gt;state&lt;/code&gt;, as shown in the example below.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*Ei5_zDgwe27uzQpEnu1T9A.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;If the JWT is encrypted, the client first needs to decrypt it. This is usually done using the default encryption key associated with the authorization server, or in some cases, a key identified by the kid (key ID) in the JWT header if it’s avilable. The key could be either a private key (with the corresponding public key registered in the client’s metadata) or a key derived from the client secret.&lt;/p&gt;
&lt;p&gt;Once decrypted, the client should check the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;iss&lt;/code&gt; (issuer) claim should match the expected authorization server. If it doesn’t, the client should reject the response.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;aud&lt;/code&gt; (audience) claim should match the &lt;code&gt;client_id&lt;/code&gt; the client used in the original request. If not, the response should be rejected.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;exp&lt;/code&gt; (expiration) claim tells the client if the JWT is still valid. If it’s expired, the response must be rejected.&lt;/li&gt;
&lt;li&gt;Finally, the client must validate the signature of the JWT to make sure it hasn’t been tampered with. If the &lt;code&gt;**alg**&lt;/code&gt; value is &lt;code&gt;**none**&lt;/code&gt; &lt;strong&gt;in the JOSE header then the response should be rejected&lt;/strong&gt; and If the &lt;strong&gt;signature check fails, the response should be rejected as well&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Sinceses JWTs and requires successful signature validation, it naturally provides integrity protection, source authentication, audience restriction, and protection from mix-up attacks. And when the JWT is encrypted, it also ensures confidentiality.&lt;/p&gt;
&lt;h4 id=&quot;jarm-inaction&quot;&gt;JARM in Action&lt;/h4&gt;
&lt;p&gt;At this point, we’ve covered the key details you need to understand about the &lt;a href=&quot;https://openid.net/specs/oauth-v2-jarm.html&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;JWT Secured Authorization Response Mode (JARM)&lt;/strong&gt;&lt;/a&gt; specification and how it helps improve the security of the authorization response of the authorization code grant type. Before wrapping up this post, I want to give you a set of instructions to run a quick hands-on demo to see &lt;a href=&quot;https://openid.net/specs/oauth-v2-jarm.html&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;JWT Secured Authorization Response Mode (JARM)&lt;/strong&gt;&lt;/a&gt; in action using a cloud-based identity provider. It should only take about 5 minutes.&lt;/p&gt;
&lt;p&gt;For this demo, I’ll be using &lt;strong&gt;Asgardeo&lt;/strong&gt; — a cloud identity service by WSO2. It fully supports the &lt;a href=&quot;https://openid.net/specs/oauth-v2-jarm.html&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;JWT Secured Authorization Response Mode (JARM)&lt;/strong&gt;&lt;/a&gt; specification and comes with a generous free tier, making it a great option to try out your identity use cases.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*7Q4M7ytIXMTiSy-7j_ztqg.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step 1 — Configure Asgardeo&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;If you don’t already have an Asgardeo account, you can sign up &lt;a href=&quot;https://wso2.com/asgardeo/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;. Once you’re logged in:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create a new &lt;strong&gt;Traditional Web Application&lt;/strong&gt; from the left-side menu and Keep &lt;strong&gt;OpenID Connect&lt;/strong&gt; selected as the protocol (this is the default). For the &lt;strong&gt;Authorized redirect URLs&lt;/strong&gt;, enter &lt;code&gt;[https://myapp.io/login](https://myapp.io/login)&lt;/code&gt; as the value. Then save the application settings.&lt;/li&gt;
&lt;li&gt;Next follow &lt;a href=&quot;https://wso2.com/asgardeo/docs/guides/users/manage-users/#onboard-single-user&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;this guide&lt;/a&gt; to create a test user, which you’ll use later in this flow.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Step 2 — Set Up Postman&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Next, you’ll need to configure Postman. First, Download &lt;a href=&quot;https://www.postman.com/warped-eclipse-61593/workspace/public/collection/25632817-3c15b3bb-1892-41d1-b273-379471c24cb9?action=share&amp;#x26;creator=25632817&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;this Postman collection&lt;/a&gt; for this demo. Open the collection and update the collection variables with the following values, which you can copy from your Asgardeo application:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;[authorize_ep](https://myapp.io/login)&lt;/code&gt; — Token Endpoint URL from the &lt;strong&gt;Info&lt;/strong&gt; tab.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;token_ep&lt;/code&gt; — Authorization Endpoint URL from the &lt;strong&gt;Info&lt;/strong&gt; tab.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;client_id&lt;/code&gt; — Client ID &lt;strong&gt;protocol&lt;/strong&gt; tab.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;client_secret&lt;/code&gt; — Client Secret &lt;strong&gt;protocol&lt;/strong&gt; tab.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Step 3 — Execute the Flow&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Since Postman can’t simulate browser-based redirects, we’ll take a small manual step here. Open the &lt;strong&gt;Code Snippet&lt;/strong&gt; tab for each request &lt;em&gt;( e.g — [Browser]jarm-query.jwt)&lt;/em&gt; from the right-hand menu in Postman and select &lt;strong&gt;cURL&lt;/strong&gt; from the dropdown. Then copy the &lt;code&gt;location&lt;/code&gt; value from the cURL snippet. This URL includes the correct &lt;code&gt;response_mode&lt;/code&gt; and &lt;code&gt;response_type&lt;/code&gt; values. Finally paste that URL into your browser’s address bar and hit Enter.&lt;/li&gt;
&lt;li&gt;You should now be redirected to Asgardeo’s login screen. Enter the credentials of the test user you created earlier. If authentication is successful, you’ll be redirected to the callback URL with JWT authorization response which you can decode from your prefred JWT decoder tool.&lt;/li&gt;
&lt;li&gt;Go back to Postman and open the &lt;code&gt;**Token-Request**&lt;/code&gt; request. Paste the copied &lt;code&gt;code&lt;/code&gt; into the &lt;code&gt;code&lt;/code&gt; parameter in the request body and send the request. If everything is set up correctly, you should receive a valid token from Asgardeo.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This quick walkthrough shows how easy it is to implement &lt;a href=&quot;https://openid.net/specs/oauth-v2-jarm.html&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;JWT Secured Authorization Response Mode (JARM)&lt;/strong&gt;&lt;/a&gt; using a modern identity platform.&lt;/p&gt;
&lt;p&gt;So far in this series, we’ve looked at how to secure the authorization request using &lt;a href=&quot;https://sagarag.dev/posts/jwt-secured-authorization-request&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;JWT-Secured Authorization Request (JAR)&lt;/strong&gt;&lt;/a&gt; and &lt;a href=&quot;https://sagarag.dev/posts/push-authorization-request-par-to-rescue&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Pushed Authorization Request (PAR)&lt;/strong&gt;&lt;/a&gt;, and in this post, we focused on how &lt;a href=&quot;https://openid.net/specs/oauth-v2-jarm.html&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;JWT Secured Authorization Response Mode (JARM)&lt;/strong&gt;&lt;/a&gt; strengthens the authorization response. With these improvements in place, we’ve successfully addressed all the security concerns we identified in the very first post of this series. As we are reaching the end of this blog series, stay tune for the last post of the series.&lt;/p&gt;
&lt;h3 id=&quot;other-posts-in-the-secure-oauth2series&quot;&gt;Other posts in the secure OAuth2 series&lt;/h3&gt;
&lt;p&gt;Read the other posts in &lt;strong&gt;Secure OAuth2&lt;/strong&gt; series.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Secure OAuth2 : Is Authorization Code Grant Type Secure Enough?&lt;/strong&gt;&lt;br&gt;
_The authorization code grant type is generally considered as the most secure, widely used and commonly recommended…_sagarag.medium.com&lt;/a&gt;&lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/jwt-secured-authorization-request&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Secure OAuth2 (Part -2): Put it in a JAR (JWT-Secured Authorization Request)&lt;/strong&gt;&lt;br&gt;
_In my last post — which I published almost a year ago — I explored whether the authorization code grant type truly…_sagarag.medium.com&lt;/a&gt;&lt;a href=&quot;https://sagarag.dev/posts/jwt-secured-authorization-request&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/push-authorization-request-par-to-rescue&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Secure OAuth2 (Part -3) : Push Authorization Request (PAR) to Rescue&lt;/strong&gt;&lt;br&gt;
_In the very first post of this series, I explored whether the authorization code grant type truly provides the highest…_sagarag.medium.com&lt;/a&gt;&lt;a href=&quot;https://sagarag.dev/posts/push-authorization-request-par-to-rescue&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;/a&gt;&lt;/p&gt;</content:encoded><dc:creator>Sagara Gunathunga</dc:creator><category>OAuth 2.0</category><category>JWT</category></item><item><title>Pushed Authorization Requests (PAR): RFC 9126 Explained</title><link>https://sagarag.dev/posts/push-authorization-request-par-to-rescue</link><guid isPermaLink="true">https://sagarag.dev/posts/push-authorization-request-par-to-rescue</guid><description>Pushed Authorization Requests (RFC 9126) move OAuth request parameters off the browser. How PAR works with JAR, request_uri, and dynamic redirect URIs.</description><pubDate>Fri, 18 Apr 2025 03:30:18 GMT</pubDate><content:encoded>&lt;p&gt;In the very &lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;first post&lt;/a&gt; of this series, I explored whether the authorization code grant type truly provides the highest level of security — and what potential risks it might carry. This grant type is widely regarded as the recommended option when involving end users, both in &lt;a href=&quot;https://datatracker.ietf.org/doc/rfc9700/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;OAuth 2.0 best current practices&lt;/a&gt; and the &lt;a href=&quot;https://datatracker.ietf.org/doc/draft-ietf-oauth-v2-1/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;OAuth 2.1&lt;/a&gt; draft specification. If you haven’t already, I highly recommend reading that first post before diving into this one.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Secure OAuth2 : Is Authorization Code Grant Type Secure Enough?&lt;/strong&gt;&lt;br&gt;
_The authorization code grant type is generally considered as the most secure, widely used and commonly recommended…_sagarag.medium.com&lt;/a&gt;&lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Just to recap, the potential security shortcomings in the authorization request of the authorization code flow includes:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;P1&lt;/a&gt; &lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;—&lt;/a&gt; &lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Integrity protection failure&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;P2 — Source Authentication Failure&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;P3 — Confidentiality failure&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;P4 — Lack of Request as a Reference semantic&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The implications tied to the authorization response of the authorization code flow includes:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;P5&lt;/a&gt; &lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;—&lt;/a&gt; &lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Server integrity protection failure&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;P6 — Client confidentiality failure&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;P7 — Mixed-up attack&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In the most recent post, we looked at how &lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc9101&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;JWT-Secured Authorization Request&lt;/a&gt; (JAR) helps address some of those concerns by introducing the concept of a &lt;em&gt;Request Object&lt;/em&gt; — essentially a JWT that can be signed (JWS) and encrypted (JWE) to offer integrity protection, source authentication, and confidentiality. We also touched on the request-by-reference semantics in the JAR spec, which remain open-ended and somewhat vague for implementation.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/jwt-secured-authorization-request&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Secure OAuth2 (Part -2): Put it in a JAR (JWT-Secured Authorization Request)&lt;/strong&gt;&lt;br&gt;
_In my last post — which I published almost a year ago — I explored whether the authorization code grant type truly…_sagarag.medium.com&lt;/a&gt;&lt;a href=&quot;https://sagarag.dev/posts/jwt-secured-authorization-request&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In this post, I’ll continue our conversation by introducing another spec in the OAuth 2.0 ecosystem: &lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc9126&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Pushed Authorization Requests&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;(PAR)&lt;/strong&gt;. We’ll look at how PAR and JAR complement each other to bring maximum security to the authorization request process&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*ahcBOUv6NO5r4sEp&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;h4 id=&quot;making-authorization-code-grant-moresecure&quot;&gt;Making Authorization Code grant more secure&lt;/h4&gt;
&lt;p&gt;If we go back to the following diagram — which captures the last point I discussed in my previous post on JWT-Secured Authorization Request (JAR) — you’ll see how a signed and optionally encrypted &lt;strong&gt;&lt;em&gt;Request Object&lt;/em&gt;&lt;/strong&gt; can be sent to the Authorization Server &lt;strong&gt;as a reference&lt;/strong&gt;, rather than being passed directly in the authorization request.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*5-gl6-wye63TSDQHCA3gHw.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;This approach makes use of the &lt;code&gt;request_uri&lt;/code&gt; parameter, introduced in the JAR specification, to point to a URI where the Request Object is stored. It’s a smart way to ensure &lt;strong&gt;confidentiality&lt;/strong&gt; in the authorization request and is especially handy in resource-constrained environments, like mobile devices, where sending large requests via the user agent isn’t always practical.&lt;/p&gt;
&lt;p&gt;However, despite these benefits, the JAR spec has a few open-end areas related to pass by reference approach. It doesn’t define a standard mechanism or location for storing the Request Object. It’s a bit &lt;em&gt;too&lt;/em&gt; open — your options include a local client location, a remote location at the Authorization Server, or even a trusted third-party location. On top of that, there’s no clear guidance on how to store the Request Object, what security measures should be applied, or how the Authorization Server is supposed to fetch it securely. Another limitation is that the send-by-reference approach in JAR is tightly coupled with the use of the Request Object itself. That makes it a less-than-ideal fit for simpler use cases where a full JWT-based Request Object might be overkill.&lt;/p&gt;
&lt;p&gt;This is exactly where &lt;strong&gt;Pushed Authorization Requests (PAR)&lt;/strong&gt; come in. The PAR specification introduces a dedicated endpoint called &lt;strong&gt;Pushed Authorization Request Endpoint&lt;/strong&gt; &lt;strong&gt;(PAR endpoint in short)&lt;/strong&gt; at the Authorization Server. This endpoint offers a &lt;em&gt;generic, secure, and standardized&lt;/em&gt; way to achieve request-by-reference semantics. In the &lt;strong&gt;standard Authorization Code flow&lt;/strong&gt;, the client sends the authorization request by directing the user agent — typically a web browser — to make an HTTP &lt;code&gt;GET&lt;/code&gt; request to the authorization server’s authorization endpoint. &lt;strong&gt;PAR&lt;/strong&gt;, however, introduces a key shift: it &lt;strong&gt;splits the authorization request into two distinct steps&lt;/strong&gt; — and this change plays a big role in strengthening the overall security of the flow.&lt;/p&gt;
&lt;p&gt;Let’s now walk through that protocol flow step by step.&lt;/p&gt;
&lt;p&gt;With &lt;strong&gt;Pushed Authorization Requests (PAR)&lt;/strong&gt;, the flow begins when the client application sends a &lt;strong&gt;HTTP&lt;/strong&gt; &lt;code&gt;**POST**&lt;/code&gt; &lt;strong&gt;request&lt;/strong&gt;—called a &lt;em&gt;pushed authorization request&lt;/em&gt;, or simply &lt;strong&gt;PAR request&lt;/strong&gt;—to a newly introduced &lt;strong&gt;PAR endpoint&lt;/strong&gt; on the authorization server. Just like the token request that happens later in the flow, this is a &lt;strong&gt;direct client-to-server call via TLS encrypted HTTP channel&lt;/strong&gt;, with no involvement from the user agent (i.e., the browser).&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*flNvidYOTd_Z_lWOSex8uA.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Later in this post, we’ll look at how you can include a &lt;strong&gt;Request Object&lt;/strong&gt; (as defined by the JAR spec) in the PAR request. But the beauty of PAR is that you don’t have to — &lt;strong&gt;you can simply send the request parameters encoded within the body of HTTP POST message&lt;/strong&gt;, making it much more flexible.&lt;/p&gt;
&lt;p&gt;Here’s what a sample PAR request looks like…&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*MTA-61Op5jdMPEFc9HC2xg.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Just like in the standard authorization request, a &lt;strong&gt;PAR request&lt;/strong&gt; includes parameters like &lt;code&gt;client_id&lt;/code&gt;, &lt;code&gt;redirect_uri&lt;/code&gt;, &lt;code&gt;response_type&lt;/code&gt;, and &lt;code&gt;scope&lt;/code&gt;, but this time they’re &lt;strong&gt;encoded in the body&lt;/strong&gt; of the HTTP &lt;code&gt;POST&lt;/code&gt; request instead of encoding them as URL parameters in the &lt;code&gt;GET&lt;/code&gt; call used in the authorization request of the standard authorization code grant flow. It’s important to note that the &lt;code&gt;response_type&lt;/code&gt; should be set to &lt;code&gt;&apos;code&apos;&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;PAR endpoint&lt;/strong&gt; is designed to accept &lt;strong&gt;any parameter defined by the OAuth 2.0 core specification for the authorization request&lt;/strong&gt;, as well as any supported extensions. For example, you can easily use PKCE (Proof Key for Code Exchange) with PAR. And since OIDC (OpenID Connect) is technically an OAuth 2.0 extension, PAR works with OIDC too.&lt;/p&gt;
&lt;p&gt;One key difference compared to the traditional approach is that, in PAR &lt;strong&gt;confidential clients must authenticate with the authorization server&lt;/strong&gt; right at this first step — &lt;strong&gt;before any user interaction happens&lt;/strong&gt;. This is clearly a security enhancement. In the above example, the client authenticates using a &lt;code&gt;client_secret&lt;/code&gt;, but you can use any supported method, including mutual TLS (mTLS), private_key_jwt, etc.&lt;/p&gt;
&lt;p&gt;Now, once the &lt;strong&gt;authorization server receives the PAR request&lt;/strong&gt;, it performs client authentication and request validation. If everything checks out, it generates a &lt;code&gt;**request_uri**&lt;/code&gt; (yep—the same one we discussed in the &lt;a href=&quot;https://sagarag.dev/posts/jwt-secured-authorization-request&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;last post&lt;/a&gt; on JAR) and sends it back to the client, along with an &lt;code&gt;expires_in&lt;/code&gt; value indicating how long the &lt;code&gt;request_uri&lt;/code&gt; is valid. If something goes wrong, the server responds with a JSON-formatted error. The diagram below illustrates a successful PAR response.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*Yt1F0LT2phzpt0YZdk9Dxg.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Now with the &lt;code&gt;**request_uri**&lt;/code&gt; in hand, the client application can build the &lt;strong&gt;authorization request URL&lt;/strong&gt;, similar to how it’s done in the traditional flow. The only real difference is that, other than &lt;code&gt;client_id&lt;/code&gt;, &lt;strong&gt;none of the sensitive request parameters are included in the URL anymore&lt;/strong&gt;—they’re all safely tucked away in the previously sent PAR request. Here’s an example of what that request might look like.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*HR9UnEByX9lK5TBY8Znp7Q.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Finally, once the user authenticates and authorizes the request, the authorization server sends back an authorization grant using the &lt;code&gt;code&lt;/code&gt; parameter appended to the redirect URI—just like in the standard flow. It’s important to note that PAR does’t not introduce any change except the above discussed modifications to the authorization request flow. The complete authorization code grant flow with the introduction of PAR is depicted in the following diagram.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*q9wqKHWEOq74afA1j_34bw.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;PAR offers a major security and usability improvement for a couple of reasons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;request parameters no longer travel through the browser&lt;/strong&gt;, which eliminates exposure to the end user and solves both &lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;P3 — Confidentiality failure&lt;/a&gt; and &lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;P4 — Lack of Request as a Reference semantic&lt;/a&gt; that we discussed in this series.&lt;/li&gt;
&lt;li&gt;It also solves the issue of handling &lt;strong&gt;large request payloads&lt;/strong&gt;, since those are now sent directly over a secure connection instead of being embedded in a URL making this is a preferable for resource constraint mobile devices and also in environments low internet connectivity.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The following diagram provides comparison between standard authorization code grant flow and authorization code grant flow with PAR.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*Itk0xYBYOU4z4iviNh1gTQ.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;h4 id=&quot;request-objectsupport&quot;&gt;Request Object support&lt;/h4&gt;
&lt;p&gt;In situations where you need &lt;strong&gt;tighter security controls&lt;/strong&gt; — like when working with sensitive data or operating in high-stakes industries such as &lt;strong&gt;finance or healthcare&lt;/strong&gt; — you can take things a step further. Instead of directly encoding each authorization request parameter in the body of the PAR request, you can use a &lt;strong&gt;signed (and optionally encrypted) Request Object&lt;/strong&gt;, which we explored in detail in my previous post on JAR.&lt;/p&gt;
&lt;p&gt;In this approach, the signed and/or encrypted &lt;strong&gt;Request Object&lt;/strong&gt; is added to the PAR request using the &lt;code&gt;request&lt;/code&gt; parameter ( the one defined in the JAR specification). This lets you combine the benefits of &lt;strong&gt;PAR&lt;/strong&gt; and &lt;strong&gt;JAR&lt;/strong&gt;, giving you &lt;strong&gt;the highest level of security&lt;/strong&gt;—something that’s more than sufficient for even the most regulated industries.&lt;/p&gt;
&lt;p&gt;Take a look at the example below to see how this looks like in PAR request. Instead of passing individual parameters like &lt;code&gt;redirect_uri&lt;/code&gt;, &lt;code&gt;scope&lt;/code&gt;, etc., directly in the body of the POST request, here you’re wrapping them all in a signed JWT and attaching that via the &lt;code&gt;request&lt;/code&gt; parameter.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*eXApawMkkc72vTFSpMORjg.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Once the authorization server receives this PAR request, it goes through the usual steps: authenticates the client, decrypts the Request Object if it’s encrypted, verifies the signature, performs any additional validation, and finally responds with a &lt;code&gt;request_uri&lt;/code&gt;. This &lt;code&gt;request_uri&lt;/code&gt; will then be used in the next stage of the flow, just like before.&lt;/p&gt;
&lt;p&gt;So, other than swapping individual parameters for a &lt;strong&gt;Request Object&lt;/strong&gt; , the flow remains the same—but now you’ve layered in an extra level of protection.&lt;/p&gt;
&lt;h4 id=&quot;dynamic-redirecturis&quot;&gt;Dynamic Redirect URIs&lt;/h4&gt;
&lt;p&gt;The core &lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc6749#section-3.1.2.3&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;OAuth 2.0 specification&lt;/a&gt; is actually a bit relaxed when it comes to callback URLs. It allows scenarios where only part of the callback URL is registered — or, in some cases, where &lt;strong&gt;no redirect URI&lt;/strong&gt; is pre-registered at all. This gives client applications a bit of wiggle room to send dynamically constructed callback URLs along with their authorization requests.&lt;/p&gt;
&lt;p&gt;However, both the &lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc9700&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;OAuth2 Best Current Practice&lt;/strong&gt;&lt;/a&gt; and the &lt;a href=&quot;https://datatracker.ietf.org/doc/draft-ietf-oauth-v2-1/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;OAuth 2.1 draft&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;spec&lt;/strong&gt; strongly recommend that authorization servers &lt;strong&gt;require an exact match&lt;/strong&gt; between the &lt;code&gt;redirect_uri&lt;/code&gt; used in a request and one that was pre-registered by the client. In fact, most identity vendors have already adopted this stricter behavior. And it makes sense—this practice helps prevent client impersonation, token leakage, and open redirection vulnerabilities.&lt;/p&gt;
&lt;p&gt;That said, in some cases, dynamically generating a callback URL per transaction is just a better architectural fit — especially for certain app designs. With PAR, that exact redirect URI matching requirement can be relaxed — but only under specific conditions. Since PAR introduces client authentication &lt;em&gt;before&lt;/em&gt; the authorization request gets processed, the authorization server can be sure it’s dealing with a legitimate client. That means it can allow redirect URIs that weren’t pre-registered, giving your app the flexibility to use &lt;strong&gt;dynamic redirect URIs&lt;/strong&gt;, say, to model per-session or transaction use cases. Of course, this flexibility isn’t mandatory — &lt;strong&gt;it’s up to the authorization server&lt;/strong&gt; to support it or not. And even if it does, it should be used thoughtfully to avoid introducing security risks.&lt;/p&gt;
&lt;h4 id=&quot;authorization-servermetadata&quot;&gt;Authorization Server Metadata&lt;/h4&gt;
&lt;p&gt;The PAR specification also introduces a few metadata additions that make life easier for client applications. One of them is a new parameter called &lt;code&gt;**pushed_authorization_request_endpoint**&lt;/code&gt;. This shows up in the server’s metadata document and tells client apps exactly where to send their PAR requests.&lt;/p&gt;
&lt;p&gt;Given the &lt;strong&gt;client authentication rules&lt;/strong&gt; used for token endpoint are also applicable to the PAR endpoint the existing metadata parameter &lt;code&gt;**token_endpoint_auth_methods_supported**&lt;/code&gt; is applicable for PAR endpoint as well—it tells you which client authentication methods are accepted at the PAR endpoint.&lt;/p&gt;
&lt;p&gt;Additionally the &lt;code&gt;**require_pushed_authorization_requests**&lt;/code&gt; parameter indicates whether the use of PAR is mandatory or not. When is set to &lt;code&gt;true&lt;/code&gt;, it means the authorization server &lt;strong&gt;only accepts authorization requests that go through PAR&lt;/strong&gt;.&lt;/p&gt;
&lt;h4 id=&quot;par-inaction&quot;&gt;PAR in Action&lt;/h4&gt;
&lt;p&gt;At this point, we’ve covered most of the important details around the Pushed Authorization Requests (PAR) specification that you’ll need when applying it in real-world scenarios. Before we wrap up this post, I’d like to walk you through a quick hands-on demonstration to see PAR in action using a cloud-based identity provider. This should only take around 5 minutes.&lt;/p&gt;
&lt;p&gt;For this, I’ll be using &lt;a href=&quot;https://wso2.com/asgardeo/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Asgardeo&lt;/strong&gt;&lt;/a&gt; — a public identity cloud offering from WSO2. &lt;a href=&quot;https://wso2.com/library/blogs/pushing-the-boundaries-of-oauth-andoidc-security/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;It supports&lt;/a&gt; the PAR specification and comes with a generous free tier, which makes it a great option for testing your identity use cases.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*7Q4M7ytIXMTiSy-7j_ztqg.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step 1 — Configure Asgardeo&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;If you don’t already have an Asgardeo account, you can sign up &lt;a href=&quot;https://wso2.com/asgardeo/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;. Once you’re logged in:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create a new &lt;strong&gt;Traditional Web Application&lt;/strong&gt; from the left-side menu and Keep &lt;strong&gt;OpenID Connect&lt;/strong&gt; selected as the protocol (this is the default). For the &lt;strong&gt;Authorized redirect URLs&lt;/strong&gt;, enter &lt;code&gt;[https://myapp.io/login](https://myapp.io/login)&lt;/code&gt; as the value. Then save the application settings.&lt;/li&gt;
&lt;li&gt;Next follow &lt;a href=&quot;https://wso2.com/asgardeo/docs/guides/users/manage-users/#onboard-single-user&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;this guide&lt;/a&gt; to create a test user, which you’ll use later in this flow.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Step 2 — Set Up Postman&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Next, you’ll need to configure Postman. First, Download t&lt;a href=&quot;https://www.postman.com/warped-eclipse-61593/workspace/public/collection/25632817-a82a5e32-4ae1-40ff-8012-d512698a6a3c?action=share&amp;#x26;creator=25632817&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;his Postman collection&lt;/a&gt; for this demo. Open the collection and update the collection variables with the following values, which you can copy from your Asgardeo application:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;par_ep&lt;/code&gt; —PAR Endpoint URL from the &lt;strong&gt;Info&lt;/strong&gt; tab.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;[authorize_ep](https://myapp.io/login)&lt;/code&gt; — Token Endpoint URL from the &lt;strong&gt;Info&lt;/strong&gt; tab.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;token_ep&lt;/code&gt; — Authorization Endpoint URL from the &lt;strong&gt;Info&lt;/strong&gt; tab.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;client_id&lt;/code&gt; — Client ID &lt;strong&gt;protocol&lt;/strong&gt; tab.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;client_secret&lt;/code&gt; — Client Secret &lt;strong&gt;protocol&lt;/strong&gt; tab.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Step 3 — Execute the Flow&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Run the &lt;code&gt;**PAR-Request**&lt;/code&gt; request from the Postman collection. You should receive a response containing a &lt;code&gt;request_uri&lt;/code&gt;. This value is key to constructing the authorization request.&lt;/li&gt;
&lt;li&gt;Since Postman can’t simulate browser-based redirects, we’ll take a small manual step here. Open the &lt;strong&gt;Code Snippet&lt;/strong&gt; tab from the right-hand menu in Postman and select &lt;strong&gt;cURL&lt;/strong&gt; from the dropdown. Then copy the &lt;code&gt;location&lt;/code&gt; value from the cURL snippet. This URL includes the &lt;code&gt;request_uri&lt;/code&gt; from the previous step. Finally paste that URL into your browser’s address bar and hit Enter.&lt;/li&gt;
&lt;li&gt;You should now be redirected to Asgardeo’s login screen. Enter the credentials of the test user you created earlier. If authentication is successful, you’ll be redirected to the callback URL with a &lt;code&gt;code&lt;/code&gt; parameter in the query string. This is your authorization code. Copy the value of the &lt;code&gt;code&lt;/code&gt;for the next step.&lt;/li&gt;
&lt;li&gt;Go back to Postman and open the &lt;code&gt;**Token-Request**&lt;/code&gt; request. Paste the copied &lt;code&gt;code&lt;/code&gt; into the &lt;code&gt;code&lt;/code&gt; parameter in the request body and send the request. If everything is set up correctly, you should receive a valid token from Asgardeo.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This quick walkthrough shows how easy it is to implement PAR using a modern identity platform.&lt;/p&gt;
&lt;p&gt;This post is the third part of my &lt;strong&gt;Secure OAuth2&lt;/strong&gt; series. We explored how the &lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc9126&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Pushed Authorization Requests&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;(PAR)&lt;/strong&gt; specification enhances the standard authorization code flow by introducing confidentiality, source authentication, and a more secure “pass by reference” mechanism for authorization requests.&lt;/p&gt;
&lt;p&gt;At this point, we’ve covered both &lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc9101&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;JWT-Secured Authorization Request&lt;/strong&gt; (&lt;strong&gt;JAR)&lt;/strong&gt;&lt;/a&gt; and &lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc9126&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Pushed Authorization Requests&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;(&lt;/strong&gt;&lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc9126&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;PAR&lt;/strong&gt;&lt;/a&gt; )— two important specifications that together help address the four security concerns: &lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;P1&lt;/a&gt; &lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;—&lt;/a&gt; &lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Integrity protection failure&lt;/a&gt;, &lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;P2 — Source Authentication Failure&lt;/a&gt;, &lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;P3 — Confidentiality failure&lt;/a&gt;, &lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;P4 — Lack of Request as a Reference semantic&lt;/a&gt; . These two specifications significantly strengthen the request side of the authorization flow.&lt;/p&gt;
&lt;p&gt;In the next post, we’ll shift our focus to the &lt;strong&gt;response flow&lt;/strong&gt;, which we haven’t fully explored yet. There are still a few important details to unpack in order to make the entire OAuth2 flow as secure and robust as possible — so stay tuned!&lt;/p&gt;
&lt;h3 id=&quot;other-posts-in-the-secure-oauth2series&quot;&gt;Other posts in the secure OAuth2 series&lt;/h3&gt;
&lt;p&gt;Read the other posts in &lt;strong&gt;Secure OAuth2&lt;/strong&gt; series.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Secure OAuth2 : Is Authorization Code Grant Type Secure Enough?&lt;/strong&gt;&lt;br&gt;
_The authorization code grant type is generally considered as the most secure, widely used and commonly recommended…_sagarag.medium.com&lt;/a&gt;&lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/jwt-secured-authorization-request&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Secure OAuth2 (Part -2): Put it in a JAR (JWT-Secured Authorization Request)&lt;/strong&gt;&lt;br&gt;
_In my last post — which I published almost a year ago — I explored whether the authorization code grant type truly…_sagarag.medium.com&lt;/a&gt;&lt;a href=&quot;https://sagarag.dev/posts/jwt-secured-authorization-request&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;/a&gt;&lt;/p&gt;</content:encoded><dc:creator>Sagara Gunathunga</dc:creator><category>OAuth 2.0</category></item><item><title>JWT-Secured Authorization Request (JAR): RFC 9101 Explained</title><link>https://sagarag.dev/posts/jwt-secured-authorization-request</link><guid isPermaLink="true">https://sagarag.dev/posts/jwt-secured-authorization-request</guid><description>JAR (RFC 9101) signs OAuth 2.0 authorization requests as JWTs. Request objects by value and by reference, validation rules, and how JAR differs from OIDC.</description><pubDate>Thu, 17 Apr 2025 11:02:06 GMT</pubDate><content:encoded>&lt;p&gt;In my &lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;last post&lt;/a&gt; — which I published almost a year ago — I explored whether the authorization code grant type truly provides the highest level of security, and what potential risks it might carry. This grant type is widely regarded as the recommended option when involving end users, both in the &lt;a href=&quot;https://datatracker.ietf.org/doc/rfc9700/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;OAuth 2.0 best current practices&lt;/a&gt; and the &lt;a href=&quot;https://datatracker.ietf.org/doc/draft-ietf-oauth-v2-1/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;OAuth 2.1&lt;/a&gt; draft specification.&lt;/p&gt;
&lt;p&gt;If you haven’t already, I highly recommend reading that &lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;first post&lt;/a&gt; before diving into this one.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Secure OAuth2 : Is Authorization Code Grant Type Secure Enough?&lt;/strong&gt;&lt;br&gt;
_The authorization code grant type is generally considered as the most secure, widely used and commonly recommended…_sagarag.medium.com&lt;/a&gt;&lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;To quickly recap — in the standard &lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc6749#section-4.1&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Authorization Code grant&lt;/a&gt; flow, the authorization request is sent by encoding all the necessary parameters directly into the URL as query parameters this approach is known as &lt;strong&gt;query parameter serialization&lt;/strong&gt;. This request then travels through the user agent (usually a browser) to the authorization server.&lt;/p&gt;
&lt;p&gt;While this approach works, it also comes with a few security shortcomings, here are some issues related to &lt;strong&gt;authorization request:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;P1&lt;/a&gt; &lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;—&lt;/a&gt; &lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Integrity protection failure&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;P2 — Source Authentication Failure&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;P3 — Confidentiality failure&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;P4 — Lack of Request as a Reference semantic&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The implications tied to the &lt;strong&gt;authorization response&lt;/strong&gt; of the authorization code flow includes:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;P5&lt;/a&gt; &lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;—&lt;/a&gt; &lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Server integrity protection failure&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;P6 — Client confidentiality failure&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;P7 — Mixed-up attack&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;To start with a bit of history — the questions that I mentioned earlier weren’t really addressed in the original &lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc6749&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;OAuth2 core specification&lt;/a&gt; released back in 2012. But if we go back to the basics and think about how we can sign and encrypt the request parameters themselves, we realize that most of these security concerns could be addressed right at the foundation level. Thankfully, we didn’t have to wait too long for a solution — around the same time, a JSON-based token format called &lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc7519&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;JWT&lt;/a&gt; started gaining traction, bringing along powerful signing capabilities through &lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc7515&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;JWS&lt;/a&gt; and encryption through &lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc7516&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;JWE&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In 2014, the &lt;a href=&quot;https://openid.net/specs/openid-connect-core-1_0.html&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;OpenID Connect (OIDC) core specification&lt;/a&gt; introduced a concept called the &lt;a href=&quot;https://openid.net/specs/openid-connect-core-1_0.html#JWTRequests&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Request Object&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;solving most of the above problem&lt;/strong&gt;. This is essentially a &lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc7519&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;JWT&lt;/a&gt; that encapsulates the request parameters, allowing the request to be signed using &lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc7515&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;JWS&lt;/a&gt; and optionally encrypted using &lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc7516&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;JWE&lt;/a&gt;. It helped to solve some of the earlier security concerns — but only within the context of OIDC.&lt;/p&gt;
&lt;p&gt;Then in 2017, the IETF began working on a new specification inspired by this idea, called &lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc9101&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;JWT-Secured Authorization Request&lt;/strong&gt;&lt;/a&gt; (or &lt;strong&gt;JAR&lt;/strong&gt;). After six years of discussion and iteration, in 2021 JAR finally became an official standard in the OAuth2 ecosystem. Because of that origin, the Request Object concept in OIDC is quite similar to what’s defined in the JAR spec — but it’s worth noting that there are still a few subtle incompatibilities between the two.&lt;/p&gt;
&lt;h4 id=&quot;request-object&quot;&gt;Request Object&lt;/h4&gt;
&lt;p&gt;The Request Object is really the heart of the JAR specification. It allows us to encode each part of the authorization request as individual JWT claims. To get a better sense of how this works, let’s start with a standard authorization request — like the one shown in the figure below.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*ua_ZRXJx1pQVu968QOHsAA.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Next, we translate those query parameter values into a JSON-encoded JWT. The following figure will show you what that same request looks like once it’s been encoded as a JWT.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*-bsMekPEePjaz2HhGVDAkg.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;There are a few rules that you need to follow when doing this. For instance:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;**iss**&lt;/code&gt;&lt;strong&gt;(issuer claim)&lt;/strong&gt; — This one is mandatory. In most cases, it should be the &lt;code&gt;client_id&lt;/code&gt; of your application. However, some authorization servers may support a custom value here, depending on prior agreements.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;**aud**&lt;/code&gt; &lt;strong&gt;(audience claim)&lt;/strong&gt; — This should match the issuer value of the Authorization Server (AS) you’re talking to.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The next step is signing the Request Object using JWS. This process involves generating a JOSE header, calculating the signature, and then producing the final JWT in compact format by applying base64url encoding — you can see how final result looks like in the figure below.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*bHsq_McEAwcNH7kyowhz4g.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;One important thing to keep in mind: the public key that matches the private key used for signing needs to be already configured on the authorization server. Ideally, this happens during the application or client registration phase. You can do this using &lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc7591&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Dynamic Client Registration&lt;/a&gt; (DCR) or whatever interface your authorization server provides for managing signature verification keys. This step is critical — without the corresponding public key, the authorization server won’t be able to verify the signature of the Request Object. But once it’s in place, the server can ensure that the Request Object really came from your client and that its content hasn’t been tampered with along the way. This directly addresses two of the earlier issues I mentioned: &lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;P1&lt;/a&gt; &lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;—&lt;/a&gt; &lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Integrity protection failure&lt;/a&gt; and &lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;P2 — Source Authentication Failure&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In addition to signing, you can optionally encrypt the signed JWT using JWE, based on a public key that has been agreed upon. This way, the encrypted Request Object can only be decrypted by the authorization server using its private key — which is never shared. This extra step ensures confidentiality between the client and the authorization server, effectively addressing &lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;P3 — Confidentiality failure&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;So, at this point, by using a signed (and optionally encrypted) Request Object, we’ve tackled first three problems: &lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;P1&lt;/a&gt; &lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;—&lt;/a&gt; &lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Integrity protection failure&lt;/a&gt; , &lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;P2 — Source Authentication Failure&lt;/a&gt; and &lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;P3 — Confidentiality failure&lt;/a&gt;. Now, let’s dive into the different ways the JAR specification allows us to send this JWT-secured Request Object to the authorization server.&lt;/p&gt;
&lt;h4 id=&quot;1-passing-authorization-request-byvalue&quot;&gt;1. Passing Authorization Request by Value&lt;/h4&gt;
&lt;p&gt;This is the most straightforward approach: the application takes the signed (or signed and encrypted) Request Object we created earlier and encodes it as the value of the &lt;code&gt;request&lt;/code&gt; query parameter. Then, it builds the authorization URL by including this encoded Request Object along with the &lt;code&gt;client_id&lt;/code&gt;, and sends it to the authorization server’s authorization endpoint. The diagram below illustrates how this flow works in practice. Other than the way the parameters are sent (now wrapped inside the &lt;code&gt;request&lt;/code&gt; parameter as a JWT), there’s really no change to the overall flow when compared to the standard Authorization Code authorization request phase.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*VRRPs8dI7ks4vi5ZMPHvhQ.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;And just to make it more clear, I’ve also included a sample authorization request for reference below.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*MlX1JgE255n8xV986Zt1cw.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;h4 id=&quot;2-passing-authorization-request-by-reference&quot;&gt;2. Passing Authorization Request by Reference&lt;/h4&gt;
&lt;p&gt;Instead of directly passing a signed (and optionally encrypted) Request Object in the authorization request, there’s another option — you can store the Request Object in a specific location that the Authorization Server can access. Then, rather than sending the full Request Object through the user agent, you just send a URI pointing to it. The Authorization Server can then fetch the Request Object using that URI to process the authorization request.&lt;/p&gt;
&lt;p&gt;This approach is considered more secure because the actual Request Object doesn’t pass through the user agent — it’s only available to the Authorization Server. It’s also a preferred method when dealing with large Request Objects or when your app needs to work on devices with limited processing power or slow internet connections (like mobile devices). The following diagram outlines how this flow works.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*gBfAXZsWC5Z7ufNNl9waMQ.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;During the &lt;strong&gt;step-1&lt;/strong&gt;, your client application creates the Request Object just like we discussed earlier and stores it in a location that’s accessible to the Authorization Server. This storage location can be:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A local endpoint hosted by your client application&lt;/li&gt;
&lt;li&gt;A remote endpoint hosted by the Authorization Server&lt;/li&gt;
&lt;li&gt;A trusted third-party endpoint&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Then comes &lt;strong&gt;step 2.&lt;/strong&gt; In this step, the client application builds the actual authorization request — but instead of including the full Request Object, it uses a new parameter introduced in the JAR specification called &lt;code&gt;request_uri&lt;/code&gt; along with the &lt;code&gt;client_id&lt;/code&gt; . The &lt;code&gt;request_uri&lt;/code&gt; parameter holds the URI pointing to the previously stored Request Object.&lt;/p&gt;
&lt;p&gt;The client sends this authorization request to the Authorization Server through the user agent, and the server fetches the actual Request Object using the provided URI. The following example shows what this kind of request looks like.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*IcpReCI_nKvXNgPAyarHIQ.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Once the Authorization Server receives the authorization request from the client application, it recognizes that it needs to fetch the actual Request Object. Using the value provided in the &lt;code&gt;request_uri&lt;/code&gt; parameter, it reaches out to that location and retrieves the Request Object to continue processing the request as usual. This approach works really well when you’re dealing with large Request Objects and also offers maximum security. Since the actual Request Object isn’t sent through the user agent, it avoids unnecessary exposure. This neatly solves the earlier mentioned &lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;P4 — Lack of Request as a Reference semantic&lt;/a&gt; problem.&lt;/p&gt;
&lt;h4 id=&quot;validating-jwt-based-requests&quot;&gt;Validating JWT-Based Requests&lt;/h4&gt;
&lt;p&gt;Once the Authorization Server receives the Request Object — either directly as an encoded parameter in the authorization request or as a reference (where the server fetches it) — the next step is validation. If the Request Object is encrypted, the Authorization Server first decrypts it as specified by the JWE standard. Since only the Authorization Server has the private key needed for decryption, we can be confident that confidentiality is maintained between the client application and the Authorization Server.&lt;/p&gt;
&lt;p&gt;Next, the server moves on to signature validation. It verifies the signature using the public key that was configured during the client application’s registration. A successful signature check ensures that the Request Object hasn’t been tampered with and also confirms that it truly originated from the signed client application.&lt;/p&gt;
&lt;p&gt;Just to recap, in this post we explored how J&lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc9101&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;WT-Secured Authorization Request&lt;/a&gt; (JAR) enhances the security of the standard authorization code grant type by introducing &lt;strong&gt;integrity protection&lt;/strong&gt;, &lt;strong&gt;source authentication&lt;/strong&gt;, &lt;strong&gt;confidentiality&lt;/strong&gt;, and support for &lt;strong&gt;request-by-reference&lt;/strong&gt; semantics.&lt;/p&gt;
&lt;p&gt;It’s been nearly five years since JAR became a standard, and we’re now seeing its concepts — especially the use of Request Objects along with signing and encryption — being adopted across different industry verticals. That said, the idea of passing the Request Object as a reference didn’t quite take off as expected. It turned out to be a bit too vague and open-ended for practical adoption.&lt;/p&gt;
&lt;p&gt;This is where the &lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc9126&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Push Authorization Request&lt;/a&gt; (PAR) specification steps in which I’ll dive into in my next post. PAR offers a more robust and standardized way to implement pass-by-reference while still building on the core benefits of JAR. Stay tuned!&lt;/p&gt;
&lt;h4 id=&quot;other-posts-in-the-secure-oauth2series&quot;&gt;Other posts in the secure OAuth2 series&lt;/h4&gt;
&lt;p&gt;Read the other posts in &lt;strong&gt;Secure OAuth2&lt;/strong&gt; series.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Secure OAuth2 : Is Authorization Code Grant Type Secure Enough?&lt;/strong&gt;&lt;br&gt;
_The authorization code grant type is generally considered as the most secure, widely used and commonly recommended…_sagarag.medium.com&lt;/a&gt;&lt;a href=&quot;https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;/a&gt;&lt;/p&gt;</content:encoded><dc:creator>Sagara Gunathunga</dc:creator><category>OAuth 2.0</category><category>JWT</category></item><item><title>Is the OAuth 2.0 Authorization Code Grant Secure Enough?</title><link>https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough</link><guid isPermaLink="true">https://sagarag.dev/posts/is-authorization-code-grant-type-secure-enough</guid><description>Seven real weaknesses in the OAuth 2.0 authorization code grant, from code interception to mix-up attacks, and the specs (PKCE, PAR, JAR, JARM) that fix them.</description><pubDate>Tue, 16 Apr 2024 22:02:01 GMT</pubDate><content:encoded>&lt;p&gt;The authorization code grant type is generally considered as the most secure, widely used and commonly recommended grant type within the OAuth2 framework requiring no special emphasis.&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;client credential grant type&lt;/strong&gt; serves a specific purpose, allowing OAuth2 clients (applications) to acquire an access token on their own behalf for use cases that don’t require end-user involvement. Let’s set client credential grant type aside for now. The &lt;strong&gt;implicit grant type&lt;/strong&gt;, despite its simplicity and convenience, comes with significant drawbacks. One key concern is its vulnerability to security threats, such as token leakage through browser history or referral headers due to the direct transmission of access tokens to the client-side application. Additionally, it lacks token refresh capabilities, necessitating clients to request new access tokens upon expiration, potentially disrupting user experience and complicating token management. Moreover, since the implicit grant lacks client authentication, it is susceptible to certain attacks. Similarly, the &lt;strong&gt;password grant type&lt;/strong&gt;, initially introduced as a transitional mechanism from security schemas like BasicAuth, also poses security risks by requiring users to disclose their credentials directly to third-party applications, ultimately undermining one of the key problems OAuth2 aimed to address.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*QI5anVomSHHZj1_A&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;In contrast to implicit and password grant types, the authorization code grant type employs a two-step process that significantly reduces the risk of interception of access tokens. This involves the client obtaining an authorization code from the authorization server after the user has been authenticated, without exposing the user’s credentials to the client. The authorization code is short-lived and can only be used once, mitigating the risk of replay attacks. Additionally, the exchange of the authorization code for an access token occurs through secure back-end communication. This separation of the client’s front-end and the authorization server’s back-end enhances security by minimizing the exposure of tokens. Furthermore, the ability to issue refresh tokens greatly simplifies token management complexity, allowing applications to securely obtain a new access token upon the expiration of the current access token without disturbing the user again. This makes it possible to implement best practices such as short-lived access tokens and long-lived refresh tokens&lt;/p&gt;
&lt;p&gt;However, in this post, I’m trying to discuss a crucial question: Despite being the preferred grant type over others, does the authorization code truly offer the highest level of security? Or should we aim to enhance the security measures even further? To answer this, let’s delve into the two-step flow of the authorization code grant type and closely analyze security measures.&lt;/p&gt;
&lt;h3 id=&quot;authorization-request&quot;&gt;&lt;strong&gt;Authorization Request&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*uktAYRtkhEcu2boy&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;As depicted in the above diagram, authorization code grant type starts with authorization request where an OAuth2 client, which is typically a mobile or a web application, initiates the authorization process by redirecting the user to the authorization server’s authorization endpoint. Typically when a user clicks the login link/button, the application perform the following sequence of activities:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Constructing an authorization request which involves building a URL with specific parameters. Typically this can be done using in-built features of an underlying framework or SDK used by the application providing the necessary parameters such as client_id, redirect_uri, response_type, scope and state. The authorization request is constructed by appending above parameter values to the URL of authorization endpoint as URL encoded query parameter values.&lt;/li&gt;
&lt;li&gt;In order to redirect the user to the authorization server, the application makes an HTTP GET request to the authorization endpoint of the authorization server along with the authorization request created in the above step.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Typically, you would be able to see the authorization request in the address bar of the browser.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*6ceM1AqH9Rp34HCa&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;P1 : Integrity protection failure&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;As you can see in the above diagram, the full authorization request is visible in the browser, which means that the communication between the web browser and the authorization server is not safeguarded against unauthorized modification or tampering. As a result, the authorization request could potentially be altered or manipulated by malicious actors without detection. For example, a malicious actor could forge a request to impersonate the application, or modify the authorization request before it reaches the authorization server. This scenario represents an integrity protection failure in security terms.&lt;/p&gt;
&lt;p&gt;Integrity protection failure implies that the integrity of the data being transmitted cannot be guaranteed, which is a fundamental security concern in any communication system specially in the context of OAuth2 client and authorization server communication. OAuth2 requires the use of TLS, which establishes a secure and encrypted transport channel, thereby reducing risks. While this measure may suffice for certain business scenarios, it fails to address the core issue: the inability to apply cryptographic integrity techniques to the authorization request.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;P2 — Source Authentication Failure&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;If we look at the above authorization request again, we can notice a couple of important parameters values. First, &lt;strong&gt;client_id&lt;/strong&gt; represents an unique identifier that helps the authorization server to uniquely identify the particular client. The OAuth2 requires the &lt;strong&gt;redirect_uri&lt;/strong&gt; in the authorization request to be matched with one of the redirect_uri values provided to the authorization server during the client registration. However, none of these parameters help the authorization server to authenticate the client, in other words, there is no assurance that the entity claiming to send the authorization request is actually who they claim to be. This scenario, known as source authentication failure, poses a significant security risk.&lt;/p&gt;
&lt;p&gt;In the 2nd step of the authorization code grant type, referred to as the token request flow, confidential clients like server-side web applications must authenticate with the authorization server when making token requests. This authentication step helps mitigate risks. However, when considering the authorization request flow alone, it lacks source authentication. It is also worth noting that client authentication during the token request flow does not apply to public clients such as browser-based applications and mobile applications.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;P3 — Confidentiality failure&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;As we saw in P1, the communication between the client and authorization server is fully visible in the browser, not just authorization requests. Instead the successful response from the authorization server called authorization response which contains the code grant is also visible in the browser. There is no fully acceptable measure to ensure these communications are not monitored by unauthorized parties leading to another issue known as confidentiality failure.&lt;/p&gt;
&lt;p&gt;Another possibility is that query string data containing OAuth 2.0 parameters has the potential to unintentionally expose at the web servers. This can occur when the data is logged by web servers or transmitted to other sites through the referrer header.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;P4 — Lack of Request as a Reference semantic&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;“By value” vs “By reference” is a well-known concept used in computer science. In the above authorization request, we embed actual parameter values within the request URL, representing the “by value” semantic. While this is a preferable option in simple scenarios, some application developers may prefer to use “by reference” semantics to tighten security or due to particle limitations such as exceeding the maximum size of the Get request.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc9396&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;OAuth 2.0 Rich Authorization Requests&lt;/a&gt; ( OAuth2 RAR) introduced a new parameter called “&lt;strong&gt;authorization_details&lt;/strong&gt;” to be used with the authorization request to facilitate communication of fine-grained authorization data with the authorization server. For example, the following payment initiation request used in Open Banking can be represented as a JSON object and then transmitted to the authorization server using the “authorization_details” parameter. When sending sensitive financial information, due to the fact that all this information is visible in the browser, the developer may prefer to use “by reference” semantics rather than “by value” semantics.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*7Jzbqvrbeq-_Vqat&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Taking another scenario related to API security, the &lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc8707&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Resource Indicators for OAuth 2.0&lt;/a&gt; specification defines a new parameter called “&lt;strong&gt;resource&lt;/strong&gt;” so that the client can indicate the target service or resource to which access is required. For example, a typical request can be as follows. However, in a real-world scenario, the resources list can be lengthy and may exceed the maximum size supported by the web browser and web server for HTTP GET requests. In such cases, “by reference” semantics come in very handy.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*YZQ2gTSjNkfi2F9k&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;As we looked at in the above example cases, the lack of “by reference” semantics can also be considered a security or practical limitation of the authorization request depending on the business use case.&lt;/p&gt;
&lt;h3 id=&quot;authorization-response&quot;&gt;Authorization Response&lt;/h3&gt;
&lt;p&gt;So far we mainly focused on the authorization request part of the flow. Now, let’s move into the authorization response part of the flow.&lt;/p&gt;
&lt;p&gt;After the end user is authenticated with the authorization server and has consented to grant access to the particular resource, the authorization server redirects the end user back to the application using the URL mentioned in the redirect_uri parameter of the request, along with the code grant and state parameter.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*DrLiX5-VQBEzwV9_&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Similar to the authorization request, the authorization response is also encoded using the URL encoding schema and fully visible in the browser. Thus, some of the issues we discussed in the previous section are applicable to authorization responses as well.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;P5 : Server integrity protection failure&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;When an authorization server returns back to an application with a code grant, it would appear as below in the browser’s address bar.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*CSQ-BnbAQnh2xsUz&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Essentially, the authorization server appends the &lt;strong&gt;code&lt;/strong&gt; and other parameters such as scope and state into the redirect_uri of the client application as query string values, making it easy for the client to process these parameters. This simplifies the processing of the response and makes it efficient.&lt;/p&gt;
&lt;p&gt;On the flip side, there is no mechanism for the client to validate whether the authorization response has been altered or modified during transit, or whether the response has been actually produced by the legitimate authorization server. This can be considered as an integrity protection failure from the client application’s point of view. There is no possibility to employ a cryptographic integrity protection mechanism such as signing or encryption for the authorization response.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;P6 — Client confidentiality failure&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The code grant is intended to be used exclusively by the client application and ideally should be known only to the client application. However, as seen in the diagram above, the authorization code grant type was designed in such a way that the code grant generated at the authorization server is transmitted to the client application using a web browser as intermediary. This can lead to situations where an attacker may monitor the flow and potentially steal the code, or the code can be leaked to web server logs. This results in a confidentiality failure for the client&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;P7 — Mixed-up attack&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This is a well-known attack related to OAuth2. In this attack, an attacker tricks a client into sending an authorization code to an authorization server controlled by the attacker instead of the intended legitimate authorization server. The client “mixes up” which authorization server it is interacting with. This is primarily because the client can’t distinguish the authorization response from a legitimate authorization server from one sent by a malicious authorization server. This can easily occur in open banking applications because generally each financial service maintains their own authorization server, and the applications usually have to support multiple financial services, hence multiple authorization servers.&lt;/p&gt;
&lt;p&gt;In a summery, in this post we have looked at some of the critical security implications related to OAuth2 authorization code grant type specially related to authorization request and response. &lt;strong&gt;Before finishing this post, I want to emphasize that my intention in discussing all these issues related to the authorization code grant type is not to discourage its use, but rather to introduce and promote architectural improvements that have been standardized over time to address some of the above discussed limitations. We will discuss these improvements in the next couple of posts.&lt;/strong&gt;&lt;/p&gt;</content:encoded><dc:creator>Sagara Gunathunga</dc:creator><category>OAuth 2.0</category></item><item><title>OAuth 2.0 Token Exchange (RFC 8693) in Practice</title><link>https://sagarag.dev/posts/oauth2-token-exchange-in-practice</link><guid isPermaLink="true">https://sagarag.dev/posts/oauth2-token-exchange-in-practice</guid><description>Practical OAuth 2.0 Token Exchange (RFC 8693): impersonation vs delegation, the act claim, scope down-scoping, cross-domain and workload identity use cases.</description><pubDate>Mon, 25 Sep 2023 21:45:36 GMT</pubDate><content:encoded>&lt;p&gt;Over time, OAuth2 has evolved to meet increasingly complex security needs that go beyond the basic capabilities of a Security Token Service (STS). In this post, we will discuss the &lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc8693&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Token Exchange grant type&lt;/a&gt; which is a versatile grant type designed to tackle a range of real-world challenges.&lt;/p&gt;
&lt;p&gt;At its core, Token Exchange facilitates client applications obtaining new security tokens by exchanging them for previously acquired tokens. What’s interesting is that this previous token can come from the same Identity Provider (IdP) that issues the new token or originate from a different IdP in a trusted domain.&lt;/p&gt;
&lt;p&gt;But why should we care about the Token Exchange grant type? Let’s dive into a couple of practical scenarios to see how it can make a difference. But before that, let’s explore two important concepts — impersonation and delegation.&lt;/p&gt;
&lt;h4 id=&quot;impersonation-vs-delegation&quot;&gt;Impersonation Vs delegation&lt;/h4&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*T7Xl77B4wE5XP7JKxLH-yQ.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Let’s introduce our imaginary friend, Bob, a music enthusiast who has meticulously curated a collection of super cool playlists on an online music streaming platform. Bob takes great pride in his playlists. Now, enter Alice, a close friend of Bob’s, who seeks access to his playlists to find the perfect soundtrack for her upcoming road trip. Let’s examine their interaction within the streaming platform.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*E1uDSbwCuPD9gQcatCIfqw.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;In this case, Alice is impersonating Bob:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The access credentials provided to the streaming platform don’t contain any information to recognize Alice’s identity.&lt;/li&gt;
&lt;li&gt;Whenever Alice accesses the platform, it believes Bob is the one using the service although the credentials (e.g. — a short-lived access token) used by Alice to access the service are different from Bob’s credentials.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Over time, the music streaming service has introduced features to support family and friend sharing. In this evolved scenario, Alice can pass her identity information along with the temporary pass provided by Bob. So the scenario can be considered as delegation now.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*H7ac4jBeehzbVdSd24gapg.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;In the case of delegation:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The access credentials to the streaming service contain information to recognize Alice’s identity in addition to Bob’s identity.&lt;/li&gt;
&lt;li&gt;When Alice accesses the service, it distinguishes between Bob and Alice, acknowledging Alice as Bob’s agent.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now that we understand these concepts, let’s explore the practical use cases of the Token Exchange.&lt;/p&gt;
&lt;h4 id=&quot;1-api-gateway-calls-backend-api-on-behalf-of-aclient&quot;&gt;1. API Gateway Calls Backend API on Behalf of a Client&lt;/h4&gt;
&lt;p&gt;Imagine a scenario where an application possesses a security token from the IdP to access an API Gateway (API-GW) obtained through a prior interaction between the IdP and the end user. However, this existing security token, while sufficient for API-GW access, may not grant access to the backend API due to audience and scope restrictions. For instance, if the token is a JWT, its audience (&lt;em&gt;aud&lt;/em&gt;) may be limited to the API-GW, and its scopes may be specific to the API-GW only. While one workaround might involve including the backend API audience and scopes in the token, this is not ideal from an API security perspective.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*Nyw0JEOfmoeW-Cu2q0k8Zg.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;The token shown in the diagram above would be valid for the API-GW since it has the right audience value for the API-GW and includes the required scopes defined by the API-GW. However, if you try to use the same token with the BE-API, it won’t work because the token isn’t intended for the BE-API and will be rejected by the BE-API after looking at the audience claim.&lt;/p&gt;
&lt;p&gt;In this case, the right approach would be for the API-GW to request a new security token suitable for calling the backend API from the IdP by trading the current token sent by the client application. The Token Exchange grant type facilitates this exchange, allowing the API-GW to request the audience and request scopes from the backend API.&lt;/p&gt;
&lt;p&gt;The API-GW has the flexibility to choose between impersonation and delegation. In impersonation, the API-GW keeps its identity hidden from the backend API and acts as the end user accessing the API through the client application. In delegation, the backend API recognizes that the API-GW is acting on behalf of the client application, which has obtained authorization from the end user. The choice between these approaches depends on the specific design, business and security requirements of the system.&lt;/p&gt;
&lt;h4 id=&quot;2-microservice-calls-another-downstream-microservice&quot;&gt;2. Microservice Calls Another Downstream Microservice&lt;/h4&gt;
&lt;p&gt;This scenario closely resembles the previous one, with the primary difference being that the interaction occurs between two microservices, omitting the API-GW. Within a well-designed microservices security architecture, microservices only accept tokens if the tokens are intended to be used by the specific microservice typically with the correct audience and scope claims. Similar to the previous use case, the initial security token may not grant sufficient access to the downstream microservice, necessitating a Token Exchange call.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*xL7rXMkoetu3VigC32-teA.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Again, the token shown in the diagram above is valid for the Customer-Service microservice because it has the right audience value for the Customer-Service and includes the required scopes as well. However, if you try to use the same token with the Order-Service, it won’t work because the token isn’t intended for the Order-Service and will be rejected by the Order-Service after looking at the audience claim.&lt;/p&gt;
&lt;h4 id=&quot;3-upgrading-or-downgrading-the-scope-of-securitytokens&quot;&gt;3. Upgrading or downgrading the Scope of Security Tokens&lt;/h4&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*I8CU6pYJWt7Pgmn3vO7x2Q.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Security best practices emphasize the principle of least privilege, within the context of our current discussion, applications should initially request a token with the minimal scopes required for current functionality, without making assumptions about future functionality that might require additional scopes. For instance, a mobile banking app might request a security token initially with read-only scopes for account data, such as balances and statements. When a user intends to perform a transaction like a fund transfer, the app can request the IdP to issue a new token with additional scopes. Token Exchange is a preferred solution for scope upgrades, as opposed to making duplicate token requests or using refresh tokens. The same would be applicable to scope downgrading too, as soon as an application has completed a transaction that requires a higher level of authorization such as in a fund transfer transaction, it should exchange an existing token for a token associated with a limited number of scope to avoid unwanted risk.&lt;/p&gt;
&lt;p&gt;In some cases, an IdP may be configured to issue an IDToken during user login while delaying the issuance of an access token until the user engages in specific actions, such as transactions. Token Exchange becomes practical in such scenarios, allowing the application to obtain the required access token with required scopes when needed.&lt;/p&gt;
&lt;h4 id=&quot;4-application-accessing-resources-in-a-different-trustdomain&quot;&gt;4. Application Accessing Resources in a Different Trust Domain&lt;/h4&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*S2iA3I8gL0k7YBbvgCM4Og.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Consider a situation where an application possesses an access token issued by the default IdP within its trust domain, which could be the same organization or department. Now, the application needs to access an API called Loyalty API residing in a different trust domain, possibly maintained by a partner organization and secured using a different IdP called Loyalty-IdP. The application must obtain a security token from the Loyalty-IdP to access the Loyalty API. This is another use case perfectly suited for the Token Exchange grant type. However, compared to previous scenarios, this involves two trust domains and two IdPs, necessitating the existence of a trust relationship between these IdPs.&lt;/p&gt;
&lt;h4 id=&quot;5-workload-identity-federation&quot;&gt;5. Workload Identity Federation&lt;/h4&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*a1xy0ABn2L7-Is3zFD78EQ.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;While this scenario shares similarities with the previous use case, I wanted to consider it as a separate use case due to the growing adoption of Workload Identity Federation patterns. Unlike traditional on-premise infrastructure, workloads deployed in cloud environments, such as AWS, Azure, GCP, or Kubernetes receive some notion of an identity from the cloud provider typically in the form of a token. In this scenario, an application or service deployed in a cloud environment seeks to access a Loyalty API deployed by a partner organization in a different trust domain. Since the Loyalty API operates in a separate trust domain, the identity token issued by the underlying cloud provider isn’t sufficient. The workload must exchange its identity token with the Loyalty-IdP to obtain a new access token and access the Loyalty API. Token Exchange is an ideal solution for this scenario, and major cloud providers already support this pattern.&lt;/p&gt;
&lt;p&gt;As in previous use cases, establishing trust between the Loyalty-IdP and the cloud provider’s IdP is essential. For further details on the Workload Identity Federation, stay tuned for my upcoming post dedicated to this topic.&lt;/p&gt;
&lt;p&gt;Now that we’ve gained a solid understanding of the potential use cases for the Token Exchange grant type, it’s time to delve into the specifics of how this grant type works. One important point to mention, the Token Exchange grant type is very flexible, it lays out request and response messages, along with the message flow. However, it leaves certain crucial aspects open for implementation decisions, such as the supported token types and trust relationships, which are particularly important in cross-domain scenarios.&lt;/p&gt;
&lt;h4 id=&quot;request-response-and-theflow&quot;&gt;Request, response, and the flow&lt;/h4&gt;
&lt;p&gt;We will start by exploring various use cases, beginning with the scenario where token exchange occurs within the same trust domain, facilitated by a single Identity Provider (IdP).&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*cuhDIPwe-HM1vYmyT8VkMA.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;In this scenario, an application initially acquires an access token. This token is obtained either by redirecting the end user to the IdP or by using the client credentials grant type. The received access token is then presented to the API-GW during an API call. The audience of this token is set to “api-gw,” and its scopes are aligned with those related to the API-GW.&lt;/li&gt;
&lt;li&gt;After validating the received access token, the API-GW creates a Token Exchange request and initiates the exchange flow by sending it to the IdP. Here, in the context of Token Exchange interaction, the API-GW plays the role of the OAuth2 client. This is an example where an API-GW that is generally recognized as a Resource Server (RS) within the OAuth2 terminology is designated as an OAuth2 client within the context of the Token Exchange. In the bottom line, depending on the circumstance, an entity different from a traditional OAuth2 client (e.g. — web and mobile apps) can participate in the Token Exchange by playing the client role.&lt;/li&gt;
&lt;li&gt;As the next step, the IdP validates the Token Exchange request and issues a fresh access token. This new token has “be-api” as its &lt;em&gt;aud&lt;/em&gt; (audience) claim value and includes the requested scope within the &lt;em&gt;scope&lt;/em&gt; claim. The API-GW can request necessary scope values to access the BE-API using the scope request parameter.&lt;/li&gt;
&lt;li&gt;The API-GW utilizes the newly received access token to successfully call the Backend API (BE-API).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As per the Token Exchange specification, the following parameters are mandatory in the request:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;grant_type&lt;/strong&gt;: This parameter signals to the IdP that this is a token exchange request.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;subject_token&lt;/strong&gt;: This parameter carries the current token received from the client, intended for exchange.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;subject_token_type&lt;/strong&gt;: Denotes the type of the subject token (e.g., OAuth2 access token, OIDC IDToken, or SAML token).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*700YsbXT-4nakUNekgSJXw.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;requested_token_type&lt;/strong&gt;: (Optional) This parameter allows the client application to specify the desired token type. In the absence, the IdP may determine the token type based on the application’s configuration.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;While not mandatory, parameters such as audience, resource, and scope are valuable for providing essential information about the target backend service to the IdP. This information helps the IdP identify the appropriate access policy for the target backend.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*7WAV4LOKNtTPsWG2Et5LPg.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;As shown in the diagram above, the ‘resource’ parameter typically points to the location of the target, often represented as an HTTP URL. Meanwhile, the ‘audience’ parameter is reserved for the logical name associated with the target, a logical target name recognized by the Identity Provider (IdP). To specify the necessary scope for the target, you can include these scopes within the ‘scope’ request parameter.&lt;/p&gt;
&lt;p&gt;Here is a sample Token Exchange request message that I used with &lt;a href=&quot;https://wso2.com/asgardeo/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Asgardeo&lt;/a&gt; — a cloud identity provider from WSO2.&lt;/p&gt;
&lt;p&gt;In the impersonation use case demonstrated above, to employ Token Exchange in delegation, two additional parameters are required: &lt;em&gt;actor_token&lt;/em&gt; and &lt;em&gt;actor_token_type&lt;/em&gt;. These parameters provide identity information about the party requesting a new token. For example, a customer-service application intending to call an order service with an exchanged token indicates its identity by passing these parameters.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*j_n2EN0RVBmagwVg1hvQzw.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;The two additional parameters used in delegation:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;actor_token&lt;/strong&gt;: The token that contains the information related to the identity of the token requesting party.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;em&gt;actor_token_type&lt;/em&gt;&lt;/strong&gt;: Denotes the type of the actor token.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The specification does not define any specific criteria for subject tokens to be considered valid for the token exchange. Nevertheless, it introduces the &lt;em&gt;may_act&lt;/em&gt; claim, which an IdP could utilize to ascertain whether the requesting party is authorized to exchange their current subject token for a delegated token. This authorization can be verified by cross-referencing the &lt;em&gt;may_act&lt;/em&gt; claim with either the requesting client’s identity or the identity information of the actor token.&lt;/p&gt;
&lt;p&gt;Implementation of Token Exchange varies: some might insist on the presence of the &lt;em&gt;may_act&lt;/em&gt; claim in the subject token as a mandatory requirement, while others might consider it optional. Additionally, there’s no standardized method for configuring and including &lt;em&gt;may_act&lt;/em&gt; in the initial token destined to become the subject token in a subsequent stage. One possible approach could be treating the &lt;em&gt;may_act&lt;/em&gt; configuration as a client-specific setting in the IdP.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*o9twg0A-fi9yYzdnTtuSpA.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;The Token Exchange specification does not impose specific requirements for client registration or client authentication. However, in practical implementations, client authentication, often involving client secrets or other methods, is commonly employed to achieve the desired protection.&lt;/p&gt;
&lt;p&gt;The Token Exchange response closely resembles standard OAuth2 responses but includes two additional parameters:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;issued_token_type&lt;/strong&gt;: This parameter signifies the type of the issued token, aligning with parameters like &lt;em&gt;requested_token_type,&lt;/em&gt; &lt;em&gt;subject_token_type,&lt;/em&gt; and &lt;em&gt;actor_token_type&lt;/em&gt; from the request.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*yxTfj1KAvf1EoiTz6AVRPQ.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;token_type&lt;/strong&gt;: Unlike the previously mentioned parameters, this parameter informs the client how to use the access token to access the target resources. For example, a value of &lt;strong&gt;Bearer&lt;/strong&gt; indicates that the issued security token can be presented as is, without additional proof of eligibility.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Also, the &lt;strong&gt;access_token&lt;/strong&gt; parameter in the response can be used to return various token types, not limited solely to access tokens. Here is a sample Token Exchange response message which returns an access token.&lt;/p&gt;
&lt;p&gt;Now, let’s move into a cross-domain use case that we discussed above which involves two different IdPs.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*u9BLClSxr3XLnbEmiN6c3g.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;In this scenario, the Sales app initially acquires an access token from the Sales-IdP. This token allows access to the required API calls within the Sales-API.&lt;/li&gt;
&lt;li&gt;When the application needs to call the Loyalty-API to complete a business transaction, it creates a Token Exchange request. This request utilizes the current access token issued by the Sales-IdP.&lt;/li&gt;
&lt;li&gt;The Loyalty-IdP validates the received Token Exchange request. Notably, Loyalty-IdP recognizes the subject token’s origin, issued by the Sales-IdP, and proceeds to validate the token’s signature. While the specification does not prescribe a trust model or verification mechanism, a widely used approach is the JSON Web Key Set (JWKS), which contains public keys for signature verification. To establish trust, Loyalty-IdP should be configured with a JWKS URL from the Sales-IdP. However, it’s possible for an Idp to use different mechanisms to obtain the public keys of the other IdP involved such as directly uploading public keys.&lt;/li&gt;
&lt;li&gt;Upon successful verification, Loyalty-IdP issues a new access token, tailored to the correct audience and scope values required to access the Loyalty-API.&lt;/li&gt;
&lt;li&gt;The Sales app utilizes the newly received access token to seamlessly call the Loyalty-API and complete the intended business transaction.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;the-actclaim&quot;&gt;The act claim&lt;/h4&gt;
&lt;p&gt;When delegation is used, sometimes it’s important to indicate that the delegation has occurred and who is the acting party. This is achieved through the use of the &lt;em&gt;act&lt;/em&gt; claim by the IdP, which plays a role in signaling that delegation has occurred and provides essential information about the identity of the acting party. The &lt;em&gt;act&lt;/em&gt; claim can be included in the introspection response of a delegated token, serving a consistent purpose throughout the token exchange process.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*Z9UrE6wKVBf6_96hbzw9Dw.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;One noteworthy feature of the &lt;em&gt;act&lt;/em&gt; claim is its structure as a JSON object. This structural flexibility is significant because it allows the &lt;em&gt;act&lt;/em&gt; claim to capture a delegation chain by nesting &lt;em&gt;act&lt;/em&gt; claims within one another. However, when making policy decisions, only the outermost &lt;em&gt;act&lt;/em&gt; claim should be considered and the nested &lt;em&gt;act&lt;/em&gt; claims are to provide information about the delegation chain. This nesting capability is quite important in token-based systems to represent complex delegation scenarios when involving multiple entities.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*D37iMr0ORS9yBdjsog_ORg.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;As we explored a couple of practical applications of the Token Exchange grant type in detail, I hope you gained some understanding of how to leverage this grant type in real-world scenarios.&lt;/p&gt;
&lt;p&gt;Stay tuned for more insights into the world of OAuth2 and identity management, where we’ll continue to bridge some gaps.&lt;/p&gt;</content:encoded><dc:creator>Sagara Gunathunga</dc:creator><category>OAuth 2.0</category><category>Delegation</category></item><item><title>OAuth 2.0 Dynamic Client Registration (DCR) Explained</title><link>https://sagarag.dev/posts/how-to-register-and-manage-oauth2-clients</link><guid isPermaLink="true">https://sagarag.dev/posts/how-to-register-and-manage-oauth2-clients</guid><description>How OAuth 2.0 clients register with an authorization server: out-of-band vs Dynamic Client Registration (RFC 7591) and DCR Management (RFC 7592), with examples.</description><pubDate>Mon, 19 Apr 2021 20:56:54 GMT</pubDate><content:encoded>&lt;p&gt;In the &lt;a href=&quot;https://sagarag.dev/posts/understanding-oauth2-landscape&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;first post&lt;/a&gt; of this blog series about the OAuth2, I provided a comprehensive overview of the OAuth2 core specification and its supporting specification. In the &lt;a href=&quot;https://sagarag.dev/posts/how-do-you-discover-the-oauth2-server-configuration&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;2nd post&lt;/a&gt;, I discussed the OAuth2 Authorization Server Metadata specification. In this post, I will discuss the OAuth2 Dynamic Client Registration (DCR) and the OAuth2 Dynamic Client Registration Management (DCR-M) protocols that play and vital role in the practical use of OAuth2.&lt;/p&gt;
&lt;p&gt;Having a basic understanding of the Authorization Code grant type is a prerequisite for this current post, and you refer to my OAuth2 overview post from here.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*Fd1oPwyEj_j5cho0&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;As you know, the Authorization Code grant type consists of two distinct steps and let’s pay attention to the following requirements of each step.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Step 1 (Authorization code request )&lt;/em&gt;&lt;/strong&gt; — in this step, when the client is making the authorization request, it should pass the client_id to the AS for the client identification.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step 2 (Access token request)&lt;/strong&gt; — In this step, when the client is making the authorization request, it should send both &lt;strong&gt;client_id&lt;/strong&gt; and &lt;strong&gt;client_secret&lt;/strong&gt; so that the AS can authenticate the client.&lt;/p&gt;
&lt;p&gt;Well, this post’s base problem is how a client obtains this client_id and client_secret in the first place? Because without these, the client can’t be involved in any successful communication with the AS.&lt;/p&gt;
&lt;p&gt;To give you a high-level answer, there are two mechanisms available:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Use out-of-band channels such as registration portals, emails etc.&lt;/li&gt;
&lt;li&gt;Use DCR and DCR-M protocols.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Regardless of whatever approach is used, it’s required to provide some mandatory information to the AS during the client registration; the most important values are &lt;strong&gt;Application Name&lt;/strong&gt; and &lt;strong&gt;Callback URL&lt;/strong&gt;.&lt;/p&gt;
&lt;h3 id=&quot;client-registration-via-out-of-band-channels&quot;&gt;Client registration via out-of-band channels&lt;/h3&gt;
&lt;p&gt;In this approach, there is a web portal maintained by the OAuth2 provider. There is a web portal available with the AS so that the client developers can logged-in and register an application themselves. Once the registration is completed, the client developer is provided with the &lt;strong&gt;client_id&lt;/strong&gt; and &lt;strong&gt;client_secret.&lt;/strong&gt; There is no standard around this approach; however, most of these web portals are self-explanatory and do not require any prior knowledge.&lt;/p&gt;
&lt;p&gt;Here is an example: OAuth2 application page from GitHub.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*CkYOQ4k9rdUP-9EW&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;his approach provides a great user experience for humans, but lack of standard makes it hard for a non-human software agent to deal with the AS; that is the main downside of this approach. One possible solution would be to develop a simple RESTful API so that software agents can easily interact with the AS, and that is what exactly has achieved in DCR and DCR-M protocols.&lt;/p&gt;
&lt;p&gt;The following are the two examples of client registration portals that are available with the ASs.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*vDwzZLMHBqnsJZfq&quot; alt=&quot;&quot;&gt;
&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*SCXH0IOUMMh3d0wq&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;oauth2-dcr-and-dcr-m-specifications&quot;&gt;OAuth2 DCR and DCR-M specifications&lt;/h3&gt;
&lt;p&gt;Both &lt;a href=&quot;https://tools.ietf.org/html/rfc7591&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;OAuth2 Dynamic Client Registration&lt;/a&gt; (OAuth2 DCR ) and &lt;a href=&quot;https://tools.ietf.org/html/rfc7592&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;OAuth2 Dynamic Client Registration Management&lt;/a&gt; (OAuth2 DCR-M) are generalizations of &lt;a href=&quot;https://openid.net/specs/openid-connect-registration-1_0.html&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;OpenID Connect Dynamic Client Registration&lt;/a&gt; (OIDC DCR) protocol to cover a wider scope than the OpenID Connect protocol. In other words, OIDC DCR was first developed, and then OAuth2 DCR and DCRM were developed by generalizing OIDC DCR protocol. The following diagram depicts the relationship between these protocols.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*rKuy06kj0kxcPs7I&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;oauth2-dynamic-client-registration&quot;&gt;OAuth2 Dynamic Client Registration&lt;/h3&gt;
&lt;p&gt;The objective of the OAuth2 DCR protocol is to define a mechanism for dynamically registering OAuth2 Client with authorization servers (ASs). The OAuth2 DCR defines:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;A RESTful client registration endpoint.&lt;/li&gt;
&lt;li&gt;Message formats for the client registration request and response messages.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The message format can take two forms: a plain JSON format or singed JWT format, which also known as Software Statement. In the case of singed JWT, the signing party, also known as the issuer, is vouching for the data’s validity. Either the client development organization itself or an authorized 3rd party entity can issue a Software Statement. Use of Software Statement for OAuth2 DCR is becoming popular in some industries such as Open Banking.&lt;/p&gt;
&lt;p&gt;The client registration endpoint is a RESTful endpoint that should be available on ASs so that client can register themselves with the AS. The registration endpoint should be a protected endpoint using some kind of a security mechanism. Initial access tokens and API tokens are some popular options; however, this initial credential’s distribution and format are not defined in the OAuth2 DCR specification.&lt;/p&gt;
&lt;p&gt;The following are some of the widely-used JSON values used in both request and response messages; you can find the complete list of these attributes &lt;a href=&quot;https://tools.ietf.org/html/rfc7591#section-2&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;client_id&lt;/strong&gt; — This is a unique identifier that can be used to identify the client within the AS scope. Generally, the AS generate client_id and included in the response message. However, some OAuth2 services accept client provided client_id as well. The client_id is a required value in the response message. In simple words, without this identifier, the client can’t perform any communication with the AS.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;client_secret&lt;/strong&gt; — Like client_id, this is usually generated by the AS and communicates back to the client. The purpose of client_secret is to authenticate the client when necessary when this present along with the client_id. For example, the token request of the authorization code grant type uses client authentication.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;redirect_uris&lt;/strong&gt; — This is one of the most important value that the client should provide within the registration request. The AS use this URL to send access tokens and authorization grants. For instance, in the authorization code grant type, this client endpoint location is used to send both ‘code’ and access token to the client.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;grant_types&lt;/strong&gt; — supported grant types of clients such as &lt;strong&gt;authorization_code&lt;/strong&gt;, &lt;strong&gt;client_credentials&lt;/strong&gt; etc.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;response_types&lt;/strong&gt; — supported response types of clients such as c&lt;strong&gt;ode&lt;/strong&gt;, &lt;strong&gt;token&lt;/strong&gt; etc.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;client_name&lt;/strong&gt; — A human-readable client name.&lt;/p&gt;
&lt;p&gt;Extending protocols such as OpenId Connect Dynamic Client registration protocol and the protocol implementers can also define and use additional parameters.&lt;/p&gt;
&lt;h3 id=&quot;dynamic-client-registration-flow&quot;&gt;Dynamic Client Registration Flow&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*yxyM-KSWc6Vtiqbr&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;This is a very simple flow that consists of just two steps; but, I have made it into 3 steps so that you can understand the flow easily.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step 0&lt;/strong&gt; — The client should have some sort of initial credential to access the registration EP; this could be an initial access token, API key etc. Any out-of-band channel can be used to distribute this initial credential.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt; — The client sends the client’s configuration data within the registration request message. As we already discussed, this can be either plain JSON or a signed JWT message. An HTTP POST should be used to send this message to the AS’s registration EP over HTTPS.&lt;/p&gt;
&lt;p&gt;Here is a sample request message.&lt;/p&gt;
&lt;p&gt;POST /register HTTP/1.1&lt;/p&gt;
&lt;p&gt;Content-Type: application/json&lt;/p&gt;
&lt;p&gt;Accept: application/json&lt;/p&gt;
&lt;p&gt;Host: server.example.com&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;“redirect_uris”: [&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light nord&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#d8dee9ff;--shiki-light-bg:#fff;--shiki-dark-bg:#2e3440ff; overflow-x: auto; white-space: pre-wrap; word-wrap: break-word;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  “https://client.example.org/callback&quot;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;   “https://client.example.org/callback2&quot;\],&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;“client_name”: “My Example Client”,&lt;/p&gt;
&lt;p&gt;“token_endpoint_auth_method”: “client_secret_basic”,&lt;/p&gt;
&lt;p&gt;“logo_uri”: “&lt;a href=&quot;https://client.example.org/logo.png&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://client.example.org/logo.png&lt;/a&gt;”,&lt;/p&gt;
&lt;p&gt;“jwks_uri”: “&lt;a href=&quot;https://client.example.org/my%5C_public%5C_keys.jwks&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://client.example.org/my\_public\_keys.jwks&lt;/a&gt;”,&lt;/p&gt;
&lt;p&gt;“example_extension_parameter”: “example_value”&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt; — Once the AS validated and registered by the client, the AS reply back to the client with registered client data as a JSON payload; this is known as the client registration response message. Generally, the AS generates &lt;strong&gt;client_id &amp;#x26; client_secret&lt;/strong&gt; and are included in the registration response message. However, some AS vendors accepts client provided client_id &amp;#x26; client_secret as well; in such cases, the client registration response message can be used to send the client_id &amp;#x26; client_secret.&lt;/p&gt;
&lt;p&gt;Here is a sample response message.&lt;/p&gt;
&lt;p&gt;HTTP/1.1 201 Created&lt;br&gt;
Content-Type: application/json&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;“client_id”: “s6BhdRkqt3”,&lt;/p&gt;
&lt;p&gt;“client_secret”: “cf136dc3c1fc93f31185e5885805d”,&lt;/p&gt;
&lt;p&gt;“client_id_issued_at”: 2893256800,&lt;/p&gt;
&lt;p&gt;“client_secret_expires_at”: 2893276800,&lt;/p&gt;
&lt;p&gt;“redirect_uris”: [&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light nord&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#d8dee9ff;--shiki-light-bg:#fff;--shiki-dark-bg:#2e3440ff; overflow-x: auto; white-space: pre-wrap; word-wrap: break-word;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;     “https://client.example.org/callback&quot;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;      “https://client.example.org/callback2&quot;\],&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;“grant_types”: [“authorization_code”, “refresh_token”],&lt;/p&gt;
&lt;p&gt;“client_name”: “My Example Client”,&lt;/p&gt;
&lt;p&gt;“token_endpoint_auth_method”: “client_secret_basic”,&lt;/p&gt;
&lt;p&gt;“example_extension_parameter”: “example_value”&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;h3 id=&quot;oauth2-dynamic-client-registration-management&quot;&gt;OAuth2 Dynamic Client Registration Management&lt;/h3&gt;
&lt;p&gt;As you probably have noticed, the OAuth2 DCR protocol only facilitates registering OAuth2 client applications with the AS. It does not facilitate updating, deleting or reading OAuth2 applications. The purpose of the OAuth2 DCRM protocol is to fill this gap by defining a mechanism to read, update and delete OAuth2 client dynamically.&lt;/p&gt;
&lt;h3 id=&quot;dynamic-client-registration-management-flows&quot;&gt;Dynamic Client Registration Management Flows&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*57adnVvstBZQo-L4&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;As shown in the above diagram, OAuth2 DCRM defines an endpoint called Client Configuration Endpoint. Still, according to REST best practice, the registration endpoint that is defined in OAuth2 DCR protocol is used as the Client Configuration Endpoint. The Client Configuration Endpoint is secured with a special token known as Registration Access Token, which is issued by the client registration endpoint during the client registration. However, in practice, Registration Access Token is not widely used; instead of initial access tokens, API tokens are pretty common.&lt;/p&gt;
&lt;p&gt;DCR defines three main flows. However, all these flows assumed that the client has already registered with the OAuth2 AS via OAuth2 DCR protocol or some other means.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;) As per the OAuth2 DCR protocol, an OAuth2 client makes an HTTP POST request to the registration EP with client data. After registering the client, the AS returns the registration response according to the OAuth2 DCR protocol. In addition to that, this response message should contain the following two parameters.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;registration_access_token&lt;/strong&gt; — This can be used with subsequent flows such as reading, updating and deleting the client.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;registration_client_uri&lt;/strong&gt; — An URI pointing to the client configuration endpoint.&lt;/p&gt;
&lt;p&gt;However, some implementors tend to have some relaxation on &lt;strong&gt;registration_access_token&lt;/strong&gt; and &lt;strong&gt;registration_client_uri&lt;/strong&gt; and more focus on the RESTfull functionality of the protocol.&lt;/p&gt;
&lt;p&gt;Here is a sample response message.&lt;/p&gt;
&lt;p&gt;{&lt;br&gt;
&lt;strong&gt;“registration_access_token&lt;/strong&gt;”: “&lt;strong&gt;reg-23410913-abewfq.123483&lt;/strong&gt;”,&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;“registration_client_uri&lt;/strong&gt;”:&lt;br&gt;
&lt;strong&gt;“&lt;a href=&quot;https://server.example.com/register/s6BhdRkqt3&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://server.example.com/register/s6BhdRkqt3&lt;/a&gt;&lt;/strong&gt;”,&lt;/p&gt;
&lt;p&gt;“client_id”: “s6BhdRkqt3”,&lt;/p&gt;
&lt;p&gt;“client_secret”: “cf136dc3c1fc93f31185e5885805d”,&lt;/p&gt;
&lt;p&gt;“client_id_issued_at”: 2893256800,&lt;/p&gt;
&lt;p&gt;“client_secret_expires_at”: 2893276800,&lt;/p&gt;
&lt;p&gt;“client_name”: “My Example Client”,&lt;/p&gt;
&lt;p&gt;“redirect_uris”: [&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light nord&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#d8dee9ff;--shiki-light-bg:#fff;--shiki-dark-bg:#2e3440ff; overflow-x: auto; white-space: pre-wrap; word-wrap: break-word;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;        “https://client.example.org/callback&quot;\],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;        “grant\_types”: \[“authorization\_code”, “refresh\_token”\],&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;“token_endpoint_auth_method”: “client_secret_basic”&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;2. ) An OAuth2 client can make an HTTP GET request to the Configuration EP of the AS with the client_id to receive registered client data from the AS as a JSON document.&lt;/p&gt;
&lt;p&gt;3.) An OAuth2 client can make an HTTP PUT request to the Configuration EP of the AS with the client_id and up-to-date client details. The AS should update the client registration data and replay the client with the client’s updated data. This response also takes JSON format.&lt;/p&gt;
&lt;p&gt;4.) An OAuth2 client can make an HTTP DELETE request to the Configuration EP of the AS with the client_id to delete the client data kept in the AS. After removing the client data, the AS should reply with HTTP 204 status code.&lt;/p&gt;
&lt;p&gt;As we have covered many theoretical details about these protocols, let’s try to discuss some practical examples using two DCR and DCR-M implementations.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;DCR and DCR-M on WSO2 IS&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*pbMEkihFHiER-zmz&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;First, let’s run an instance of the WSO2 Identity Server (IS).&lt;/p&gt;
&lt;p&gt;docker run — rm -it -p 9443:9443 — name is wso2/wso2is:5.10.0&lt;/p&gt;
&lt;p&gt;You can reach the registration endpoint of the WSO2 IS via the following URL. Also, note that WSO2 IS expects a prior registered user account for authentication of these requests by default. For simplicity, we use the admin: admin account for this demonstration.&lt;/p&gt;
&lt;div&gt;&lt;/div&gt;
&lt;p&gt;Now, let’s see how we could register, read, update and delete an OAuth2 client application dynamically.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;) Client registration&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;You can register a client with the following cURL command.&lt;/p&gt;
&lt;p&gt;curl -k — location — request POST ‘&lt;strong&gt;&lt;a href=&quot;https://localhost:9443/api/identity/oauth2/dcr/v1.1/register&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://localhost:9443/api/identity/oauth2/dcr/v1.1/register&lt;/a&gt;&lt;/strong&gt;’ \&lt;br&gt;
— header ‘Content-Type: application/json’ \&lt;br&gt;
— &lt;strong&gt;user ‘admin:admin’&lt;/strong&gt; \&lt;br&gt;
— data-raw ‘{ &lt;strong&gt;“client_name&lt;/strong&gt;”: “simple-application”, &lt;strong&gt;“redirect_uris&lt;/strong&gt;”: [“server.example.com/callback”], &lt;strong&gt;“grant_types&lt;/strong&gt;”: [“authorization_code”]}’&lt;/p&gt;
&lt;p&gt;Here is the expected response message; you can use the server-generated &lt;strong&gt;client_id&lt;/strong&gt; and &lt;strong&gt;client_secret&lt;/strong&gt; in the response message.&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;“client_id&lt;/strong&gt;”: “Ak32fw4v16Uv_5FNfv9fg2n7Ei8a”,&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;“client_secret&lt;/strong&gt;”: “MTZrCpVvaP_VpjZE6uFYQuxXH88a”,&lt;/p&gt;
&lt;p&gt;“client_secret_expires_at”: null,&lt;/p&gt;
&lt;p&gt;“redirect_uris”: [“server.example.com/callback”],&lt;/p&gt;
&lt;p&gt;“client_name”: “simple-application”&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;Alternatively, you can provide your own client_id and client_secret with the request message. In that case, WSO2 IS uses &lt;strong&gt;ext_param_client_id&lt;/strong&gt; and &lt;strong&gt;ext_param_client_secret&lt;/strong&gt; extension parameters with the request message. You can use the following cURL command.&lt;/p&gt;
&lt;p&gt;curl -k — location — request POST ‘&lt;strong&gt;&lt;a href=&quot;https://localhost:9443/api/identity/oauth2/dcr/v1.1/register&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://localhost:9443/api/identity/oauth2/dcr/v1.1/register&lt;/a&gt;&lt;/strong&gt;’ \&lt;br&gt;
— header ‘Content-Type: application/json’ \&lt;br&gt;
— &lt;strong&gt;user ‘admin:admin’&lt;/strong&gt; \&lt;br&gt;
— data-raw ‘{“client_name”: “provided-application”, “grant_types”: [“authorization_code”], “redirect_uris”: [“server.example.com/callback”], “&lt;strong&gt;ext_param_client_id&lt;/strong&gt;”:”provided_client_id0001”, “&lt;strong&gt;ext_param_client_secret&lt;/strong&gt;”:”provided_client_secret0001”}&lt;/p&gt;
&lt;p&gt;2.) &lt;strong&gt;Read&lt;/strong&gt; &lt;strong&gt;Client configuration&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;You can use one of the two following cURL commands to read client configuration data with the &lt;strong&gt;client_id&lt;/strong&gt; as a URL parameter or &lt;strong&gt;client_name&lt;/strong&gt; as a query string.&lt;/p&gt;
&lt;p&gt;curl -k — location &lt;strong&gt;— user ‘admin:admin’&lt;/strong&gt; — request GET ‘&lt;a href=&quot;https://localhost:9443/api/identity/oauth2/dcr/v1.1/register/**Ak32fw4v16Uv%5C_5FNfv9fg2n7Ei8a&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://localhost:9443/api/identity/oauth2/dcr/v1.1/register/**Ak32fw4v16Uv\_5FNfv9fg2n7Ei8a&lt;/a&gt;**’&lt;/p&gt;
&lt;p&gt;curl -k — location &lt;strong&gt;— user ‘admin:admin’&lt;/strong&gt; — request GET ‘&lt;a href=&quot;https://localhost:9443/api/identity/oauth2/dcr/v1.1/**register?client%5C_name=simple-application&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://localhost:9443/api/identity/oauth2/dcr/v1.1/**register?client\_name=simple-application&lt;/a&gt;**’&lt;/p&gt;
&lt;p&gt;Here is the expected response message for the above calls.&lt;/p&gt;
&lt;p&gt;{&lt;br&gt;
“client_id”: “Ak32fw4v16Uv_5FNfv9fg2n7Ei8a”,&lt;br&gt;
“client_secret”: “MTZrCpVvaP_VpjZE6uFYQuxXH88a”,&lt;br&gt;
“client_secret_expires_at”: null,&lt;br&gt;
“redirect_uris”: [ “server.example.com/callback”],&lt;br&gt;
“client_name”: “simple-application&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;3.) Update the client configuration&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;You can use the following cURL command to update the client configuration with the &lt;strong&gt;client_id&lt;/strong&gt; as a URL parameter.&lt;/p&gt;
&lt;p&gt;curl -k — location &lt;strong&gt;— request PUT&lt;/strong&gt; ‘&lt;a href=&quot;https://localhost:9443/api/identity/oauth2/dcr/v1.1/register/**Ak32fw4v16Uv%5C_5FNfv9fg2n7Ei8a&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://localhost:9443/api/identity/oauth2/dcr/v1.1/register/**Ak32fw4v16Uv\_5FNfv9fg2n7Ei8a&lt;/a&gt;**’ \&lt;br&gt;
— header ‘Content-Type: application/json’ \&lt;br&gt;
&lt;strong&gt;— user ‘admin:admin’&lt;/strong&gt; \&lt;br&gt;
— data-raw ‘{ “client_name”: “simple-application”, “redirect_uris”: [“server.example.com/callback”], “grant_types”: [“authorization_code”, &lt;strong&gt;“password”&lt;/strong&gt;]}’&lt;/p&gt;
&lt;p&gt;Here is the expected response message.&lt;/p&gt;
&lt;p&gt;{&lt;br&gt;
“client_id”: “Ak32fw4v16Uv_5FNfv9fg2n7Ei8a”,&lt;br&gt;
“client_secret”: “MTZrCpVvaP_VpjZE6uFYQuxXH88a”,&lt;br&gt;
“client_secret_expires_at”: null,&lt;br&gt;
“redirect_uris”: [ “server.example.com/callback”]&lt;br&gt;
“client_name”: “simple-application”&lt;br&gt;
}&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;4.) Delete the client configuration&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Here is the cURL command to delete the client configuration with the &lt;strong&gt;client_id&lt;/strong&gt; as a URL parameter. If it worked, it should return an HTTP 204 status code.&lt;/p&gt;
&lt;p&gt;curl -k — location &lt;strong&gt;— user ‘admin:admin’ — request DELETE&lt;/strong&gt; ‘&lt;a href=&quot;https://localhost:9443/api/identity/oauth2/dcr/v1.1/register/**Ak32fw4v16Uv%5C_5FNfv9fg2n7Ei8a&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://localhost:9443/api/identity/oauth2/dcr/v1.1/register/**Ak32fw4v16Uv\_5FNfv9fg2n7Ei8a&lt;/a&gt;**’&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;DCR and DCR-M on Okta&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*UFLGqs_ChNJb9rWd&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Okta is an Identity as a Service provider, and you need to be signed up for a developer account and should have the following details to proceed with the next steps.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;— Your Okta organization domain.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;— API token&lt;/em&gt;.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;) Client registration&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;You can register a client with the following cURL command.&lt;/p&gt;
&lt;p&gt;curl -v -X &lt;strong&gt;POST&lt;/strong&gt; \&lt;br&gt;
-H “Accept: application/json” \&lt;/p&gt;
&lt;p&gt;-H “Content-Type: application/json” \&lt;/p&gt;
&lt;p&gt;-H “&lt;strong&gt;Authorization: SSWS ${api_token}&lt;/strong&gt;” \&lt;/p&gt;
&lt;p&gt;-d ‘{&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;“client_name&lt;/strong&gt;”: “simple-application”,&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;“redirect_uris&lt;/strong&gt;”: [&lt;/p&gt;
&lt;p&gt;“&lt;a href=&quot;https://server.example.com/callback&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://server.example.com/callback&lt;/a&gt;”&lt;/p&gt;
&lt;p&gt;],&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;“response_types&lt;/strong&gt;”: [&lt;/p&gt;
&lt;p&gt;“code”&lt;/p&gt;
&lt;p&gt;],&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;“grant_types&lt;/strong&gt;”: [&lt;/p&gt;
&lt;p&gt;“authorization_code”,&lt;/p&gt;
&lt;p&gt;“refresh_token”&lt;/p&gt;
&lt;p&gt;]&lt;/p&gt;
&lt;p&gt;}’ “&lt;strong&gt;https://${yourOktaDomain}/oauth2/v1/clients&lt;/strong&gt;”&lt;/p&gt;
&lt;p&gt;Here is the expected response message; you can use the server-generated &lt;strong&gt;client_id&lt;/strong&gt; and &lt;strong&gt;client_secret&lt;/strong&gt; in the response message.&lt;/p&gt;
&lt;p&gt;{&lt;br&gt;
&lt;strong&gt;“client_secret&lt;/strong&gt;” : “5gdsgdfhdfhmaBbgdgsdgsdgsdg”,&lt;/p&gt;
&lt;p&gt;“client_id_issued_at” : 1585695068,&lt;/p&gt;
&lt;p&gt;“redirect_uris” : [&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light nord&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#d8dee9ff;--shiki-light-bg:#fff;--shiki-dark-bg:#2e3440ff; overflow-x: auto; white-space: pre-wrap; word-wrap: break-word;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt; “https://server.example.com/callback&quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;],&lt;/p&gt;
&lt;p&gt;“grant_types” : [&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light nord&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#d8dee9ff;--shiki-light-bg:#fff;--shiki-dark-bg:#2e3440ff; overflow-x: auto; white-space: pre-wrap; word-wrap: break-word;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    “authorization\_code”,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;    “refresh\_token”&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;],&lt;/p&gt;
&lt;p&gt;“client_secret_expires_at” : 0,&lt;/p&gt;
&lt;p&gt;“logo_uri” : null,&lt;/p&gt;
&lt;p&gt;“application_type” : “web”,&lt;/p&gt;
&lt;p&gt;“client_name” : “simple-application”,&lt;/p&gt;
&lt;p&gt;“client_uri” : null,&lt;/p&gt;
&lt;p&gt;“token_endpoint_auth_method” : “client_secret_basic”,&lt;/p&gt;
&lt;p&gt;“response_types” : [&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light nord&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#d8dee9ff;--shiki-light-bg:#fff;--shiki-dark-bg:#2e3440ff; overflow-x: auto; white-space: pre-wrap; word-wrap: break-word;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;      “code”&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;],&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;“client_id&lt;/strong&gt;” : “&lt;strong&gt;0oagdggh5l8i8b2bJ2wnfd&lt;/strong&gt;”&lt;/p&gt;
&lt;p&gt;}}&lt;/p&gt;
&lt;p&gt;2.) &lt;strong&gt;Read&lt;/strong&gt; &lt;strong&gt;Client configuration&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;You can use one of the two following cURL commands to read client configuration data with the &lt;strong&gt;client_id&lt;/strong&gt; as a URL parameter or &lt;strong&gt;client_name&lt;/strong&gt; as a query string.&lt;/p&gt;
&lt;p&gt;curl -v &lt;strong&gt;-X GET&lt;/strong&gt; \&lt;br&gt;
-H “Accept: application/json” \&lt;br&gt;
-H “Content-Type: application/json” \&lt;br&gt;
&lt;strong&gt;-H “Authorization: SSWS ${api_token}”&lt;/strong&gt; “https://${yourOktaDomain}/oauth2/v1/clients/&lt;strong&gt;0oagdggh5l8i8b2bJ2wnfd&lt;/strong&gt;”&lt;/p&gt;
&lt;p&gt;Here is the expected response message for the above call.&lt;/p&gt;
&lt;p&gt;{&lt;br&gt;
“grant_types” : [&lt;br&gt;
“authorization_code”,&lt;br&gt;
“refresh_token”&lt;br&gt;
],&lt;br&gt;
“client_id” : “0oagdggh5l8i8b2bJ2wnfd”,&lt;br&gt;
“application_type” : “web”,&lt;br&gt;
“logo_uri” : null,&lt;br&gt;
“client_id_issued_at” : 1585695068,&lt;br&gt;
“client_secret_expires_at” : 0,&lt;br&gt;
“redirect_uris” : [&lt;br&gt;
“&lt;a href=&quot;https://server.example.com/callback&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://server.example.com/callback&lt;/a&gt;”&lt;br&gt;
],&lt;br&gt;
“response_types” : [&lt;br&gt;
“code”&lt;br&gt;
],&lt;br&gt;
“token_endpoint_auth_method” : “client_secret_basic”,&lt;br&gt;
“client_name” : “simple-application”,&lt;br&gt;
“client_uri” : null&lt;br&gt;
}&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;3.) Update the client configuration&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;You can use the following cURL command to update the client configuration with the &lt;strong&gt;client_id&lt;/strong&gt; as a URL parameter.&lt;/p&gt;
&lt;p&gt;curl -v -X PUT \&lt;br&gt;
-H “Accept: application/json” \&lt;br&gt;
-H “Content-Type: application/json” \&lt;br&gt;
-H “Authorization: SSWS &lt;strong&gt;${api_token}&lt;/strong&gt;” \&lt;br&gt;
-d ‘{ “grant_types” : [ “authorization_code”, “refresh_token”, “password” ], “client_id” : “0oa55l8i8b2bJ2wnP4x6”, “application_type” : “web”, “logo_uri” : null, “client_id_issued_at” : 1585695068, “client_secret_expires_at” : 0, “redirect_uris” : [ “&lt;a href=&quot;https://server.example.com/callback%22%5C&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://server.example.com/callback”\&lt;/a&gt;], “response_types” : [ “code”], “token_endpoint_auth_method” : “client_secret_basic”, “client_name” : “simple-application”, “client_uri” : null }’ “https://${yourOktaDomain}/oauth2/v1/clients/&lt;strong&gt;0oagdggh5l8i8b2bJ2wnfd&lt;/strong&gt;”&lt;/p&gt;
&lt;p&gt;Here is the expected response message.&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;“client_uri” : null,&lt;/p&gt;
&lt;p&gt;“logo_uri” : null,&lt;/p&gt;
&lt;p&gt;“response_types” : [&lt;/p&gt;
&lt;p&gt;“code”&lt;/p&gt;
&lt;p&gt;],&lt;/p&gt;
&lt;p&gt;“redirect_uris” : [&lt;/p&gt;
&lt;p&gt;“&lt;a href=&quot;https://server.example.com/callback&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://server.example.com/callback&lt;/a&gt;”&lt;/p&gt;
&lt;p&gt;],&lt;/p&gt;
&lt;p&gt;“client_name” : “simple-application”,&lt;/p&gt;
&lt;p&gt;“client_secret_expires_at” : 0,&lt;/p&gt;
&lt;p&gt;“client_secret” : “5gdsgdfhdfhmaBbgdgsdgsdgsdg”,&lt;/p&gt;
&lt;p&gt;“client_id” : “&lt;strong&gt;0oagdggh5l8i8b2bJ2wnfd&lt;/strong&gt;”,&lt;/p&gt;
&lt;p&gt;“token_endpoint_auth_method” : “client_secret_basic”,&lt;/p&gt;
&lt;p&gt;“client_id_issued_at” : 1585695068,&lt;/p&gt;
&lt;p&gt;“application_type” : “web”,&lt;/p&gt;
&lt;p&gt;“grant_types” : [&lt;/p&gt;
&lt;p&gt;“authorization_code”,&lt;/p&gt;
&lt;p&gt;“refresh_token”,&lt;/p&gt;
&lt;p&gt;“password”&lt;/p&gt;
&lt;p&gt;]&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;4.) Delete the client configuration&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Here is the cURL command to delete the client configuration with the &lt;strong&gt;client_id&lt;/strong&gt; as a URL parameter. If it worked it should return an HTTP 204 status code.&lt;/p&gt;
&lt;p&gt;curl -v -X DELETE \&lt;br&gt;
-H “Accept: application/json” \&lt;br&gt;
-H “Content-Type: application/json” \&lt;br&gt;
&lt;strong&gt;-H “Authorization: SSWS ${api_token}”&lt;/strong&gt; \&lt;br&gt;
“https://${yourOktaDomain}/oauth2/v1/clients/&lt;strong&gt;0oagdggh5l8i8b2bJ2wnfd&lt;/strong&gt;”&lt;/p&gt;
&lt;p&gt;As a part of my OAuth2 blog series, In this post, I’ve discussed client registration and management patterns and how they can be implemented using two popular Identity solutions. I hope this was useful, and stay tuned for the next post of this series.&lt;/p&gt;
&lt;p&gt;Here are the previous posts of this series.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Part 1 — &lt;a href=&quot;https://sagarag.dev/posts/understanding-oauth2-landscape&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Understanding OAuth2 Landscape&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Part 2 — &lt;a href=&quot;https://sagarag.dev/posts/how-do-you-discover-the-oauth2-server-configuration&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;How do you discover the OAuth2 server configuration?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content:encoded><dc:creator>Sagara Gunathunga</dc:creator><category>OAuth 2.0</category></item><item><title>OAuth 2.0 Server Discovery with .well-known Metadata</title><link>https://sagarag.dev/posts/how-do-you-discover-the-oauth2-server-configuration</link><guid isPermaLink="true">https://sagarag.dev/posts/how-do-you-discover-the-oauth2-server-configuration</guid><description>How OAuth 2.0 clients discover endpoints using Authorization Server Metadata (RFC 8414) and OpenID Connect Discovery, with real .well-known examples.</description><pubDate>Fri, 24 Apr 2020 21:52:37 GMT</pubDate><content:encoded>&lt;p&gt;This article is the second post in my blog series about the OAuth2; reading the &lt;a href=&quot;https://sagarag.dev/posts/understanding-oauth2-landscape&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;first post&lt;/a&gt; may help you to understand this current topic easily.&lt;/p&gt;
&lt;p&gt;Although I intended to provide an overview above the OAuth2 and related specifications, I have extensively discussed the &lt;strong&gt;Authorization Code&lt;/strong&gt; grant type in the &lt;a href=&quot;https://sagarag.dev/posts/understanding-oauth2-landscape&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;previous post&lt;/a&gt;. The &lt;strong&gt;Authorization Code&lt;/strong&gt; grant type consists of two distinct steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The application (OAuth2 client ) redirects the end-user who is accessing the application into the &lt;strong&gt;Authorization Endpoint&lt;/strong&gt; of the Authorization Server (AS) with an authorization request to obtain an authorization grant (a.k.a ‘code’).&lt;/li&gt;
&lt;li&gt;Once the authorization grant (a.k.a ‘code’) is received by the application (OAuth2 client ), it makes a direct HTTP POST request to the &lt;strong&gt;Token Endpoint&lt;/strong&gt; of the Authorization Server (AS) with a token request to obtain an access token.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*cnW6COQy5qxC_FCHELAISQ.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Although we haven’t explicitly discussed, in both cases, we assumed that the locations of &lt;strong&gt;Authorization Endpoint&lt;/strong&gt; and &lt;strong&gt;Token Endpoint&lt;/strong&gt; of the Authorization Server (AS) are known to the application (OAuth2 client); Yet, how does this work in the real world?&lt;/p&gt;
&lt;p&gt;The application should also know about the other configuration details about the Authorization Server (AS), such as supported grant types, supported scopes, etc. Note that these configuration data are also called as the metadata.&lt;/p&gt;
&lt;p&gt;In this post, I’m trying to answer the above questions; basically, there are two approaches available:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Use out-of-band channels to communicate the above configuration details.&lt;/li&gt;
&lt;li&gt;Use OAuth 2.0 Authorization Server Metadata specification.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;server-metadata-via-out-of-band-channels&quot;&gt;Server Metadata via Out-of-band channels&lt;/h3&gt;
&lt;p&gt;In this approach, there is no standard methodology to define and communicate the AS configuration metadata. It’s up to the AS and the application to agree on an approach to communicate this data. Following are some of the possible methods:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The AS maintains a human-readable page with the configuration metadata.&lt;/li&gt;
&lt;li&gt;Application developers can log in to a portal maintained by the AS to figure out the configuration metadata.&lt;/li&gt;
&lt;li&gt;The AS uses e-mail/text to communicate the configuration metadata to the application developers.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*BMATRIHjrUfPfdUsf5wI4A.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Although this is not a standard, it is still a pretty popular option due to the simplicity. The main drawback of this approach is that the configuration data are static or hard-coded within the application. The client can’t discover and establish the communication according to that dynamically. For example, once the Authorization Endpoint and Token Endpoint locations have been changed, the application must reconfigure to call new locations.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*12pzi48GhTH9euzyP28JGw.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;oauth-20-authorization-servermetadata&quot;&gt;OAuth 2.0 Authorization Server Metadata&lt;/h3&gt;
&lt;p&gt;In contrast to the above approach, the OAuth 2.0 Authorization Server Metadata specification defines an automated approach for the applications to discover the AS’s configuration metadata. For instance, the application can automatically retrieve confirmation metadata as a machine-readable document frequently and change the Authorization Endpoint and Token Endpoint location dynamically.&lt;/p&gt;
&lt;p&gt;There is a strong overlap between OAuth 2.0 Authorization Server Metadata and OpenID Connect Discovery specification. OpenID Connect Discovery specification was developed first. Then, the OAuth2 working group generalised the OpenID Connect Discovery specification to support use cases other than the OpenID Connect protocol. Due to this reason, you can find a great level of overlap with the JSON structures used to define server metadata and semantics of metadata request and response flows.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*gyyG3rp5j6gaZyfRylZEPQ.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;In addition to the server metadata structure and request-response semantics, OpenID Connect Discovery specification defines a discovery mechanism so that the client application can discover the AS based on an identifier provided by the end-user. Once the discovery process has taken place, the client application can send a metadata request to the discovered AS to figure out server metadata. However, in contrast to the OpenID Connect Discovery specification, the OAuth 2.0 Authorization Server Metadata specification does not define any particular discovery mechanism. It defines server metadata structure and request-response semantics only, which is significantly different between these two specifications. Note that most of the post examples are based on OpenID Connect Discovery specification that covers both of the specifications.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*9hdSJrZQFl_6Bxr6ZFsOVA.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;This specification defines several aspects related to the AS configuration, its capabilities and endpoint locations as follows.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Server metadata format that covers endpoint locations, server capabilities and configuration. This metadata configuration document can be a plain JSON document exposed over HTTPS or JWT document signed by the AS.&lt;/li&gt;
&lt;li&gt;The metadata endpoint to query the server as mentioned above for configuration data.&lt;/li&gt;
&lt;li&gt;Metadata request and response semantics.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The best way to understand the metadata format is to look at a real-world example; here, let’s look at a part of the metadata from the Google authorization service.&lt;/p&gt;
&lt;p&gt;{&lt;br&gt;
“&lt;strong&gt;issuer&lt;/strong&gt;”: “&lt;a href=&quot;https://accounts.google.com&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://accounts.google.com&lt;/a&gt;”,&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;authorization_endpoint&lt;/strong&gt;”:&lt;br&gt;
“&lt;a href=&quot;https://accounts.google.com/o/oauth2/v2/auth&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://accounts.google.com/o/oauth2/v2/auth&lt;/a&gt;”,&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;token_endpoint&lt;/strong&gt;”: “&lt;a href=&quot;https://oauth2.googleapis.com/token&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://oauth2.googleapis.com/token&lt;/a&gt;”,&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;revocation_endpoint&lt;/strong&gt;”: “&lt;a href=&quot;https://oauth2.googleapis.com/revoke&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://oauth2.googleapis.com/revoke&lt;/a&gt;”,&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;response_types_supported&lt;/strong&gt;”: [&lt;br&gt;
“code”,&lt;br&gt;
“token”,&lt;br&gt;
“none”&lt;br&gt;
],&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;scopes_supported&lt;/strong&gt;”: [&lt;br&gt;
“openid”,&lt;br&gt;
“email”,&lt;br&gt;
“profile”&lt;br&gt;
],&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;token_endpoint_auth_methods_supported&lt;/strong&gt;”: [&lt;br&gt;
“client_secret_post”,&lt;br&gt;
“client_secret_basic”&lt;br&gt;
],&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;grant_types_supported&lt;/strong&gt;”: [&lt;br&gt;
“authorization_code”,&lt;br&gt;
“refresh_token”,&lt;br&gt;
“urn:ietf:params:oauth:grant-type:device_code”,&lt;br&gt;
“urn:ietf:params:oauth:grant-type:jwt-bearer”&lt;br&gt;
]&lt;br&gt;
}&lt;/p&gt;
&lt;p&gt;Let’s look at some of the values of the above metadata document.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Issuer&lt;/strong&gt; — This mandatory element is the issuer identifier of the AS and used to identify the AS uniquely. This takes the URL format and starts with HTTPS.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;example&lt;/em&gt;: &lt;a href=&quot;https://accounts.google.com&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://accounts.google.com&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;example&lt;/em&gt;: &lt;a href=&quot;https://sts.windows.net/%7Btenantid%7D/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://sts.windows.net/{tenantid}&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;authorization_endpoint&lt;/strong&gt; — The location of the OAuth2 authorization endpoint.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;token_endpoint&lt;/strong&gt; — The location of the OAuth2 token endpoint.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;revocation_endpoint&lt;/strong&gt; — The location of the OAuth2 revocation endpoint.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;grant_types_supported&lt;/strong&gt; — List of supported grant types.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;token_endpoint_auth_methods_supported&lt;/strong&gt; — List of supported client authentication mechanisms.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;scopes_supported&lt;/strong&gt; — List of supported grant types.&lt;/p&gt;
&lt;p&gt;You can find the complete list of supported values from &lt;a href=&quot;https://tools.ietf.org/html/rfc8414#section-2&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;. In addition to that, the specification allows properly defining custom values. For instance, there are OpenID Connect specific additional values defined in the OpenID Connect Discovery specification.&lt;/p&gt;
&lt;p&gt;This is another example from Microsoft Azure. In this example document, you can find some OpenID Connect metadata and Microsoft specific metadata in addition to OAuth2 metadata elements.&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;issuer&lt;/strong&gt;”: “&lt;a href=&quot;https://sts.windows.net/%7Btenantid%7D/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://sts.windows.net/{tenantid}/&lt;/a&gt;”,&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;token_endpoint&lt;/strong&gt;”: “&lt;a href=&quot;https://login.windows.net/common/oauth2/token&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://login.windows.net/common/oauth2/token&lt;/a&gt;”,&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;token_endpoint_auth_methods_supported&lt;/strong&gt;”: [&lt;br&gt;
“client_secret_post”,&lt;br&gt;
“private_key_jwt”,&lt;br&gt;
“client_secret_basic”&lt;br&gt;
],&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;jwks_uri&lt;/strong&gt;”: “&lt;a href=&quot;https://login.windows.net/common/discovery/keys&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://login.windows.net/common/discovery/keys&lt;/a&gt;”,&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;response_types_supported&lt;/strong&gt;”: [&lt;br&gt;
“code”,&lt;br&gt;
“id_token”,&lt;br&gt;
“code id_token”,&lt;br&gt;
“token id_token”,&lt;br&gt;
“token”&lt;br&gt;
],&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;scopes_supported&lt;/strong&gt;”: [&lt;br&gt;
“openid”&lt;br&gt;
],&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;microsoft_multi_refresh_token&lt;/strong&gt;”: true,&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;authorization_endpoint&lt;/strong&gt;”:&lt;br&gt;
“&lt;a href=&quot;https://login.windows.net/common/oauth2/authorize&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://login.windows.net/common/oauth2/authorize&lt;/a&gt;”,&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;http_logout_supported&lt;/strong&gt;”: true,&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;frontchannel_logout_supported&lt;/strong&gt;”: true,&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;end_session_endpoint&lt;/strong&gt;”:&lt;br&gt;
“&lt;a href=&quot;https://login.windows.net/common/oauth2/logout&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://login.windows.net/common/oauth2/logout&lt;/a&gt;”&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;check_session_iframe&lt;/strong&gt;”:&lt;br&gt;
“&lt;a href=&quot;https://login.windows.net/common/oauth2/checksession&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://login.windows.net/common/oauth2/checksession&lt;/a&gt;”,&lt;br&gt;
}&lt;/p&gt;
&lt;p&gt;As mentioned previously, the above metadata document can be communicated using one of the following two approaches.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;A plain JSON document over a HTTPS channel —&lt;/strong&gt; This is the most common approach due to its simplicity. For instance, as per the above examples, Microsoft Azure and Google use this approach to define the AS metadata.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A signed JWT document&lt;/strong&gt; — A set of metadata claims can be bundled as a JWT and signed using JWS. This singed JWT is placed within the plain JSON document as the value of signed_metadata element. The main advantage of this approach is that the receiving party can validate the issuer via signature verification.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;metadata-request--responseflow&quot;&gt;Metadata request &amp;#x26; response flow&lt;/h3&gt;
&lt;p&gt;This flow initiates when a client makes a metadata request call to the &lt;strong&gt;metadata endpoint&lt;/strong&gt; of the AS. To make this possible, the client should know the location of the metadata endpoint of the AS. The OAuth 2.0 Authorization Server Metadata specification defines the following URL format based on IETF &lt;a href=&quot;https://tools.ietf.org/html/rfc8615&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Defining Well-Known Uniform Resource Identifiers&lt;/a&gt; specification; however, it does not specify any discovery mechanism for clients to discover this metadata endpoint location. The ASs can use out-of-band mechanisms such as web page, portal, email to communicate this location or use &lt;a href=&quot;https://openid.net/specs/openid-connect-discovery-1_0.html#IssuerDiscovery&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;the server discovery mechanism&lt;/a&gt; defined in the OpenID Connect Discovery specification, based on &lt;a href=&quot;https://webfinger.net/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;WebFinger&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Metadata endpoint location&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;According to the specification, the metadata endpoint URL takes the following format, which includes &lt;strong&gt;.well-known&lt;/strong&gt; literal value.&lt;/p&gt;
&lt;p&gt;/&lt;strong&gt;.well-known&lt;/strong&gt;/oauth-authorization-server&lt;/p&gt;
&lt;p&gt;Examples:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://accounts.google.com/.well-known/openid-configuration&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://accounts.google.com/&lt;strong&gt;.well-known&lt;/strong&gt;/openid-configuration&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://login.windows.net/common/.well-known/openid-configuration&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://login.windows.net/common/&lt;strong&gt;.well-known&lt;/strong&gt;/openid-configuration&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*tPB2YeILzQpbvcP3y5WA7Q.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step1&lt;/strong&gt; — The client makes a HTTP GET to the known metadata endpoint of the AS.&lt;/p&gt;
&lt;p&gt;Examples:&lt;/p&gt;
&lt;p&gt;curl &lt;a href=&quot;https://accounts.google.com/.well-known/openid-configuration&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://accounts.google.com/.well-known/openid-configuration&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt; — The AS returns a JSON response with the metadata elements that we have discussed in the previous section.&lt;/p&gt;
&lt;p&gt;Examples:&lt;/p&gt;
&lt;p&gt;curl &lt;a href=&quot;https://accounts.google.com/.well-known/openid-configuration&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://accounts.google.com/.well-known/openid-configuration&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;{&lt;br&gt;
“issuer”: “&lt;a href=&quot;https://accounts.google.com&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://accounts.google.com&lt;/a&gt;”,&lt;br&gt;
“authorization_endpoint”: “&lt;a href=&quot;https://accounts.google.com/o/oauth2/v2/auth&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://accounts.google.com/o/oauth2/v2/auth&lt;/a&gt;”,&lt;br&gt;
“device_authorization_endpoint”: “&lt;a href=&quot;https://oauth2.googleapis.com/device/code&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://oauth2.googleapis.com/device/code&lt;/a&gt;”,&lt;br&gt;
“token_endpoint”: “&lt;a href=&quot;https://oauth2.googleapis.com/token&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://oauth2.googleapis.com/token&lt;/a&gt;”,&lt;/p&gt;
&lt;p&gt;…&lt;/p&gt;
&lt;p&gt;…&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;We have already discussed a few publically available OAuth2 services; now, let’s look at some popular open-source OAuth2 implementations and their OAuth2 metadata configurations.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Keycloak OAuth2 implementation&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*XxlM6zQE7W6tHB5y.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;You can start Keycloak server instance by running the following Docker run command.&lt;/p&gt;
&lt;p&gt;docker run -p 8080:8080 -p 9990:9990 -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin quay.io/keycloak/keycloak:9.0.0&lt;/p&gt;
&lt;p&gt;Once the Keycloak server started, you can access its OAuth2/OpenID Connect metadata using the following URL.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://127.0.0.1:8080/auth/realms/master/.well-known/openid-configuration&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;http://127.0.0.1:8080/auth/realms/master/.well-known/openid-configuration&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Example :&lt;/p&gt;
&lt;p&gt;curl -k &lt;a href=&quot;http://127.0.0.1:8080/auth/realms/master/.well-known/openid-configuration&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;http://127.0.0.1:8080/auth/realms/master/.well-known/openid-configuration&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;{&lt;br&gt;
“&lt;strong&gt;issuer&lt;/strong&gt;”: “&lt;a href=&quot;http://127.0.0.1:8080/auth/realms/master&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;http://127.0.0.1:8080/auth/realms/master&lt;/a&gt;”,&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;authorization_endpoint&lt;/strong&gt;”: “&lt;a href=&quot;http://127.0.0.1:8080/auth/realms/master/protocol/openid-connect/auth&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;http://127.0.0.1:8080/auth/realms/master/protocol/openid-connect/auth&lt;/a&gt;”,&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;token_endpoint&lt;/strong&gt;”: “&lt;a href=&quot;http://127.0.0.1:8080/auth/realms/master/protocol/openid-connect/token&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;http://127.0.0.1:8080/auth/realms/master/protocol/openid-connect/token&lt;/a&gt;”,&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;token_introspection_endpoint&lt;/strong&gt;”: “&lt;a href=&quot;http://127.0.0.1:8080/auth/realms/master/protocol/openid-connect/token/introspect&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;http://127.0.0.1:8080/auth/realms/master/protocol/openid-connect/token/introspect&lt;/a&gt;”,&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;userinfo_endpoint&lt;/strong&gt;”: “&lt;a href=&quot;http://127.0.0.1:8080/auth/realms/master/protocol/openid-connect/userinfo&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;http://127.0.0.1:8080/auth/realms/master/protocol/openid-connect/userinfo&lt;/a&gt;”,&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;end_session_endpoint&lt;/strong&gt;”: “&lt;a href=&quot;http://127.0.0.1:8080/auth/realms/master/protocol/openid-connect/logout&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;http://127.0.0.1:8080/auth/realms/master/protocol/openid-connect/logout&lt;/a&gt;”,&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;jwks_uri&lt;/strong&gt;”: “&lt;a href=&quot;http://127.0.0.1:8080/auth/realms/master/protocol/openid-connect/certs&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;http://127.0.0.1:8080/auth/realms/master/protocol/openid-connect/certs&lt;/a&gt;”,&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;check_session_iframe&lt;/strong&gt;”: “&lt;a href=&quot;http://127.0.0.1:8080/auth/realms/master/protocol/openid-connect/login-status-iframe.html&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;http://127.0.0.1:8080/auth/realms/master/protocol/openid-connect/login-status-iframe.html&lt;/a&gt;”,&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;grant_types_supported&lt;/strong&gt;”: [&lt;br&gt;
“authorization_code”,&lt;br&gt;
“implicit”,&lt;br&gt;
“refresh_token”,&lt;br&gt;
“password”,&lt;br&gt;
“client_credentials”&lt;br&gt;
],&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;response_types_supported&lt;/strong&gt;”: [&lt;br&gt;
“code”,&lt;br&gt;
“none”,&lt;br&gt;
“id_token”,&lt;br&gt;
“token”,&lt;br&gt;
“id_token token”,&lt;br&gt;
“code id_token”,&lt;br&gt;
“code token”,&lt;br&gt;
“code id_token token”&lt;br&gt;
],&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;subject_types_supported&lt;/strong&gt;”: [&lt;br&gt;
“public”,&lt;br&gt;
“pairwise”&lt;br&gt;
],&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;id_token_signing_alg_values_supported&lt;/strong&gt;”: [&lt;br&gt;
“PS384”,&lt;br&gt;
“ES384”,&lt;br&gt;
“RS384”,&lt;br&gt;
],&lt;/p&gt;
&lt;p&gt;…&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;WSO2 Identity Server OAuth2 implementation&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*u_DyNSB6pntTFixQ_TkGew.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;You can start WSO2 Identity Server instance by running the following Docker command.&lt;/p&gt;
&lt;p&gt;docker run —rm -it -p 9443:9443 —name is wso2/wso2is:5.10.0&lt;/p&gt;
&lt;p&gt;Once the Keycloak server started, you can access its OAuth2/OpenID Connect metadata using the following URL.&lt;/p&gt;
&lt;div&gt;&lt;/div&gt;
&lt;p&gt;Example :&lt;/p&gt;
&lt;p&gt;curl -k &lt;a href=&quot;https://localhost:9443/oauth2/token/.well-known/openid-configuration&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://localhost:9443/oauth2/token/.well-known/openid-configuration&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;issuer&lt;/strong&gt;”: “&lt;a href=&quot;https://localhost:9443/oauth2/token&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://localhost:9443/oauth2/token&lt;/a&gt;”,&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;introspection_endpoint&lt;/strong&gt;”: “&lt;a href=&quot;https://localhost:9443/oauth2/introspect&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://localhost:9443/oauth2/introspect&lt;/a&gt;”,&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;Response_modes_supported&lt;/strong&gt;”: [&lt;br&gt;
“query”,&lt;br&gt;
“fragment”,&lt;br&gt;
“form_post”&lt;br&gt;
],&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;scopes_supported&lt;/strong&gt;”: [&lt;br&gt;
“openid”,&lt;br&gt;
“email”,&lt;br&gt;
“profile”,&lt;br&gt;
“phone”,&lt;br&gt;
“address”&lt;br&gt;
],&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;check_session_iframe&lt;/strong&gt;”: “&lt;a href=&quot;https://localhost:9443/oidc/checksession&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://localhost:9443/oidc/checksession&lt;/a&gt;”,&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;backchannel_logout_supported&lt;/strong&gt;”: true,&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;authorization_endpoint&lt;/strong&gt;”: “&lt;a href=&quot;https://localhost:9443/oauth2/authorize&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://localhost:9443/oauth2/authorize&lt;/a&gt;”,&lt;/p&gt;
&lt;p&gt;“&lt;strong&gt;grant_types_supported&lt;/strong&gt;”: [&lt;br&gt;
“refresh_token”,&lt;br&gt;
“urn:ietf:params:oauth:grant-type:saml2-bearer”,&lt;br&gt;
“password”,&lt;br&gt;
“client_credentials”,&lt;br&gt;
“iwa:ntlm”,&lt;br&gt;
“urn:ietf:params:oauth:grant-type:device_code”,&lt;br&gt;
“authorization_code”,&lt;br&gt;
“urn:ietf:params:oauth:grant-type:uma-ticket”,&lt;br&gt;
“account_switch”,&lt;br&gt;
“urn:ietf:params:oauth:grant-type:jwt-bearer”&lt;br&gt;
],&lt;/p&gt;
&lt;p&gt;…&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;There you have it! I have discussed OAuth 2.0 Authorization Server Metadata in detail and its relationship to the OpenID Connect Discovery specification in this post. If you’re enjoying what you’re reading now — just wait until you check out my next article! This is where I will be discussing the OAuth2 DCR and DCRM specifications; these also play an essential role in the OAuth2 eco-system.&lt;/p&gt;</content:encoded><dc:creator>Sagara Gunathunga</dc:creator><category>OAuth 2.0</category><category>OpenID Connect</category></item><item><title>OAuth 2.0 Explained: Roles, Grants, Tokens and Extensions</title><link>https://sagarag.dev/posts/understanding-oauth2-landscape</link><guid isPermaLink="true">https://sagarag.dev/posts/understanding-oauth2-landscape</guid><description>A complete map of OAuth 2.0: roles, grant types, why implicit and password grants are deprecated, token types, introspection, revocation, DCR, OIDC and UMA.</description><pubDate>Sun, 19 Apr 2020 05:57:31 GMT</pubDate><content:encoded>&lt;p&gt;Now it has been nearly 8 years after the formal approval of OAuth2 Core standard by IETF. Obviously, the OAuth2 is not a new technology for writing yet another introduction post, especially in 2020. So what has motivated me to write an introductory post about OAuth2 at this point? I believe it’s worth discussing that first.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Security technology is evolving relatively fast compared to other technology, this is true for the OAuth2 as well. Some of the content of the spec is no longer considered as best practice and discouraged to use as well. This has happened because some of the technological constraints existed in back then are no longer valid now. This is also due to the fact that the discovery of new vulnerabilities that affect some parts of the spec. So it’s worth to refine the way we use Oauth2 according to the current best practice.&lt;/li&gt;
&lt;li&gt;In the OAuth2 core spec, a relatively large number of elements that are required for practical implementations were intentionally left undefined. During the recent past, OAuth2 has evolved from a core spec to an eco-system with a number of supportive specs, and some of which are still under the development too. Therefore after 8 years, we are in a much better position to present a more complete and comprehensive picture about how to implement OAuth2 in terms of open standards.&lt;/li&gt;
&lt;li&gt;As we will discuss a little later with further details, the semantics of requesting an authorization token from an authorization server by a client is defined as ‘grant type’. There are a number of grant types that have been developed after the core spec; so again, it’s worth discussing them and provides a consolidated view on when and how to use them.&lt;/li&gt;
&lt;li&gt;As anticipated by the original authors, the OAuth2 core spec is being used as a foundation to derive some other technology: OpenID Connect (OIDC) authentication protocol and User-Manager Access (UMA2) access management protocol all are good examples. Thus it’s important to understand how these new technologies have been developed on top of OAuth2.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;access-delegation&quot;&gt;Access Delegation&lt;/h3&gt;
&lt;p&gt;The OAuth2 introduces itself as an authorisation framework. Although there is no issue with the term, I would much prefer to call the OAuth2 an ‘&lt;strong&gt;access delegation&lt;/strong&gt;’ framework. However, it seems there is considerable confusion about OAuth2 as an authentication technology; nevertheless, it’s a topic for another post.&lt;/p&gt;
&lt;p&gt;Before the OAuth2 era, when you created a Twitter account and Twitter wanted to send friend requests to your contact list stored in Gmail, it used to ask for your Gmail username and password promising you that they would “behave appropriately” with those credentials and wouldn’t misuse them.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*Q8aqaX_x9fndozmx9_yH-w.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;As you can easily understand, this is not acceptable in terms of security, and this problem has opened up the potential to invent a new technology that we call OAuth2 today. The Oauth2 facilitates to implement the above-discussed use case without sharing original credentials, instead of using a temporary token with a great level of control.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*yhhw8yW8ZZWM02DM_42_oQ.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;To give you a real-world example; this is bit smiler to the use of an access card system in a hotel rather than physical keys. The access card provides numerous benefits over traditional keys, some of them are listed below.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The access card itself doesn’t contain any useful information instead it’s just a reference issued by the security system and used by the security system to execute a set of pre-agreed actions; in this case, to open the door of a particular room only during a certain time period. However, once the card is presented to the security system, the system can easily identify details such as to whom the access card was issued, issued time and the authorized person who issued the card, validity period of the card, what rooms are allowed to be accessed etc.&lt;/li&gt;
&lt;li&gt;In a scenario where multiple access cards being used to access a particular room, the security system can track some audit logs such as who has accessed the room during a particular time.&lt;/li&gt;
&lt;li&gt;Unlike physical keys, if a stolen, access card possesses very low-security risk because security system can revoke a stolen access card with a single click.&lt;/li&gt;
&lt;li&gt;There is no requirement to collect the access card during the check-out time and there is no great risk of creating duplicate cards because if someone managed to create identical duplicate access card, it could be only used for a limited period.&lt;/li&gt;
&lt;li&gt;It’s easy to rotate the new card and easy to revoke access cards from a security systems level.&lt;/li&gt;
&lt;li&gt;If you present your access card to the door of another room, it wouldn’t work. In other words, this card knows its audience.&lt;/li&gt;
&lt;li&gt;However, the access card can’t verify whether the room is accessed by the original person who was issued an access card, it could be someone else who carries the access card.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;At this point, I want you to think the above hotel access card is identical to the temporary token used in OAuth2; and all of the above points are also applicable to OAuth2 token as well. I hope your next hotel visit will remind you about OAuth2.&lt;/p&gt;
&lt;h3 id=&quot;oauth2&quot;&gt;OAuth2&lt;/h3&gt;
&lt;p&gt;In the standard OAuth2 flow it constitutes 4 basic roles or actors know as the &lt;strong&gt;resource owner&lt;/strong&gt;, the &lt;strong&gt;resource server&lt;/strong&gt;, the &lt;strong&gt;authorisation server&lt;/strong&gt; and the &lt;strong&gt;client&lt;/strong&gt;. The following diagrams help you to understand the above roles/actors based on the real-world examples that have mentioned in the previous sections.&lt;/p&gt;
&lt;p&gt;OAuth2 roles based on hotel example&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*2GfmFJValqzS9ormYsxMUg.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;OAuth2 roles based on Twitter example.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*MGyUIwoHoN6zflQ3Y7SjHw.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The Resource Owner (RO):&lt;/strong&gt; The owner of the underline resource that the client wants to access. For example, this could be your photos stored in Flickr, a file stored in DropBox, Gmail contact list or your Facebook profile etc.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The Client:&lt;/strong&gt; This is the 3rd party application that wants to access the service. For instance, a photo printing application may want to access your photos hosted in Flickr. In that case, the photo printing application acts as the OAuth2 client.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The Resource Server (RS):&lt;/strong&gt; This is where the resource owners store their resources. For example Flickr, DropBox and Gmail services.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Authorization Server (AS):&lt;/strong&gt; This is the entity responsible for coordinating with the client and the resource owner, also provides temporary access tokens to the client. In most of the real-world cases, it’s hard to distinguish this entity from the resource server.&lt;/p&gt;
&lt;p&gt;As you have some level of understanding about the above actors, now let’s look at interactions among these actors. First, we will look at abstract OAuth2 flow, the abstract flow means you can’t find this flow in real-world instead this helps you to understand concrete OAuth flows easily like OSI abstract model in computer networking. The abstract OAuth2 flow consists of 3 mains steps as follows.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step-1&lt;/strong&gt; — The client should possess a special token known as an authorization grant, which is a credential representing the resource owner’s (RO) authorization for this particular client. In case the client does not possess a valid authorization grant, it should first request it from the AS. Usually, this happens by redirecting the resource owner (in fact resource owner’s user-agent) to the authorisation server (AS) so that the RO can authenticate with the AS and authorize the client. It’s also important to note that the authorization grant that we are discussing here is again an abstract notion, &lt;strong&gt;&lt;em&gt;grant type&lt;/em&gt;&lt;/strong&gt;&lt;em&gt;: another OAuth2 construct which we will look at little later defines the actual format and processing logic for authorization grant&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step-2&lt;/strong&gt; — The client authenticates with the AS and requests an access token by providing the above-discussed &lt;strong&gt;authorization grant&lt;/strong&gt;. The AS validates both the client and the received authorization grant then issues an access token to the client.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step-3&lt;/strong&gt; — The client access the resource on the Resource Server (RO) by producing the access token, this access token can be used multiple times as far is it remains valid. However, the RS should validate the received access token before it returns the requested resource.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*sOLHjjbx_zrfP59qKCS7og.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Now, it is the best time to introduce the concept of ‘&lt;strong&gt;grant type&lt;/strong&gt;’, the underline mechanism that the client requests an access token is known as grant type, grant types are generally defined based on use cases.&lt;/p&gt;
&lt;p&gt;If you look at OAuth2 core spec there are 4 grant types; however; in a contemporary view, 2 grants types should not be used, so it’s more accurate to mention here that there are 2 grants types in the core spec.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Authorisation code grant type&lt;/li&gt;
&lt;li&gt;I̶m̶p̶l̶i̶c̶i̶t̶ ̶g̶r̶a̶n̶t̶ ̶t̶y̶p̶e̶&lt;/li&gt;
&lt;li&gt;R̶e̶s̶o̶u̶r̶c̶e̶ ̶o̶w̶n̶e̶r̶s̶ ̶p̶a̶s̶s̶w̶o̶r̶d̶ ̶g̶r̶a̶n̶t̶ ̶t̶y̶p̶e̶&lt;/li&gt;
&lt;li&gt;Client credentials grant type&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Back then web browsers could not make cross-domain requests and limited to access the domain where the website is hosted; this was a major limitation for JavaScript-based applications when using OAuth2. As a solution for this limitation, the implicit grant type was introduced. However, the CORS standard that is supported by most of the modern web browsers has successfully addressed this limitation so today’s JavaScript-based application can use Authorisation code grant type without any issue. The main security issues associated with the implicit grant type are: it can’t support client authentication and also tokens are visible to the RO via the web browser. If you want to read more, take a look at the following blog posts.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://brockallen.com/2019/01/03/the-state-of-the-implicit-flow-in-oauth2/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;The State of the Implicit Flow in OAuth2&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://medium.com/oauth-2/why-you-should-stop-using-the-oauth-implicit-grant-2436ced1c926&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Why you should stop using the OAuth implicit grant!&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The resource owner password grant type was introduced as a transition step from HTTP BasicAuth to OAuth2 framework. After 8 years of successful adoption, we are no longer in the transition phase, so it’s not required to have transition grant types any more. The main security drawbacks of the resource owner password grant type are: it forces the client to capture username/password from the RO instead of redirecting to the AS, also the RO is limited to use username/password-based authentication. If you want to read more, take a look at the following blog posts.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://www.scottbrady91.com/OAuth/Why-the-Resource-Owner-Password-Credentials-Grant-Type-is-not-Authentication-nor-Suitable-for-Modern-Applications&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Why the Resource Owner Password Credentials Grant Type is not Authentication nor Suitable for Modern Applications&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In OAuth2 jargon, the term endpoint is used to refer to a network address. There are two main endpoints are available within the AS: &lt;strong&gt;authorization endpoint&lt;/strong&gt; and &lt;strong&gt;token endpoint&lt;/strong&gt;. The authorization endpoint is used to get an authorization grant by the client and the token endpoint is used to request an access token.&lt;/p&gt;
&lt;p&gt;The endpoint known as redirection endpoint should be implemented and should be available in the client, this endpoint is used to send authorisation grant and access token by the AS.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*dm01_zCN0tPh40pfj8ev7A.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;oauth2-clients&quot;&gt;OAuth2 Clients&lt;/h3&gt;
&lt;p&gt;OAuth2 clients are identified using an identifier known as &lt;strong&gt;client_id&lt;/strong&gt; which is unique within the specific AS. Generally, &lt;strong&gt;client_id&lt;/strong&gt; is generated by the AS when a client is registered. In addition to that, some of the ASs support the client to provide its own client_id during the client registration process. Although &lt;strong&gt;client_id&lt;/strong&gt; is used to uniquely identify the application, it does not necessarily identify each and every instance of the client application. As an example, all the instances of a mobile application that have been installed in a large number of mobile devices can use the same &lt;strong&gt;client_id&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*0ndlLfECsesH4Y7DuV-7HA.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;In addition to that, depending on the client type, each application is provided with a secret called &lt;strong&gt;client-secret&lt;/strong&gt; which can be used to authenticate the client with the AS during the access token request process.&lt;/p&gt;
&lt;p&gt;OAuth2 clients are grouped into two wider categories known as confidential clients and public clients, let’s look at each of them with some details.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Confidential clients&lt;/em&gt;&lt;/strong&gt; — These are the clients that &lt;strong&gt;can keep&lt;/strong&gt; the &lt;strong&gt;client-secret&lt;/strong&gt; securely. For instance, a server-side web application hosted in web server can. be considered as a confidential client because it can store a &lt;strong&gt;client-secret&lt;/strong&gt; securely. During the client registration, these clients are provided with a client-secret and suppose to use it for client authentication.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Public clients&lt;/em&gt;&lt;/strong&gt; — These are the type of client that &lt;strong&gt;can not keep&lt;/strong&gt; a &lt;strong&gt;client-secret&lt;/strong&gt; securely. Public clients are very common nowadays, mobile applications, SPA applications such as ReactJS, AngulerJS or clients run on devices are good examples for public clients. Since public clients can’t process a &lt;strong&gt;client-secret&lt;/strong&gt; securely, a &lt;strong&gt;client-secret&lt;/strong&gt; should not be provided to them and the AS should not try to authenticate the public client. Instead of client authentication, the AS must use another OAuth2 extension called Proof Key for Code Exchange (PKCE) with public clients.&lt;/p&gt;
&lt;p&gt;By the way, web browser-based clients and device clients such as mobile applications face their own challenges and security concerns; these challenges and constraints are also addressed by the OAuth2 community.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Browser-based application development&lt;/strong&gt; — &lt;a href=&quot;https://tools.ietf.org/html/draft-ietf-oauth-browser-based-apps-05&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;OAuth 2.0 for Browser-Based Apps draft&lt;/strong&gt;&lt;/a&gt; address challenges specific to browser-based application development and define the best practice as well. Some of the challenges include how to use Authorization grant with proper security measures, how to keep access token securely and clarification on various patterns related to browser-based applications.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Device-based application development&lt;/strong&gt; — &lt;a href=&quot;https://tools.ietf.org/html/rfc8252&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;OAuth 2.0 for Native Apps&lt;/strong&gt;&lt;/a&gt; is a current best practice document that addresses the challenges and security issues related to device-based clients such as rich mobile applications. Some best practice includes how to redirect the end-user to the AS server via system browser instead of framework level mechanisms, callback URL techniques and best practices related to security issues.&lt;/p&gt;
&lt;h3 id=&quot;authorization-code-granttype&quot;&gt;Authorization code grant type&lt;/h3&gt;
&lt;p&gt;Authorisation code grant type is the widely used grant type and the recommended grant type for the most of the use cases including server-side web applications, browser-based client-side applications and mobile applications that based on iOS and Android.&lt;/p&gt;
&lt;p&gt;As you can see in the following diagram, the flow of the Authorisation code grant type is pretty much identical to the abstract OAuth2 flow that we have discussed earlier. Let’s examine the authorisation code grant type with some example messages.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*qRyn_gXQNEhITn7vSO2Npw.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step -1&lt;/strong&gt; — The client makes a HTTP GET call to the Authorisation EP over a HTTPS connection with following parameters, also note that the URL should in application/x-www-form-urlencoded format.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;client_id&lt;/strong&gt; — pre-agreed string identifier which the AS used to uniquely identify this client.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;redirect_uri&lt;/strong&gt; — The address of the redirect endpoint of the client in which the client has registered prior to this call.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;scope&lt;/strong&gt; — This is used to mention requested scopes for the access token.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;response_type=code&lt;/strong&gt; — This is a fixed value for this grant type, the AS use this parameter to determine the grant type.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;a href=&quot;https://localhost:9443/oauth2/authorize?**client%5C_id**%5C=g6%5C_E15YBhaMoHeGOzlFR6TpD4%5C_Ua&amp;#x26;scope=read&amp;#x26;redirect%5C_uri=http://127.0.0.1:5000/&amp;#x26;**response%5C_type=code&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://localhost:9443/oauth2/authorize?**client\_id**\=g6\_E15YBhaMoHeGOzlFR6TpD4\_Ua&amp;#x26;scope=read&amp;#x26;redirect\_uri=http://127.0.0.1:5000/&amp;#x26;**response\_type=code&lt;/a&gt;**&lt;/p&gt;
&lt;p&gt;Once the server receives this request, it validates &lt;strong&gt;client_id&lt;/strong&gt; and &lt;strong&gt;redirect_uri&lt;/strong&gt;, if there is no issue found it will redirect the user-agent to the authentication page of the AS in order to authenticate the resource owner. Usually, this will be followed by a number of redirect calls based on authentication configuration of the server; in terms of OAuth2, it doesn’t matter how does the AS authenticate the RO.&lt;/p&gt;
&lt;p&gt;Once the authentication and authorization are successful, the server returns a valid authorization grant in which represent the approval of the RO the client. The AS uses user-agent to send the authorization grant to the redirect-EP of the client, usually by executing an automatic HTML form submission via a script. This also means that authentication grant ( code) is visible to the RO via the user-agent.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://127.0.0.1:5000/?**code**%5C=9bf93eb9-d1de-3fc2-950c-4f17d79d8876&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;http://127.0.0.1:5000/?**code**\=9bf93eb9-d1de-3fc2-950c-4f17d79d8876&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step -2&lt;/strong&gt; — During this step, the client directly call the token endpoint of the AS without using the web browser; typically making a POST request over HTTPS. The following are the most important parameters of this request.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;grant_type=authorization_code&lt;/strong&gt; — this is a constant parameter value used to differentiate authorisation grant type based token requests from other token requests.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;redirect_uri&lt;/strong&gt; — The address of the redirect endpoint of the client in which the client has registered prior to this call.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;code&lt;/strong&gt; — This is the value that the client has received in the previous step.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Also, note that the client_id and the client_secret should be sent using HTTP HTTP Authorization header in order for the AS to authenticate the client. This value takes &lt;strong&gt;base64(client_id:client_secret)&lt;/strong&gt; format.&lt;/p&gt;
&lt;p&gt;curl -k -X POST - user “g6_E15YBhaMoHeGOzlFR6TpD4_Ua:BhUDJqMoYo8mgfU6f3fZXn16BEUa” -H “Content-Type: application/x-www-form-urlencoded” -d “&lt;strong&gt;grant_type=authorization_code&lt;/strong&gt;&amp;#x26;&lt;strong&gt;code&lt;/strong&gt;=1ca46bf5-dffe-38fc-a576-f04f97ce5a28&amp;#x26;redirect_uri=&lt;a href=&quot;http://127.0.0.1:5000/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;http://127.0.0.1:5000/&lt;/a&gt;” &lt;a href=&quot;https://localhost:9443/oauth2/token&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://localhost:9443/oauth2/token&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Upon receiving the above request, the AS first try to authenticate the client and then verify the received code and redirect_uri values. If everything is ok, the AS returns an access token to the client with additional metadata.&lt;/p&gt;
&lt;p&gt;{&lt;br&gt;
“&lt;strong&gt;access_token&lt;/strong&gt;”:“48c4abd3–3f7e-3eee-8ac8–9e3fd0c435ec”,&lt;br&gt;
“refresh_token”:“488c282a-7b11–3b57-b907-ae1cc90680f4”,&lt;br&gt;
“scope”:“read”,&lt;br&gt;
“token_type”:“Bearer”,&lt;br&gt;
“expires_in”:3600&lt;br&gt;
}&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;access_token&lt;/strong&gt; — This contains the access token for the client.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;refresh_token&lt;/strong&gt; — This token can be used to request an access token once the current access token expired without going through the step-1, we will discuss this topic separately.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;token_type&lt;/strong&gt; — The type of token.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;expires_in&lt;/strong&gt; — validity period of the current access token.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Step -3 — Client access the protected resource on the RS by presenting the access token. It is expected from the RS to validate the access token by contacting the AS or some other means before it grants access to the resource.&lt;/p&gt;
&lt;p&gt;curl &lt;a href=&quot;http://api.example.com/articles&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;http://api.example.com/articles&lt;/a&gt;  -H “Authorization: Bearer 48c4abd3–3f7e-3eee-8ac8–9e3fd0c435ec”&lt;/p&gt;
&lt;p&gt;Note that, the value of HTTP Authorization header use &lt;strong&gt;Bearer ACCESS_TOKEN&lt;/strong&gt; format.&lt;/p&gt;
&lt;h3 id=&quot;client-credentials-granttype&quot;&gt;Client Credentials grant type&lt;/h3&gt;
&lt;p&gt;Sometimes the above-discussed Authorization Code grant type is known as a 3-legged OAuth2 flow because it involves three parties: the AS, the client and the end-user; in contrast to that Client Credentials grant type is known as a 2-legged OAuth2 flow because it only involves two parties: the AS and the client. As an example, a Facebook client installed on your mobile device accessing the Facebook API to get some application data ( not user data or user-specific data) can be considered as a use case for Client Credentials grant type. Also, note that this grant type is only applicable to confidential clients because client authentication is a requirement of this grant type.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*SCiDJNnyW2GLR_13rMS1ag.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step -1&lt;/strong&gt; — The client makes a HTTP GET call to the Token EP over a HTTPS connection with following parameters, also note that the URL should in application/x-www-form-urlencoded format.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;grant_type=client_credentials&lt;/strong&gt; — this is a constant parameter value used to differentiate client credentials grant type based token requests from other token requests.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;scope&lt;/strong&gt; — This is used to mention requested scopes for the access token.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Also, note that the &lt;strong&gt;client_id&lt;/strong&gt; and the &lt;strong&gt;client_secret&lt;/strong&gt; should be sent using the HTTP Authorization header in order for the AS to authenticate the client. This value takes &lt;strong&gt;base64(client_id:client_secret)&lt;/strong&gt; format.&lt;/p&gt;
&lt;pre class=&quot;astro-code astro-code-themes github-light nord&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#d8dee9ff;--shiki-light-bg:#fff;--shiki-dark-bg:#2e3440ff; overflow-x: auto; white-space: pre-wrap; word-wrap: break-word;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt; POST /token HTTP/1.1  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt; Host: server.example.com  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt; Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt; Content-Type: application/x-www-form-urlencoded  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt; **grant\_type=client\_credential**&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Upon receiving the above request, the AS first try to authenticate the client. If everything is ok, the AS returns an access token to the client with additional metadata.&lt;/p&gt;
&lt;p&gt;{&lt;br&gt;
“&lt;strong&gt;access_token&lt;/strong&gt;”:“48c4abd3–3f7e-3eee-8ac8–9e3fd0c435ec”,&lt;br&gt;
“refresh_token”:“488c282a-7b11–3b57-b907-ae1cc90680f4”,&lt;br&gt;
“scope”:“read”,&lt;br&gt;
“token_type”:“Bearer”,&lt;br&gt;
“expires_in”:3600&lt;br&gt;
}&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;refresh_token&lt;/strong&gt; — This token can be used to request an access token once the current access token expired without going through the step-1, we will discuss this topic separately.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;token_type&lt;/strong&gt; — The type of token.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;expires_in&lt;/strong&gt; — validity period of the current access token.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Step -3&lt;/strong&gt; — Client access the protected resource on the RS by presenting the access token. It is expected from the RS to validate the access token by contacting the AS or some other means before it grants access to the resource.&lt;/p&gt;
&lt;p&gt;curl &lt;a href=&quot;http://api.example.com/articles&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;http://api.example.com/articles&lt;/a&gt; -H “Authorization: Bearer 48c4abd3–3f7e-3eee-8ac8–9e3fd0c435ec”&lt;/p&gt;
&lt;p&gt;Note that, the value of HTTP Authorization header use &lt;strong&gt;Bearer ACCESS_TOKEN&lt;/strong&gt; format.&lt;/p&gt;
&lt;h3 id=&quot;proof-key-for-code-exchangepkce&quot;&gt;Proof Key for Code Exchange (PKCE)&lt;/h3&gt;
&lt;p&gt;PKCE is the acronym for Proof Key for Code Exchange — which is an extension for OAuth2 framework. As we discussed in a previous section PKCE must be used with public clients when they generating access tokens. However, it’s recommended to use PKCE with confidential clients as well.&lt;/p&gt;
&lt;p&gt;In short, a one-time randomly generated cryptographical key is generated by the client and pass to the AS with the initial authorization request and the subsequent token request. The idea here is if an attacker manages to hijack the authorization grant (a.k.a ‘code’), still it can not use it to generate an access token because the PKCE key (known as ‘&lt;strong&gt;code verifier&lt;/strong&gt;’ ) is unknown to the attacker.&lt;/p&gt;
&lt;p&gt;Up to now, we have covered basic grant types defined in the core framework. In the following sections, I will introduce other extension grants types widely used today in brief and I hope to cover these grants type in details in my future posts.&lt;/p&gt;
&lt;h3 id=&quot;refresh-token-granttype&quot;&gt;Refresh Token grant type&lt;/h3&gt;
&lt;p&gt;I believe you remember about the &lt;strong&gt;refresh token&lt;/strong&gt; returned along with access token request, the purpose of this refresh token is to allow clients to request new access by presenting a valid refresh token without reauthenticating the end-user again. This usually happens once the current access token expired and greatly enhance the user experience. This flow is much similar to the token request (2nd interaction) of the Authorization Code grant type, but refresh token grant type uses a “&lt;strong&gt;Refresh token&lt;/strong&gt;” instead of an “&lt;strong&gt;Authorization code&lt;/strong&gt;” to request a new access token.&lt;/p&gt;
&lt;p&gt;Once the token request received, the AS checks the validity of the refresh token along with some other checks and if everything is ok then return a new access token usually along with another refresh token which can be used subsequently.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*mSTGrgUikjg7g-OTejlVRg.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;saml-assertion-and-jwt-assertion-granttypes&quot;&gt;SAML Assertion and JWT Assertion grant types&lt;/h3&gt;
&lt;p&gt;In Authorization Code grant type, the client does not possess any credential or any authorization token from the end-user, and that is why it has to redirect the end-user to the AS and acquires an “&lt;strong&gt;Authorization code&lt;/strong&gt;” first (which represent the end-user approval ) before requesting an access token.&lt;/p&gt;
&lt;p&gt;So, what would be the situation if the client possesses some kind of security tokens such as SAML token or JWT token?&lt;/p&gt;
&lt;p&gt;As you can imagine, there are OAuth2 extension grant types that allow the AS to accept these security tokens as valid authorization grants and issue an access token in return.&lt;/p&gt;
&lt;p&gt;SAML Assertion grant type facilitates a client to pass a SAML token and requests an access token and JWT Assertion grant type facilitates a client to pass a JWT security token when requesting an access token. Both of these grant types leverage great level of flexibility to OAuth2 framework to interoperate with other security eco-systems, especially with SAML based previous-generation web SSO environments.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*5oTnXLdl8gXc987I9gaLdg.png&quot; alt=&quot;&quot;&gt;
&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*LYRzVl9eSWgLQC1IokG5Lg.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;token-exchange-granttype&quot;&gt;Token Exchange grant type&lt;/h3&gt;
&lt;p&gt;This grant type facilitates to request a new access token by presenting an existing token mainly to support impersonation and delegation use cases. This grant type needs to be discussed in detail so I will cover it in a future post.&lt;/p&gt;
&lt;h3 id=&quot;oauth2-tokentypes&quot;&gt;OAuth2 token types&lt;/h3&gt;
&lt;p&gt;The OAuth2 framework does not specify any specific token format and lets implementers (usually ASs) define the format of the token and attributes of the token. A brief summary of two widely used token types is given below.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Opaque Bearer&lt;/em&gt;&lt;/strong&gt; — As its name implies this is a reference type-token; this means no sensitive user data are encoded in the token. If an attacker manages to receive a token, the attacker can not find any useful information by decoding the token, most of the cases this is just a random string. Generally, the AS that issued the token can provide information about the token to the authorized parties such as AS once the token is presented to the AS; technically, this is known as Token Introspection. As you can expect, there is a separate spec for that as well.&lt;/p&gt;
&lt;p&gt;The other main characteristic of the opaque bearer token is whoever processes the token can legitimately use the token without proving their identity. In real-world, this is similar to use of currency notes at a shop where anybody can use them without proving their identity in contrast to credit cards where it’s necessary to have a signature check or a secure pin.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;JWT Bearer&lt;/em&gt;&lt;/strong&gt; — Use of this token type is similar to opaque bearer token: that is whoever holds the token can legitimately use it. However, the main difference is sensitive user and token data are encoded within the token. In some environments, this may present a security risk but token encryption can mitigate the potential risk up to an acceptable level. The main advantage of this access token type is intended audience ( such as RS ) can themselves validate and access user and token data without contacting the issued AS.&lt;/p&gt;
&lt;h3 id=&quot;token-introspection&quot;&gt;Token Introspection&lt;/h3&gt;
&lt;p&gt;In the previous section, we discussed that opaque (bearer) tokens do not contain any useful information about the user or the token itself, and it’s required to contact the issued AS to verify and learn details about the token. The Token Introspection spec standardize this interaction with the client and the AS. By presting a token to the introspection endpoint defined by the specification, an authorized party can receive information about the token such as the validity of the token, expiration of the token and attributes related to the end-user etc.&lt;/p&gt;
&lt;h3 id=&quot;token-revocation&quot;&gt;Token Revocation&lt;/h3&gt;
&lt;p&gt;By design, access tokens are meant to be expired after a short period without any external intervene; however, there can be situations that the token need to be revoked before its expiration period, especially access token with a long or infinite expiration time. In such cases, the OAuth2 framework defines special endpoint called revocation endpoint that allows authorized parties such as the end-user and the OAuth2 client to revoke the token. Once revoked, the access tokens become invalidated and can’t be used further.&lt;/p&gt;
&lt;h3 id=&quot;authorization-servermetadata&quot;&gt;Authorization Server Metadata&lt;/h3&gt;
&lt;p&gt;At this point, you are aware that, to request an access token from an AS a client should know some information about the AS such as URLs of token and authorization endpoints, supported grant types, supported scopes, the identity of the AS etc. One possible approach to make this information available is to have human-readable documentation somewhere so that the client application developer can access it. This approach is still widely used and quite popular as well.&lt;/p&gt;
&lt;p&gt;The other option is, facilitate to discover the above information via an automated mean, and that is the intended purpose of Authorization Server Metadata specification. It defines a standard endpoint and message semantics, by sending a request message an OAuth2 client can receive information about the AS.&lt;/p&gt;
&lt;h3 id=&quot;client-registration--client-manamgnet&quot;&gt;Client registration &amp;#x26; Client Manamgnet&lt;/h3&gt;
&lt;p&gt;In a previous section, we discussed that having a &lt;strong&gt;client _id&lt;/strong&gt; and a &lt;strong&gt;client_secret&lt;/strong&gt; as a prerequisite to making a token request; but, we haven’t discussed how a client can register with an AS to receive a client _id and a client_secret. In brief, a client can use the following approaches:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;&lt;em&gt;Online portal&lt;/em&gt;&lt;/strong&gt; — application developers can register themselves with the AS and generate a client _id and a client_secret. Most of the social identity providers such as Facebook, Twitter use this approach.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Offline channels&lt;/strong&gt; — Client developers can contact the support staff of the AS via e-mails or some other means to register the application and receive a pair of a client _id and a client_secret.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dynamic Client Registration (DCR)&lt;/strong&gt; — This is a RESTful endpoint exposed by the AS. The client applications can dynamically register with the AS by sending a registration request, and receive client _id and a client_secret as well.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dynamic Client Registration Management (DCR -M)&lt;/strong&gt; — This is also a RESTful endpoint exposed by the AS and going had in hand with DCR. DCR standard is limited to client registration only, while &lt;strong&gt;DCR -M&lt;/strong&gt; standard defines semantics to modify and delete client application.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;oauth2-extensions&quot;&gt;OAuth2 extensions&lt;/h3&gt;
&lt;p&gt;There are a number of OAuth2 extensions are available, among them, it’s worth to discuss the following two. However, these are good candidates for separate posts.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;OpenID Connect&lt;/em&gt;&lt;/strong&gt; — This is an identity protocol extended from OAuth2. If you are familiar with SAML, OpenID Connect use cases are almost identical to that.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;UMA2&lt;/em&gt;&lt;/strong&gt; — OAuth2 is mainly about access delegation to an application, mainly to a non-human. As an end-user, how do you delegate access to a human to access your resources on behalf of you? That is the primary problem space of UMA2 standard which is also an OAuth2 extension.&lt;/p&gt;
&lt;p&gt;Also, note that as of writing this post there is an on-going effort within the OAuth2 working group to develop OAuth 2.1 specification targeting to cover the wider scope and up to date practice. You can refer to the current draft of 2.1 specs from &lt;a href=&quot;https://tools.ietf.org/html/draft-parecki-oauth-v2-1-01&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This is a very long post; but, I believe I have provided you with a comprehensive picture not only about the core OAuth2 specification but also about the supporting standards of the OAuth2 eco-system. You also can find all OAuth2 related specifications and their current status from &lt;a href=&quot;https://tools.ietf.org/wg/oauth/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;. I hope to write similar posts about each of these supporting specifications as well.&lt;/p&gt;</content:encoded><dc:creator>Sagara Gunathunga</dc:creator><category>OAuth 2.0</category><category>OpenID Connect</category></item><item><title>Preventing BOLA and BFLA: OWASP API Authorization Flaws</title><link>https://sagarag.dev/posts/how-to-avoid-broken-object-level-authorization</link><guid isPermaLink="true">https://sagarag.dev/posts/how-to-avoid-broken-object-level-authorization</guid><description>How to prevent Broken Object Level Authorization (BOLA) and Broken Function Level Authorization (BFLA), top OWASP API risks, using OAuth scopes and policies.</description><pubDate>Wed, 02 Oct 2019 09:02:00 GMT</pubDate><content:encoded>&lt;p&gt;OWASP project recently finalised their API Security Top 10 list into RC level; you can have a look at it from &lt;a href=&quot;https://github.com/OWASP/API-Security&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;. When I went through the list, I was a bit surprised because most of the top security vulnerabilities are fundamental principles that we had been practising for a long time; it seems that we have forgotten most of these basics while we are busy with new technology advancements.&lt;/p&gt;
&lt;p&gt;This post discusses Broken Object Level Authorization and Broken Function Level Authorization vulnerabilities and several remedies to avoid these vulnerabilities. I start by discussing Broken Function Level Authorization and then move into Broken Object Level Authorization.&lt;/p&gt;
&lt;h3 id=&quot;broken-function-level-authorization&quot;&gt;Broken Function Level Authorization&lt;/h3&gt;
&lt;p&gt;Broken Function Level Authorization is the 5th top-most API security vulnerability in OWASP list. First, let’s understand what that means without using any security jargon; here, I use a very straightforward (hypothetical) exam management system to explain the issue.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*149vU8TrW3vSD-CvHL80Lg.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Assume there is a modern exam management system called “GetMyResults”, which provides two separate mobile apps for students &amp;#x26; teachers, and a modern RESTful API backs the mobile apps. Once the student app is installed, it only allows for a particular student to check individual marks; there are no other functionalities available in this app. In contrast to that, the teacher app will enable teachers to submit marks to the system; teachers are allowed to submit marks for modules that have been assigned to them.&lt;/p&gt;
&lt;p&gt;If we look at the system architecture, there is a RESTful API called “Results”, which supports basic CURD operations; and this API is adequately secured using OAuth2 protocol in a way that mobile apps should receive an access token from the system by redirecting to the system for authentication and authorization.&lt;/p&gt;
&lt;p&gt;Assume one bright student managed to analyse the student mobile app and found out the following details.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Student mobile app calls the following API.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*ROf9vPU84HQygRrUmOilxg.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;2. The mobile app uses the following OAuth2 access token to call the above API.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*THYctZO1lSi5l8yA8pyuRg.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Now, with his RESTful API design skills, the student tried to perform the following experiment, just using a straightforward tool like cURL. He tried to make the following call presenting the above access token.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*711mKHfLGus8BvhwCwFAiw.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;After the experiment, the student surprised to see that his marks for maths have changed to 98! How that possible?&lt;/p&gt;
&lt;p&gt;To understand what went wrong, let’s carefully examine the following OAuth2 response that mobile apps have received from the system.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*Dk9GmHKDMQK9agnBHDR0jg.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Can you find any similarities between the above OAuth2 responses other than the same format?&lt;/p&gt;
&lt;p&gt;Yes, you are correct; although access tokens and refresh tokens are different, &lt;strong&gt;the value of the scope attribute is the same&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Now you may think, what is wrong with that? It makes sense to have different access tokens and refresh tokens because those are bound to different users and different apps (OAuth2); but, the scope is attached with API, so it should be the same value. This is the exact point that I wanted to emphasise! According to API security best practices, OAuth2 scopes need to be designed based on functional capabilities in a fine-grained manner instead of having one scope per each API. The current scope design can be depicted as follows.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*C4_hKG_zEiK-Qq56D4Sg6A.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;The following diagram shows the same API after applying the above-discussed fine-grained scope principle&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*puHf7FZ0cBj-_1NaLcTmhg.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Now, let’s try to compare OAuth2 response traces from both apps after applying the above principle.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*697M0t1WunvceSABeghYeA.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;As you can see, the student app has received an access token with only “read-scope”, which means it can only execute GET resources. Still, on the other hand, the teacher app has received an access token with two scopes to perform both read and write operations.&lt;/p&gt;
&lt;p&gt;If you have some experience in the OAuth2 framework, you may want to raise another question: regardless of the above design fix, when an attacker makes a token request, the attacker still can send a request with both scopes, so, what can we do to prevent that?&lt;/p&gt;
&lt;p&gt;Firstly, your API scope implementation is needed to be backed with a robust authorization mechanism. Once a user gets authenticated to the system, it should check whether is it possible to generate a token with all the requested scopes based on authorization policies. For example, let’s consider a simple Role-Based Access Control (RBAC) system; in such scenarios, it’s required to maintain a scope-to-role mapping somewhere and evaluate before generating access tokens.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*SKa81EhlNEh098kI9HIktQ.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;An alternative approach would be, keep the Coarse-grained scope design at the API level and perform fine-grained authorization checks at the backend API level; personally, I don’t like this approach because it misses the whole point of the Secure API concept. However, this does not mean you should forget backend service-level authorization; instead, the point is you should not design vulnerable APIs making assumptions on backend security.&lt;/p&gt;
&lt;h3 id=&quot;broken-object-level-authorization&quot;&gt;Broken Object Level Authorization&lt;/h3&gt;
&lt;p&gt;Now, let’s try to understand Broken Object Level Authorization vulnerability using the same example. Also, note that this is the number -1 API security evaluability of OWASP list. Our smart student knows the student-ids of some of his friends, so he wanted to give it a try by making a call to the API with an id belong to one of his friends. He eventually ran a cURL with the following format and managed to read his friends’ mark! This is not the intended usage of the system. Students should check their own marks and certainly not the marks of other students! In this example, the issue begun due to a lack of object (data) level authorization.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*USRdVBhCRpFjWYZBkj5EBA.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;To prevent this vulnerability, the API layer should check whether the requested party can access the required data/objects based on authorization policies. To highlight again, this issue is different from the previously discussed Broken Function Level Authorization vulnerability. In the current case, the attacker is making a legitimate API call by trying to view results, but the problem here is the attempt to access a data element that is not authorised to access.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*VsnCZ15xkVQBvdtUMLU0bA.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;There are multiple solutions to prevent this vulnerability but performing the authorization check for data/object access is a common requirement for any of these solutions; I have discussed two possible solutions below.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;For an API hosted in an API Gateway, it is possible to enforce an authorization check at the gateway level; either the API Gateway itself can perform policy evaluation locally, or it is possible to delegate an authorization check to a remote policy evaluation point. These access policies can be stored centrally or possible to sync with the local policy stores periodically. Policy implementations such as XACML, Open Policy Engine (OPA) can define these policies. For instance, in this example, there should be a policy similar to “ &lt;em&gt;If the user is authenticated and the role is ‘student’ then he can only access the data record that contains user’s id&lt;/em&gt;”. However, this centralised policy management and evaluation approach may not suit some use cases due to complexity and inflexibility.&lt;/li&gt;
&lt;li&gt;Suppose the API is local to the app, such as in Java JAX-RS or SpringBoot REST service. In that case, it’s straightforward to perform these data/object level authorization checks using traditional Role-Based Access Control (RBAC) mechanisms. Compare to the above approach; this is much simple and easy to manage.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;how-to-address-both-together&quot;&gt;How to address both together?&lt;/h3&gt;
&lt;p&gt;Considering both vulnerabilities and fixes discussed so far, I would like to present two unified solutions to address both vulnerabilities&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution 1 :&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*7uSrbRTtkKsVTlsF5v4m9A.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Perform API resource (function) level authorization at the API Gateway based on OAuth2 scopes to prevent Broken Function Level Authorization vulnerability. If the access token is an opaque token, the gateway should contact the OAuth2 STS via Introspection Endpoint to learn more about the token before the authorization check occurs. If the access token is a self-contained token such as JWT, the gateway can validate the token itself by checking the signature.&lt;/li&gt;
&lt;li&gt;Once the above step is completed, to prevent Broken Object Level Authorization vulnerability, the gateway should perform another authorization check to determine whether the authenticated user can access the requested data/object, for this, the gateway can locally evaluate the access policies, or the gateway can contact remote policy evaluation points such as OPA engine or XACML PEP/PDP.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Solution 2 :&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*WqTQiNY8UaICZ4plg6T0tw.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;This step is identical to the 1st step of the above solution, perform API resource (function) level authorization at the API Gateway based on OAuth2 scopes to prevent Broken Function Level Authorization vulnerability. If the access token is an opaque token, the gateway should contact the OAuth2 STS via Introspection Endpoint to learn more about the token before the authorization check takes place. If the access token is a self-contained token such as JWT, the gateway can validate the token itself by checking the signature.&lt;/li&gt;
&lt;li&gt;Once the 1st step is completed, the gateway should pass the message to the backend along with a JWT token, and this token carries user identity, user attributes and roles. The gateway or STS service can generate this JWT token based on the authenticated user.&lt;/li&gt;
&lt;li&gt;Based on information available in the JWT token at the backend API, the backend API is responsible for performing an authorization check to determine whether the authenticated user can access the requested data/object. The backend API either perform this check locally or possible to delegate to a remote policy engine.&lt;/li&gt;
&lt;/ol&gt;</content:encoded><dc:creator>Sagara Gunathunga</dc:creator><category>API Security</category><category>OAuth 2.0</category></item><item><title>SAML Web Browser SSO Profile: SP and IdP-Initiated Flows</title><link>https://sagarag.dev/posts/reloading-saml-web-browser-sso-profile</link><guid isPermaLink="true">https://sagarag.dev/posts/reloading-saml-web-browser-sso-profile</guid><description>SAML 2.0 Web Browser SSO Profile explained: SP-initiated vs IdP-initiated SSO, Redirect and POST bindings, AuthnRequest and Response anatomy, and RelayState.</description><pubDate>Sat, 09 Jun 2018 16:04:41 GMT</pubDate><content:encoded>&lt;p&gt;So far I have discussed key constructs of &lt;a href=&quot;https://sagarag.dev/posts/saml-basics&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;SAML 2.0 core standard&lt;/a&gt; and few supportive standards such as &lt;a href=&quot;https://sagarag.dev/posts/saml-idp-discovery&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;IDP Discovery&lt;/a&gt; and &lt;a href=&quot;https://sagarag.dev/posts/why-do-you-need-metadata&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;SAML Metadata&lt;/a&gt; too. Starting from this post, I’m planning to discuss SAML Profiles, if I recall our discussion about &lt;a href=&quot;https://sagarag.dev/posts/saml-basics&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;SAML profiles&lt;/a&gt;, profiles are practical use-cases defined in terms of basic SAML constructs such as Assertions, Bindings and Protocols. In this post, I will discuss ‘Web Browser SSO Profile’, which is one of the widely used SAML profile. In Web Browser SSO profile, a user access a SP via a web browser, the presence of a web browser is mandatory.&lt;/p&gt;
&lt;p&gt;Before we discuss further, I would like to provide you the following fact sheet about Web Browser SSO Profile.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*uKYLV1KKoQhVhSKD_hnsjA.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Depend on the direction of the message flows it’s possible to divide this profile as SP initiated SSO, and IdP initiated SSO.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*S7VRGoR0HiYBDFaK&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;sp-initiated-sso-vs-idp-initiated-sso&quot;&gt;&lt;strong&gt;SP-initiated SSO vs IdP-initiated SSO&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*j5BEp0rRerX0f6-9KWVlXg.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;In SP-initiated Web Browser SSO approach, the user first access the login page or restricted resource within the SP, this approach usually consists of the following 3 steps.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The user first access the login page or restricted resource within the SP.&lt;/li&gt;
&lt;li&gt;The SP redirects the user to the IdP with a SAML authentication request.&lt;/li&gt;
&lt;li&gt;IdP authenticates the user and returns the user with a valid SAML assertion or error message.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;In IdP-initiated Web Browser SSO approach, the user first access the IdP and once the authentication is successful IdP redirects the user to the SP. This approach usually consists of the following 2 steps.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The user first access the login page within the IdP, the IdP authenticate the user.&lt;/li&gt;
&lt;li&gt;User clicks a link within the IdP which redirect the user to the specific SP with a valid SAML assertion.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;sp-and-idp-endpoints&quot;&gt;&lt;strong&gt;SP and IdP endpoints&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*O-4j-COpUfFugjs8&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;If we leave HTTP Artifact binding for a while, this profile mainly assumes the availability of two network endpoints, one at the IdP and another one at the SP.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Single Sign-on Service&lt;/em&gt;&lt;/strong&gt; — This is a network endpoint exposed by the IdP, the SP suppose to send SAML authentication requests to this endpoint via HTTP GET or POST. According to SAML specification, this endpoint needed to be secured using the latest TLS security.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Assertion consumer Service&lt;/em&gt;&lt;/strong&gt; — This is a network endpoint exposed by the SP, the IdP suppose to send SAML response messages to this endpoint via HTTP POST. According to SAML specification, this endpoint also needed to be secured using the latest TLS security.&lt;/p&gt;
&lt;h3 id=&quot;sp-initiated-web-browsersso&quot;&gt;&lt;strong&gt;SP-initiated Web Browser SSO&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*8hJkx798zY2bltRm&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;As we have seen in the above section SP-initiated approach consists with 3 steps, but the very first step that is the user access the SP via a browser is out of the scope of our discussion (however usually we can assume that the user type SP URL in the browser or click a bookmark to reach the SP) During the step 2 and 3 it’s required to transport SAML messages from SP to IdP and IdP to SP, to achieve that one of the following SAML binding combinations can be used.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*BnQHto04_rsYAQ6qnzdATA.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;During the next few sections we will look at some of the above combinations in detail.&lt;/p&gt;
&lt;h3 id=&quot;sp-initiated-redirectpost&quot;&gt;SP-initiated Redirect — POST&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*WjNECodGo2ob-p9V&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;The above diagram depicts SP-initiated Redirect — POST approach with exact message structures, however, I use the following sequence diagram to further explain this approach.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*rm36SIzgXcEhgS_j&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;In the initial step the user tries to access a secure resource/page at the SP, usually through a HTTP GET request from the browser to the SP.&lt;/li&gt;
&lt;li&gt;As the 2nd step, the SP determines the correct IdP associated with the current user. The mechanism used to determine the correct IdP is implementation-specific, one possible option is the IdP Discovery mechanism that we discussed in &lt;a href=&quot;https://sagarag.dev/posts/saml-idp-discovery&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;a previous post&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Once the SP decides the correct IdP it generates a SAML authentication request. To generate this request SP needs some level of information about the IdP such as unique identifiers, public certificates, supported binding and SSO service location etc. the SP should able to find these details using proprietary approach such as reading a configuration file or standard approach such as &lt;a href=&quot;https://sagarag.dev/posts/why-do-you-need-metadata&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;IdP Metadata&lt;/a&gt; specification.&lt;/li&gt;
&lt;li&gt;Once the SP generate a proper SAML authentication request, it returns a HTTP redirect ( 302) message back to the browser with a URL of the SSO service endpoint of the IdP. URL encoded SAML request is appended to the above redirect URL as the value of “&lt;strong&gt;SAMLRequest&lt;/strong&gt;” query string parameter, optionally it is possible to have “&lt;strong&gt;RelayState&lt;/strong&gt;” query string parameter. You can read further details about this point from one of my previous post about &lt;a href=&quot;https://sagarag.dev/posts/saml-basics&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;SAML Bindings&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;The browser follows the redirect message and issue a HTTP GET request to the SSO service endpoint of the IdP, note that this URL contains the encoded SAML request along with RelayState.&lt;/li&gt;
&lt;li&gt;At the IdP once it receives the above SAML request, it checks whether an active authentication context exists for the current user or not, if not the IdP try to authenticate the current user based on its configuration, usually this can result into several back-and-forth interactions with the user. Once the IdP completed the authentication and creation of user session, it generates a SAML response which contains one or more SAML assertions about the authenticated user.&lt;/li&gt;
&lt;li&gt;As the next step IdP generate a HTML form control with SAML response and return to the browser. You can read further details about this point from one of my previous post about &lt;a href=&quot;https://sagarag.dev/posts/saml-basics&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;SAML Binding&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;At the browser, it submits the received HTML Form to the ACL URL of the SP.&lt;/li&gt;
&lt;li&gt;At the SP, it read the SAML response message and decide to grant the access.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Note that the HTML form mentioned in the above step 7 consists of following HTML form controls.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;em&gt;SAML Response&lt;/em&gt;&lt;/strong&gt; — The encode SAML Response is set as the value of hidden HTML input control called “SAMLResponse”&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;RelayState&lt;/strong&gt; — The original value received as RelayState is set as the value of hidden HTML input control called “RelayState”&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SP’s ACL URL&lt;/strong&gt; — ACL URL of the SP is set as the &lt;strong&gt;&lt;em&gt;action&lt;/em&gt;&lt;/strong&gt; of the HTML form control.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A script&lt;/strong&gt; (e.g — Javascript) that will auto-submit the above HTML Form at the browser to the SP.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;sp-initiated-postpost&quot;&gt;&lt;strong&gt;SP-initiated POST — POST&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*XRWPEtuxNbW3hIZO&quot; alt=&quot;&quot;&gt;
&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*L32clwe8xXG_vjIV&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;The above diagrams illustrate the exact message flows under SP-initiated POST — POST approach.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;In the very first step the user tries to access a secure resource/page at the SP, usually through a HTTP GET request from the browser to the SP.&lt;/li&gt;
&lt;li&gt;As the 2nd step, the SP determines the correct IdP associated with the current user. The mechanism used to determine the correct IdP is implementation-specific, one possible option is the IdP Discovery mechanism that we discussed in &lt;a href=&quot;https://sagarag.dev/posts/saml-idp-discovery&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;a previous post&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Once the SP decides the correct IdP it generates a SAML authentication request. To generate this request message SP need some level of information about the IdP such as unique identifiers, public certificates, supported binding and SSO service location etc. the SP should able to find these details using a proprietary approach such as reading a configuration file or standard approach such as &lt;a href=&quot;https://sagarag.dev/posts/why-do-you-need-metadata&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;IdP Metadata&lt;/a&gt; specification.&lt;/li&gt;
&lt;li&gt;Once the SP generates a proper SAML authentication request, it retunes a HTTP 200 message back to the browser with a HTML Form plus a script that can be used to submit this HTML form the SSO service endpoint of the IdP. Generated SAML request is encoded as the value of hidden input control named “&lt;strong&gt;SAMLRequest&lt;/strong&gt;”, You can read further details about this point from one of my previous post about &lt;a href=&quot;https://sagarag.dev/posts/saml-basics&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;SAML Bindings&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Upon the receiving of above HTTP message from SP, IdP submits the HTML Form to the IdP by executing the script.&lt;/li&gt;
&lt;li&gt;At the IdP once it receives the above SAML request, it checks whether an active authentication context exists for the current user or not, if not IdP try to authenticate the current user based on its configuration, usually this can result into several back-and-forth interactions with the user. Once the IdP completed the authentication and creation of user session, it generates a SAML response which contains one or more SAML assertions about the authenticated user.&lt;/li&gt;
&lt;li&gt;As the next step IdP generate a HTML form control with SAML response and returns to the browser. You can read further details about this point from one of my previous post about &lt;a href=&quot;https://sagarag.dev/posts/saml-basics&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;SAML Binding&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;At the browser, it submits the received HTML Form to the ACL URL of the SP.&lt;/li&gt;
&lt;li&gt;At the SP, it read the SAML response message and decide to grant the access or not.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Note that the HTML form mentioned in the above step 7 consists of following HTML form controls.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;em&gt;SAML Response&lt;/em&gt;&lt;/strong&gt; — The encode SAML Response is set as the value of hidden HTML input control called “SAMLResponse”&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;RelayState&lt;/strong&gt; — The original value received as RelayState is set as the value of hidden HTML input control called “RelayState”&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SP’s ACL URL&lt;/strong&gt; — ACL URL of the SP is set as the &lt;strong&gt;&lt;em&gt;action&lt;/em&gt;&lt;/strong&gt; of the HTML form control.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A script&lt;/strong&gt; (e.g — Javascript) that will auto-submit the above HTML Form at the browser to the SP.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;idp-initiated-web-browsersso&quot;&gt;&lt;strong&gt;IdP-initiated Web Browser SSO&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*49_t6eKNppAkTGBn&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Like in IdP-initiated case, the very first iteration, that is the very first user interaction with the IdP is out of the scope of our discussion, for the 2nd step, that is to transmit SAML response from IdP to SP one of the following binding option can be used.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*DRYBpCvS1tqD97UMPTS5JA.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Following diagrams illustrates exact message flows under this approach.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*yR6l01ytoduh6OG0&quot; alt=&quot;&quot;&gt;
&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*H-9Fuf50q5u6aDNY&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;anatomy-of-authentication-request-response&quot;&gt;&lt;strong&gt;Anatomy of Authentication Request &amp;#x26; Response&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;In this section let’s discuss the structure of authentication request and response, first, let’s start with the authentication request.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*O-kYNgXRlyIgvnZk&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Generally &lt;authnrequest&gt; is a signed message and depended on requirements it is possible to encrypt as well. The following section, you can find short descriptions about each and every attribute and element supported by AuthRequest message.&lt;/authnrequest&gt;&lt;/p&gt;
&lt;h4 id=&quot;attributes&quot;&gt;&lt;strong&gt;Attributes&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;ID&lt;/strong&gt; — This is a mandatory attribute and represents a unique identifier of the current message. The value of this attribute is used as the value of “InResponseTo” attribute of the response message for the purpose of message correlating.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Version&lt;/strong&gt; — A mandatory attribute represents the version of SAML specification, the current value should be “2.0”&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;IssueInstant&lt;/strong&gt; — A mandatory attribute represents, the value should UTC value of the time instance.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Destination&lt;/strong&gt; — An optional attribute that represents the URI reference indicating the address to which this request has been sent.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Consent&lt;/strong&gt; — Indicate whether the consent is obtained from the user in order to send this request message, the following are possible URI values.&lt;/li&gt;
&lt;/ul&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;&lt;em&gt;urn:oasis:names:tc:SAML:2.0:consent:unspecified&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;— No claim as to principal consent is being made&lt;/em&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;2. urn:oasis:names:tc:SAML:2.0:consent:obtained&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;— The consent has been obtained by the issuer.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;3. urn:oasis:names:tc:SAML:2.0:consent:prior&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;— The consent has been obtained by the issuer at some prior point.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;4. urn:oasis:names:tc:SAML:2.0:consent:current-implicit&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;— The consent has been implicitly obtained by the issuer during the action that initiated the message.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;5. urn:oasis:names:tc:SAML:2.0:consent:current-explicit&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;— The consent has been explicitly obtained by the issuer during the action that initiated the message.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;6. urn:oasis:names:tc:SAML:2.0:consent:unavailable&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;— The issuer did not obtain consent.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;7. urn:oasis:names:tc:SAML:2.0:consent:inapplicable&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;— The issuer does not believe that they need to obtain consent&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;ForceAuthn&lt;/strong&gt; — If the value is ‘true’ the IdP should authenticate the user directly rather than rely on a previous security context, the default value is ‘false’.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;IsPassive&lt;/strong&gt; — If the value is ‘true’ then the IdP and the browser itself MUST NOT visibly take control of the user interface from the requester and &lt;strong&gt;interact&lt;/strong&gt; with the user in a noticeable fashion.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;AssertionConsumerServiceURL&lt;/strong&gt; — Specifies by value the location to which the &lt;response&gt; message MUST be returned to the requester.&lt;/response&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;AttributeConsumingServiceIndex&lt;/strong&gt; — Indirectly identifies information associated with the requester describing the SAML attributes the requester desires or requires to be supplied by the identity provider in the &lt;response&gt; message&lt;/response&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;AssertionConsumerServiceIndex&lt;/strong&gt; — Indirectly identifies the location to which the &lt;response&gt; message should be returned to the requester.&lt;/response&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ProtocolBinding&lt;/strong&gt; — A URI reference that identifies a SAML protocol binding to be used when returning the &lt;response&gt; message.&lt;/response&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ProviderName&lt;/strong&gt; — Specifies the human-readable name of the requester for use by the presenter’s user agent or the IdP.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;elements&quot;&gt;Elements&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&quot;saml:Issuer&quot;&gt;saml:Issuer&lt;/a&gt;&lt;/strong&gt; — Identifies the entity that generated the request message.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&quot;ds:Signature&quot;&gt;ds:Signature&lt;/a&gt;&lt;/strong&gt; — An XML Signature that authenticates the requester and provides message integrity.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&quot;saml:Subject&quot;&gt;saml:Subject&lt;/a&gt;&lt;/strong&gt; — Specifies the requested subject of the resulting assertion.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;nameidpolicy&gt;&lt;/nameidpolicy&gt;&lt;/strong&gt; — Specifies constraints on the name identifier to be used to represent the requested subject. If omitted, then any type of identifier supported by the identity provider for the requested subject can be used.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&quot;saml:Conditions&quot;&gt;saml:Conditions&lt;/a&gt;&lt;/strong&gt; — Specifies the SAML conditions the requester expects to limit the validity and/or use of the resulting assertion.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;requestedauthncontext&gt;&lt;/requestedauthncontext&gt;&lt;/strong&gt; — Specifies the requirements, if any, that the requester places on the authentication context that applies to the responding provider’s authentication of the user, I will discuss this matter in a separate post.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Here is the structure of a typical SAML authentication request message.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*j_PYtbHlVLWr6-XG&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Generally, the Response message is a signed message and depended on the requirements it is possible to encrypt the whole message or part of the message as well. In the next section, you can find short descriptions about each and every attribute and element available on AuthRequest message.&lt;/p&gt;
&lt;h4 id=&quot;attributes-1&quot;&gt;&lt;strong&gt;Attributes&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;ID&lt;/strong&gt; — This is a mandatory attribute and represents a unique identifier of the current message.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;InResponseTo&lt;/strong&gt; — The value of the ‘ID’ attribute of the associated &lt;authnrequest&gt; message.&lt;/authnrequest&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Version&lt;/strong&gt; — A mandatory attribute represents the version of SAML specification, the current value should be “2.0”&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;IssueInstant&lt;/strong&gt; — A mandatory attribute represents, the value should UTC value of the time instance.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Destination&lt;/strong&gt; — An optional attribute that represents the URI reference indicating the address to which this request has been sent.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Consent&lt;/strong&gt; — Indicate whether the consent is obtained from the user in order to send this request message, the following are possible URI values.&lt;/li&gt;
&lt;/ul&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;&lt;em&gt;urn:oasis:names:tc:SAML:2.0:consent:unspecified&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;— No claim as to principal consent is being made&lt;/em&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;2. urn:oasis:names:tc:SAML:2.0:consent:obtained&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;— The consent has been obtained by the issuer.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;3. urn:oasis:names:tc:SAML:2.0:consent:prior&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;— The consent has been obtained by the issuer at some prior point.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;4. urn:oasis:names:tc:SAML:2.0:consent:current-implicit&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;— The consent has been implicitly obtained by the issuer during the action that initiated the message.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;5. urn:oasis:names:tc:SAML:2.0:consent:current-explicit&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;— The consent has been explicitly obtained by the issuer during the action that initiated the message.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;6. urn:oasis:names:tc:SAML:2.0:consent:unavailable&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;— The issuer did not obtain consent.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;7. urn:oasis:names:tc:SAML:2.0:consent:inapplicable&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;— The issuer does not believe that they need to obtain consent&lt;/em&gt;&lt;/p&gt;
&lt;h4 id=&quot;elements-1&quot;&gt;&lt;strong&gt;Elements&lt;/strong&gt;&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&quot;saml:Issuer&quot;&gt;saml:Issuer&lt;/a&gt;&lt;/strong&gt; — Identifies the entity that generated the request message.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&quot;ds:Signature&quot;&gt;ds:Signature&lt;/a&gt;&lt;/strong&gt; — An XML Signature that authenticates the requester and provides message integrity.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;status&gt;&lt;/status&gt;&lt;/strong&gt; — A code representing the status of the corresponding request.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&quot;saml:Assertion&quot;&gt;saml:Assertion&lt;/a&gt; OR &lt;a href=&quot;saml:EncryptedAssertion&quot;&gt;saml:EncryptedAssertion&lt;/a&gt;&lt;/strong&gt; — Specifies an assertion by value, or optionally an encrypted assertion by value.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;sp-and-idp-configuration&quot;&gt;&lt;strong&gt;SP and IdP configuration&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Up to now, you have a better understanding about message formats, exact interactions among various roles etc. but in order to make it possible these interactions there should be an understanding between the SP and the IdP about each other, basically each party should know some kind of knowledge about the other party. Generally following configuration details needed to be shared by one party with the other.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Entity Id&lt;/li&gt;
&lt;li&gt;Issuer&lt;/li&gt;
&lt;li&gt;Assertion consumer service URL/ SSO service URL&lt;/li&gt;
&lt;li&gt;Public certificate&lt;/li&gt;
&lt;li&gt;Message level security options such as singing, encryption&lt;/li&gt;
&lt;li&gt;Supported SAML profiles such as SLO, attribute profiles etc.&lt;/li&gt;
&lt;li&gt;Signing and encryption algorithm details&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;There are two widely used options available to provide the above information.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Using a proprietary UI or API&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Provide configuration data related to the other party using a proprietary UI or API provided by the IdP/the SP. As this is not a standard-based approach an identity administrator is supposed to go through the SP/IdP configuration guide to figure out exact procedure, additionally manually proving each and every input value can be error-prone as well.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*s15uUM3zBkazQsW2&quot; alt=&quot;&quot;&gt;
&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*NxuK-VrvhXH1Cek2&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2. Using SAML Metadata&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Provide configuration data related to the other party as a SAML Metadata is the other option, compared to the previous approach this is a more easiest and efficient approach. An identity administrator can download metadata specification from other party and can use with own configuration, this metadata specification consists of all the required configuration data about a SAML entity. Today almost all the IdP vendors and providers are supported for SAML Metadata.&lt;/p&gt;
&lt;p&gt;Following diagram illustrate sample SAML metadata description generated by Salesforce SP.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*Uj7BLA4gQ9kABNES&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Following diagram illustrate sample SAML metadata description generated by WSO2IS IdP.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*KIdeBCt_wMiUZeVN&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;RealyState&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;First, consider the following two practical scenarios,&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The user requests a specific secured page/video/resource at the SP, in order to provide better user experience the SP suppose to return the originally requested page/video/resource back to the user after successful SAML message exchange with the IdP.&lt;/li&gt;
&lt;li&gt;The SP can decide to re-authenticate the user via the IdP at the middle of a transaction, in such cases, it’s required to restore the original transaction context after successful authentication.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In both of the above cases, the SP suppose to persist current state before it contacts the IdP, and it should restore the state after receiving the SAML assertion from the IdP. SAML provides a special parameter called “&lt;strong&gt;RealyState&lt;/strong&gt;” to fulfil this requirement, SP can persist its local state and pass an opaque reference token to the IdP along with SAML authentication request either as a query string parameter or as a HTML has hidden input control deepening on underline SAML Binding. In both cases, the name of the parameter/HTML control should be &lt;strong&gt;RealyState&lt;/strong&gt;. Once the IdP receives this &lt;strong&gt;RealyState&lt;/strong&gt; it must return this original value back to the SP along with SAML response.&lt;/p&gt;
&lt;h4 id=&quot;other-posts-in-thisseries&quot;&gt;Other posts in this series&lt;/h4&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/do-you-really-need-saml&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Reloading SAML: Do you really need SAML?&lt;/strong&gt;&lt;br&gt;
_Recently I have been working closely and directly on Identity and Access Management (IAM) domain, which also raised a…_sagarag.medium.com&lt;/a&gt;&lt;a href=&quot;https://sagarag.dev/posts/do-you-really-need-saml&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/saml-basics&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Reloading SAML : SAML Basics&lt;/strong&gt;&lt;br&gt;
_During the last post, I discussed some of the practical use cases of SAML, within this post I will try to discuss a few…_sagarag.medium.com&lt;/a&gt;&lt;a href=&quot;https://sagarag.dev/posts/saml-basics&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/why-do-you-need-metadata&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Reloading SAML: Why do you need SAML Metadata?&lt;/strong&gt;&lt;br&gt;
_As we previously discussed, SAML is a structured format to define security information (assertions) about a subject…_sagarag.medium.com&lt;/a&gt;&lt;a href=&quot;https://sagarag.dev/posts/why-do-you-need-metadata&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/saml-idp-discovery&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Reloading SAML : IdP Discovery&lt;/strong&gt;&lt;br&gt;
_This post is somewhat different from other posts of this series, majority of the concepts that we are discussing here…_sagarag.medium.com&lt;/a&gt;&lt;a href=&quot;https://sagarag.dev/posts/saml-idp-discovery&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;/a&gt;&lt;/p&gt;</content:encoded><dc:creator>Sagara Gunathunga</dc:creator><category>SAML</category></item><item><title>SAML IdP Discovery: How Service Providers Find the Right IdP</title><link>https://sagarag.dev/posts/saml-idp-discovery</link><guid isPermaLink="true">https://sagarag.dev/posts/saml-idp-discovery</guid><description>How a SAML service provider finds a user&apos;s identity provider: common domain cookie, identifier-first login, discovery services, and the OASIS discovery profiles.</description><pubDate>Sat, 12 May 2018 16:38:02 GMT</pubDate><content:encoded>&lt;p&gt;This post is somewhat different from other posts of this series, majority of the concepts that we are discussing here are not only specific to SAML, those can be used with some other protocols as well, additionally, some of the real-world examples used here to describe some general concepts are not related to SAML as well but I used them because they are the best suite to illustrate those concepts.&lt;/p&gt;
&lt;p&gt;As the tradition we used throughout this series, let’s try to understand why we need IdP discovery in the first place. Assume you have the following deployment in a place where only one IdP in the system.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*8yRzRP1AQj-W9DiR.&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;In above deployment all the SPs are aware of the location and the configuration details of the IdP based on metadata(SAML IdP Metadata) or some other mean, now whenever a user trying to login to a SP, the SP simply redirect the user to the IdP along with a SAML request, in this case, all the users are redirected to a single IdP.&lt;/p&gt;
&lt;p&gt;Now let’s look at following deployment with 3 IdPs.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*6R4UFwr7-J75Ez2x.&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;In this example, all the customers belong to a business are managed by an IdP called &lt;strong&gt;public.idp.com,&lt;/strong&gt; employees of the business are managed by an IdP called &lt;strong&gt;internal.idp.com&lt;/strong&gt; and the partners of the business are managed by &lt;strong&gt;partner.idp.com&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;In above case whenever a user tries to login, the SP should determine the corresponding IdP among three so that the user will be redirected to the correct IdP, otherwise the user can’t be logged in to the application. As an example when a customer tries to log in, the customer needs to be redirected to &lt;strong&gt;public.idp.com&lt;/strong&gt; IdP while when a partner tries to login, the partner needs to be redirected to the &lt;strong&gt;partner.idp.com&lt;/strong&gt; Idp and so on.&lt;/p&gt;
&lt;h4 id=&quot;when-multiple-idps-exist-within-a-system-the-process-of-finding-the-correct-idp-corresponding-to-a-specific-user-is-known-as-idp-discovery&quot;&gt;&lt;strong&gt;When multiple IdPs exist within a system, the process of finding the correct IdP corresponding to a specific user is known as IdP discovery.&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;At this point, you have an idea about the concept of IdP discovery and also its practical necessity. However due to the same example, one can easily come to a conclusion that IdP discovery is a responsibility of the SP, but that is not always correct, other than SP there are some other options available for IdP discovery to take place. Since I’m not aware of any standard name, I called this as &lt;strong&gt;IdP discovery topologies&lt;/strong&gt;, in the next section we will look at each of these options.&lt;/p&gt;
&lt;h3 id=&quot;idp-discovery-topologies&quot;&gt;IdP Discovery Topologies&lt;/h3&gt;
&lt;h4 id=&quot;1-idp-discovery-at-thesp&quot;&gt;&lt;strong&gt;1. IdP discovery at the SP&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*5gn-1zRm72iTXn3R.&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;In this approach, the IdP discovery process takes place at the SP level, either SP by its own make the IdP selection or get user’s involvement for the IdP selection.&lt;/p&gt;
&lt;h4 id=&quot;2-delegated-idp-discovery-at-thesp&quot;&gt;&lt;strong&gt;2. Delegated IdP discovery at the SP&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*NFR3ikDqDwfrzDFF.&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;In this approach, SP simply delegates IdP discovery task to a 3rd party service where this 3rd party service makes the IdP selection by its own or with help from the user.&lt;/p&gt;
&lt;h4 id=&quot;3-idp-discovery-at-the-proxy--or-a-middleware&quot;&gt;&lt;strong&gt;3. IdP discovery at the proxy ( or a middleware)&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*gq-zM7TOKFlijEEm.&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;In this approach, SP simply forward SAML request to a proxy service where the proxy service has the knowledge to make the IdP selection and SP is not aware of the selected IdP. However, it is very hard to put this pattern into practice due to a number of practical limitations.&lt;/p&gt;
&lt;p&gt;The above classification is based on the topology of the components and considering at which point it performs the IdP discovery. We can come up with another classification based on who is responsible or who has better knowledge to determine the correct IdP from the available list of IdPs.&lt;/p&gt;
&lt;h3 id=&quot;idp-discovery-option-based-on-responsible-actor&quot;&gt;&lt;strong&gt;IdP discovery option based on responsible actor&lt;/strong&gt;&lt;/h3&gt;
&lt;h4 id=&quot;1-the-user-knows-the-correctidp&quot;&gt;&lt;strong&gt;1. The user knows the correct IdP&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;In this approach, an individual who is trying to login can make a better choice on correct IdP selection once the SP prompt him a list of IdPs.&lt;/p&gt;
&lt;p&gt;In practical use cases, an individual can have multiple accounts in multiple IdPs or can have a single account in one Idp, this behaviour varies from one use case to another.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example — 1&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*ZSRGPI_qk_9YVnVP.&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;In e-ID schema used in France called &lt;a href=&quot;https://app.franceconnect.gouv.fr&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;FranceConnect&lt;/a&gt;, a user need to pick his/her Identity provider first then the system redirects the user into that IdP, in this case, the user makes the IdP selection.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example -2&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*sy1gD7OFPq05mUkA.&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;In this example SP facilitates users to login via social networks, in contrast to the previous example here it’s valid for someone to have accounts with a number of social networks, in such cases one can login to SP via Facebook today and try to login to the SP via Twitter tomorrow.&lt;/p&gt;
&lt;p&gt;This use case is much complex than the previous one because one individual can be associated with multiple social networks but there is no option for social network themselves to make this association, in other words, there is no relationship between my Facebook identity and my Twitter identity then it’s a SP’s responsibility to associate these accounts into a single identity at the SP level. Without that support, one can get two identities when login to the SP via Facebook and Twitter.&lt;/p&gt;
&lt;h4 id=&quot;2-sp-knows-the-correctidp&quot;&gt;&lt;strong&gt;2. SP knows the correct IdP&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;In this case, SP can determine the correct IdP itself by evaluating the available context details of the user or asking some questions from the user, according to the behaviour of the user it is possible to break this approach into two.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Passive User&lt;/strong&gt; — In this case, SP determines the correct IdP by evaluating the context details available to the SP at the time of user accessing the SP, additionally most of the cases IdP discovery process is transparent to users. Following are some of the examples for such context details helpful to make IdP selection.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Request URL&lt;/strong&gt; — Inputs for IdP selection can be encoded in the request URL such as tenant domain for the user etc. As an example “HelloWorld” section of this &lt;a href=&quot;https://helloworld.my.salesforce.com/&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;https://helloworld.my.salesforce.com/&lt;/a&gt; URL is used by Salesforce to identify the tenant of the user and also to determine correct IdP for the user.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Using a shared cookie&lt;/strong&gt; — Deployments where a common domain exists between the IdPs and SP, it is possible to use a common cookie to determine the correct IdP by the SP.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Using the previous session&lt;/strong&gt; — SP can determine the existing user session from the previous log-in or based on cookie data created during the previous session.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;IP Address/Ranges&lt;/strong&gt; — In deployments where a mapping among IP ranges and IdPs exists, it is possible for SP to determine the correct IdP by evaluating the IP address of the access request.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Active User&lt;/strong&gt; — In this case, the user actively participates to the IdP discovery process by providing inputs to the SP. Identity first login used by Google is one of the best examples for this where Google 1st ask for username only then after evaluating the provided username it determines and redirects the user to the correct IdP. Another approach is to provide a list of options such as list of departments or list of countries so that based on the user’s selection SP can determine the correct IdP.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;IdP Discovery based on common domain cookie (CDC)&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*3GTIBQkfUOTrYcnc.&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;In this approach, SP identifies the correct IdP using a browser cookie that is previously set by the IdP. According to HTTP specification cookies are bound with a specific domain, which means in order to have a common cookie between the SP and the IdP, there should be a common domain between the SP and the IdP otherwise this approach won’t work. In the above diagram, &lt;em&gt;example.com&lt;/em&gt; is common for both &lt;em&gt;hr.example.com&lt;/em&gt; and &lt;em&gt;idp.example.com&lt;/em&gt;, hence any cookie set to &lt;em&gt;example.com&lt;/em&gt; can be common for both domains.&lt;/p&gt;
&lt;p&gt;Typical IdP discovery processing based on common domain cookie (CDC) consists of following steps.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;IdP consists of a component that can write a cookie in a common domain, we can call this component as CDC Writer. After a successful user login IdP write this CDC cookie with a unique IdP identifier that can be understood by the SP.&lt;/li&gt;
&lt;li&gt;SP consists of a component that can read the common cookie set by the IdP, we can call this component as CDC Reader. When a user tries to login back to the same SP or another SP which fulfil the common domain requirement, SP check for the existence of CDC cookie, if it exists it tries to identify the correct IdP based on the IdP identifier encoded within the cookie.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;In practice, you can use any custom cookie with custom convention or you can use a profile called &lt;strong&gt;SAML2 Identity Provider Discovery Profile&lt;/strong&gt; defined in section 4.3 of the &lt;a href=&quot;https://www.oasis-open.org/committees/download.php/35389/sstc-saml-profiles-errata-2.0-wd-06-diff.pdf&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;SAML Profiles specification&lt;/strong&gt;&lt;/a&gt;, at the later stage of this post we will discuss SAML2 IdP discovery profile in detail.&lt;/p&gt;
&lt;p&gt;Due to the hard requirement to have a common domain between SP and IdP this approach is not quite popular in the industry.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;IdP Discovery based on the user identifier&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*VK_HClOAyGnNq9m8.&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;If you are a GMail user for some time probably you may have noticed the following change they have done in login experience a few years back.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*p0eqPXV5e6aWQ4u--j6uPQ.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Previously, you had to provide both username and password at once, but now GMail asks you your identity first, then depend on the identifier they will redirect you to correct IdP for authentication. As an example, if you use &lt;a href=&quot;mailto:yourname@gmail.com&quot;&gt;yourname@gmail.com&lt;/a&gt; Google identifies this identity is associated its own IdP hence proceed further authentication by asking the password, if you use &lt;a href=&quot;mailto:yourname@youtcompany.com&quot;&gt;yourname@yourcompany.com&lt;/a&gt; as the identifier, it identifies &lt;em&gt;yourcompany.com&lt;/em&gt; as the domain and redirect to the IdP belong to &lt;em&gt;yourcompany.com&lt;/em&gt; organization.&lt;/p&gt;
&lt;p&gt;Above pattern is known as &lt;strong&gt;Identity-first login&lt;/strong&gt;, SP also can use the same approach to determine the correct IdP for a user trying to login. SP can first ask for the identifier of the user and based on that can determine the correct IdP.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;IdP Discovery based on user inputs&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*IeLOQIIAf45jAbMz.&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Above diagram is from Swedish eIDAS demo portal where it facilitates cross-border digital authentications for Europe citizens, if we consider this portal as a SP then it prompts a list of countries so that the user can pick the correct country where his/her e-ID is established.&lt;/p&gt;
&lt;p&gt;Typically a citizen can have e-ID only within single country hence once he selects a specific country ( a IdP) there is a high chance that he/she will pick the same country over again, in such cases SP can locally store the user selection so that the SP provide much better user experience whenever he/she returns next time.&lt;/p&gt;
&lt;h4 id=&quot;3-independent-discovery-service-knows-the-correctidp&quot;&gt;&lt;strong&gt;3. Independent Discovery Service knows the correct IdP&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;In this approach when a user is trying to login, the SP simply redirect the user to a separately deployed discovery service with the required information, then this discovery service is responsible for correct IdP selection. Once the discovery service comes to a conclusion about IdP selection it returns back to the SP with discovery results so that SP can redirect the user to the correct IdP.&lt;/p&gt;
&lt;p&gt;Following diagram illustrate one such implementation based on a cookie, unlike the previously discussed CDC cookie-based approach here we don’t need to have a common domain between the SP and the IdP.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*clSqaWxLRWeeD2K_.&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;This approach consists of the following procedure.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;After successful user authentication, the user is redirected to the separately deployed discovery service with the IdP identification details.&lt;/li&gt;
&lt;li&gt;The discovery service set a cookie with IdP identification details.&lt;/li&gt;
&lt;li&gt;When a user is trying to login, SP redirects the user to the discovery service.&lt;/li&gt;
&lt;li&gt;The discovery service looks for a previously created cookie if found it read IdP identification details from the cookie.&lt;/li&gt;
&lt;li&gt;The discovery service returns back to the SP with identified IdP details so that SP can redirect the user to the correct IdP for authentication.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;When it comes to implementation, you can come up with your own custom cookie and custom discovery service or you can follow the specification called &lt;a href=&quot;http://docs.oasis-open.org/security/saml/Post2.0/sstc-saml-idp-discovery.pdf&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;SAML2 Identity Provider Discovery protocol and Profile&lt;/strong&gt;&lt;/a&gt; which provides standard semantics for this approach, we will discuss this specification at the end of this post.&lt;/p&gt;
&lt;h4 id=&quot;4-proxy-knows-the-correctidp&quot;&gt;&lt;strong&gt;4. Proxy knows the correct IdP&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*Xr6Ter7ENydCi9b1.&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;In this approach, SP simply sends the authentication request (SAML request) to a proxy service where the proxy service is responsible to figure out the correct IdP and forward the request messages. Old &lt;a href=&quot;https://wiki.shibboleth.net/confluence/display/EDS10/Embedded+Discovery+Service&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;WAYF&lt;/a&gt; ( Where Are You From) model used in Shibboleth is a good example of this approach but this is no longer a popular option and we are not going to discuss much this approach.&lt;/p&gt;
&lt;h4 id=&quot;saml2-identity-provider-discovery-profile&quot;&gt;&lt;strong&gt;SAML2 Identity Provider Discovery Profile&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Section 4.3 of the &lt;a href=&quot;https://www.oasis-open.org/committees/download.php/35389/sstc-saml-profiles-errata-2.0-wd-06-diff.pdf&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Profiles for SAML 2.0 specification&lt;/a&gt; define a profile called “&lt;strong&gt;Identity Provider Discovery&lt;/strong&gt;” which can be used to identify a correct IdP for a user by a SP and based on common cookie between the IdP and SP.&lt;/p&gt;
&lt;p&gt;In a previous section of this post ( IdP Discovery based on common domain cookie ) we already discussed the generic architecture for this common cookie-based discovery approach. I have given the following diagram again to recall the generic architecture.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*-iruuglt9VqQ9sAs.&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Identity Provider Discovery profile tries to standardize this approach as a SAML specification, I have discussed most of the important points below.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The objective of this profile is, facilitate SP to discover a correct IdP that the particular user is associated.&lt;/li&gt;
&lt;li&gt;This discovery profile can be used with web browser-based SSO, in other words this discovery profile assume the presence of a web browser as the user agent.&lt;/li&gt;
&lt;li&gt;In this profile, it’s mandatory to have a common domain between SP and IdP because without such common domain there is not any other approach to share a common cookie between the SP and the IdP.&lt;/li&gt;
&lt;li&gt;The cookie used in this profile called Common Domain Cookie (CDC) and it should use the following semantics.&lt;/li&gt;
&lt;li&gt;IdP should be able to write this cookie in the common domain after successful user authentication. If the cookie is already present IdP should append it’s a unique identifier to the IdP list within the cookie.&lt;/li&gt;
&lt;li&gt;SP should able to read and process this cookie to identify the correct IdP associated with the user.&lt;/li&gt;
&lt;li&gt;CDC name must be “&lt;strong&gt;_saml_idp&lt;/strong&gt;”&lt;/li&gt;
&lt;li&gt;CDC can have one or more base-64 encoded URI values separated by a single space character, each URI should uniquely represent an IdP.&lt;/li&gt;
&lt;li&gt;CDC’s path prefix should be “&lt;strong&gt;/&lt;/strong&gt;”&lt;/li&gt;
&lt;li&gt;CDC’s domain should set to the common domain.&lt;/li&gt;
&lt;li&gt;CDC must be marked as &lt;strong&gt;secure&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;CDC can be &lt;strong&gt;season-only&lt;/strong&gt; or &lt;strong&gt;persistent&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;This profile does not define any standard approach to write the CDC by the IdP and read by the SP, usually, both can be achieved by redirecting within the same domain.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;However, the requirement to have a common domain between the SP and the IdP has reduced the usability of this profile, SAML2 Identity Provider Discovery protocol and Profile that we will look at in next section is more flexible than this profile.&lt;/p&gt;
&lt;h4 id=&quot;saml2-identity-provider-discovery-protocol-andprofile&quot;&gt;&lt;strong&gt;SAML2 Identity Provider Discovery protocol and Profile&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Although there are similarities in names and purposes this profile is entirely different from the SAML2 Identity Provider Discovery Profile defined in section 4.3 of the profiles of SAML2 specification, &lt;a href=&quot;http://docs.oasis-open.org/security/saml/Post2.0/sstc-saml-idp-discovery.pdf&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;this profile&lt;/a&gt; is produced as a separate specification in 2008.&lt;/p&gt;
&lt;p&gt;For the simplicity of our discussion, I will call this current profile as Discovery Protocol while previously discussed approach CDC Discovery profile. First, let’s look at some of the differences between these two approaches.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;CDC Discovery profile assumes only two roles: IdP and SP but in contrast to that discovery, profile assumes three roles as IdP, SP and centralized Discovery Service.&lt;/li&gt;
&lt;li&gt;In CDC Discovery profile it’s mandatory to have a common domain between SP and IdP but in discovery protocol, there is no such requirement, due to this discovery protocol is much flexible.&lt;/li&gt;
&lt;li&gt;CDC discovery profile is based on the cookie but discovery protocol does not mandate the use of cookie instead discovery service can choose suitable approach ( BTW cookie can be used as well)&lt;/li&gt;
&lt;li&gt;Wire-protocol used in discovery protocol is dependent on browser redirects.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Like is previous profile the main objective of this profile is also to facilitate SP to discover a correct IdP that a particular user is associated. This discovery profile can be used with web browser-based SSO, in other words this discovery profile also assumes the presence of a web browser as the user agent.&lt;/p&gt;
&lt;p&gt;Following diagram describe the interactions between the players of this profile.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*KTjR_SY7fKk9-3CQ.&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step 1 : Request to discovery service from the SP&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;SP redirects the user to the discovery service with &lt;strong&gt;HTTP GET&lt;/strong&gt; request.&lt;/li&gt;
&lt;li&gt;Parameters required for the discovery service are attached as URL-encoded query strings to the above GET request. These are the possible parameters …&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;entityID&lt;/strong&gt; (mandatory parameter ) — unique identifier of the SP.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;return&lt;/strong&gt; — A URL with a possible query string value, once the discovery process is completed discovery service will redirect the user to this location.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;returnIDParam&lt;/strong&gt; — A parameter name used to return the unique identifier of the selected IdP to the SP. If this parameter is omitted, it defaults value is “&lt;strong&gt;entityID&lt;/strong&gt;”&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;IsPassive&lt;/strong&gt; — indicate whether the discovery service is allowed to interact with the user or not, the default value is false.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Step 2 : Discovery service determine the correct IdP&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;In this step discovery service determine the correct IdP associated with the SP, depending on the value of &lt;strong&gt;IsPassive&lt;/strong&gt; parameter discovery service may directly interact with the user or not.&lt;/p&gt;
&lt;p&gt;In case if the discovery service uses a single cookie to determine the correct IdP, the cookie name must be “&lt;strong&gt;_saml_idp&lt;/strong&gt;”.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step 3 : Discovery service send back user to the SP with discovery results&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;During this step, the discovery service sends back the user to the SP via the URL specified in the &lt;strong&gt;return&lt;/strong&gt; parameter and the URI of the selected IdP is set as the value of the &lt;strong&gt;entityID&lt;/strong&gt; query parameter, note that if &lt;strong&gt;returnIDParam&lt;/strong&gt; is present the discovery service use that value instead of entityID for the query parameter name.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt; : to improve security measures especially against phishing attacks, it is encouraged to use SAML Metadata to specify the return URL instead of sending via the the browser (via &lt;strong&gt;return&lt;/strong&gt; parameter). In case both the metadata and is r&lt;strong&gt;eturn&lt;/strong&gt; parameter is present, the discovery service should use the URL specified in the metadata.&lt;/p&gt;
&lt;p&gt;It is possible to use &lt;strong&gt;&lt;a href=&quot;idpdisc:DiscoveryResponse&quot;&gt;idpdisc:DiscoveryResponse&lt;/a&gt;&lt;/strong&gt; element to specify the return URL under the &lt;strong&gt;&lt;a href=&quot;md:SPSSODescriptor&quot;&gt;md:SPSSODescriptor&lt;/a&gt;&lt;/strong&gt; element.&lt;/p&gt;
&lt;p&gt;I hope this post helpful to understand the concept of IdP discovery and available technical approaches to achieve IdP discovery, this also helps to get a clear idea about IdP discovery profiles defined in SAML2 specifications.&lt;/p&gt;
&lt;h4 id=&quot;other-posts-in-thisseries&quot;&gt;Other posts in this series&lt;/h4&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/do-you-really-need-saml&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Reloading SAML: Do you really need SAML?&lt;/strong&gt;&lt;br&gt;
_Recently I have been working closely and directly on Identity and Access Management (IAM) domain, which also raised a…_sagarag.medium.com&lt;/a&gt;&lt;a href=&quot;https://sagarag.dev/posts/do-you-really-need-saml&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/saml-basics&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Reloading SAML : SAML Basics&lt;/strong&gt;&lt;br&gt;
_During the last post, I discussed some of the practical use cases of SAML, within this post I will try to discuss a few…_sagarag.medium.com&lt;/a&gt;&lt;a href=&quot;https://sagarag.dev/posts/saml-basics&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/why-do-you-need-metadata&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Reloading SAML: Why do you need SAML Metadata?&lt;/strong&gt;&lt;br&gt;
_As we previously discussed, SAML is a structured format to define security information (assertions) about a subject…_sagarag.medium.com&lt;/a&gt;&lt;a href=&quot;https://sagarag.dev/posts/why-do-you-need-metadata&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;/a&gt;&lt;/p&gt;</content:encoded><dc:creator>Sagara Gunathunga</dc:creator><category>SAML</category></item><item><title>SAML Metadata Explained: EntityID, SP and IdP Descriptors</title><link>https://sagarag.dev/posts/why-do-you-need-metadata</link><guid isPermaLink="true">https://sagarag.dev/posts/why-do-you-need-metadata</guid><description>Why SAML 2.0 needs metadata: entityID, EntityDescriptor, IdP and SP role descriptors, signing keys, and static vs dynamic metadata exchange between partners.</description><pubDate>Sun, 01 Apr 2018 07:51:56 GMT</pubDate><content:encoded>&lt;p&gt;As we &lt;a href=&quot;https://sagarag.dev/posts/saml-basics&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;previously&lt;/a&gt; discussed, SAML is a structured format to define security information (assertions) about a subject (usually about an individual) by an authorized authority called asserting party; however, there is no point to generate a SAML assertion and keep it itself by the asserting party, instead generated SAML assertions need to be shared with another party so that this other party can use this SAML assertion, technically we call this other party as relying party.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*iZJIxIdR21NTgWwy.&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;As we discussed, SAML assertions are only useful when they transmit from one party to another usually over a network connection. By the way, SAML does not define its own transport mechanism, instead, SAML utilize existing Internet protocols such as HTTP, SOAP etc. these transport semantics are known as SAML Bindings and we have discussed SAML Bindings during our previous &lt;a href=&quot;https://sagarag.dev/posts/saml-basics&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;post&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In real-world, in order to communicate between two parties, there should be a prior agreement between these two parties, this is a valid requirement for communication between SAML asserting party and SAML relying on the party as well. To generate and transmit a SAML assertion by a particular SAML entity it should know the following information about the other party.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The unique identifier of the other party, &lt;strong&gt;in SAML jargons this is called as “entityID”.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;The role of the other party, for example in Web Browser SSO profile &lt;authrequest&gt; message need to send to a party which can play a “SSO IdP” role.&lt;/authrequest&gt;&lt;/li&gt;
&lt;li&gt;Whether the other party expect confidentiality during the message transmission? if that is the case generated SAML assertions need to be encrypted before the transmission, also the first party should know the encryption algorithms and other cryptographic policies supported by the other party.&lt;/li&gt;
&lt;li&gt;Whether the other party expect message integrity and proof of origin for SAML messages? if that is the case generated SAML assertions need to be digitally signed before the transmission, also the first party should know the signing algorithms and other cryptographic policies supported by the other party.&lt;/li&gt;
&lt;li&gt;Also for both message encryption and signing each party should have a valid public key certificate of the other party.&lt;/li&gt;
&lt;li&gt;Supported transport and messaging semantics of the other party, in SAML jargons this is called supported bindings, an example whether the other party support bindings such as HTTP-GET, HTTP-POST, HTTP POST etc.&lt;/li&gt;
&lt;li&gt;Network locations or endpoint address to establish network connections and transmit messages.&lt;/li&gt;
&lt;li&gt;SAML attribute profiles supported by the other party.&lt;/li&gt;
&lt;li&gt;Indication of the validity of the above data to determine whether that information are outdated or not.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Now let’s move to the main question of this post,&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;how one party describe above information and make them available for the other party ?&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;We can find two possible answers for the above question&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Use human language to describe all of this information so that a human being can read &amp;#x26; understand this manual and then configure/program systems accordingly. Theoretically, this should work but practically this caused lot of problems, some of the disadvantages are machines can not understand these manuals and there is no standard format.&lt;/li&gt;
&lt;li&gt;Use structured and machine-readable format, this approach solves both of the disadvantages related to the previous approach.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Note&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;:&lt;/em&gt; &lt;a href=&quot;https://docs.wso2.com/display/IS550/Configuring+SAML2+Web+Single-Sign-On#ConfiguringSAML2WebSingle-Sign-On-Manualconfiguration&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;em&gt;Following page&lt;/em&gt;&lt;/a&gt;&lt;em&gt;, which contains detailed instructions about how to configure SAML SP in&lt;/em&gt; &lt;a href=&quot;https://wso2.com/identity-and-access-management&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;em&gt;WSO2 IS&lt;/em&gt;&lt;/a&gt; &lt;em&gt;is an example for the above 1st approach.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.oasis-open.org/committees/download.php/35391/sstc-saml-metadata-errata-2.0-wd-04-diff.pdf&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Metadata for SAML V2.0 specification&lt;/a&gt; defines &lt;a href=&quot;http://docs.oasis-open.org/security/saml/v2.0/saml-schema-metadata-2.0.xsd&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;XMLSchema based&lt;/a&gt; such machine-readable format to describe capabilities and expectations of a SAML actor. This post tries to introduce and discuss core concepts related to SAML Metadata specification.&lt;/p&gt;
&lt;h3 id=&quot;unique-identification-of-samlentity&quot;&gt;&lt;strong&gt;Unique identification of SAML Entity&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Each of the entity (SP, IdP etc.) that participates in SAML protocol should have a unique identifier, this identifier should be a URI with maximum 1024 characters. According to Metadata specification this identifier is represented as an attribute called “&lt;strong&gt;entityID&lt;/strong&gt;” within &lt;strong&gt;&lt;entitydescriptor&gt;&lt;/entitydescriptor&gt;&lt;/strong&gt; or &lt;strong&gt;&lt;entitiesdescriptor&gt;&lt;/entitiesdescriptor&gt;&lt;/strong&gt; elements.&lt;/p&gt;
&lt;p&gt;Also any valid Metadata definition should start with either &lt;strong&gt;&lt;entitydescriptor&gt;&lt;/entitydescriptor&gt;&lt;/strong&gt; or &lt;strong&gt;&lt;entitiesdescriptor&gt;&lt;/entitiesdescriptor&gt;&lt;/strong&gt; elements. &lt;strong&gt;&lt;entitydescriptor&gt;&lt;/entitydescriptor&gt;&lt;/strong&gt; used to describes a single deployment of SAML entity and &lt;strong&gt;&lt;entitiesdescriptor&gt;&lt;/entitiesdescriptor&gt;&lt;/strong&gt; used to describes a group of SAML deployments.&lt;/p&gt;
&lt;h3 id=&quot;anatomy-of-saml-metadata-definition&quot;&gt;Anatomy of SAML Metadata Definition&lt;/h3&gt;
&lt;p&gt;Following diagram illustrates the typical high-level elements of SAML Metadata Definition.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*7Ex3jEooe6c-_vbIKEt2NA.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;EntityDescriptor&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;As discussed &lt;strong&gt;&lt;entitydescriptor&gt;&lt;/entitydescriptor&gt;&lt;/strong&gt; element is the root element of a SAML metadata definition and denote a SAML entity such as SAML SP, SAML IdP . &lt;strong&gt;&lt;entitydescriptor&gt;&lt;/entitydescriptor&gt;&lt;/strong&gt; element can contain following attributes.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;entityID&lt;/strong&gt; [Required] — the unique identifier of the SAML entity which is described by this definition.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ID&lt;/strong&gt; [Optional] — a document-unique identifier for the element, typically used as a reference point when signing.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;validUntil&lt;/strong&gt; [Optional] — The expiration time of the metadata&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;cacheDuration&lt;/strong&gt; [Optional] — the maximum length of time a consumer should cache the metadata.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&quot;ds:Signature&quot;&gt;ds:Signature&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Used to include a digital signature that can be used to sign various elements in a metadata definition.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;extensions&gt;&lt;/extensions&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Used to include metadata extensions that are agreed upon between a metadata publisher and the consumer, we will discuss actual usage of this element in a later section of this post.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;organization&gt;&lt;/organization&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The optional element which can be used to identifying the organization responsible for the SAML entity, it possible to include details such as organization’s name, display name, URL.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;contactperson&gt;&lt;/contactperson&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This element can be used to provide various kind of information about a contact person such as individuals’ name, email address and phone numbers etc.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;additionalmetadatalocation&gt;&lt;/additionalmetadatalocation&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This element can be used to provide a set of locations where additional metadata exists for the current SAML entity.&lt;/p&gt;
&lt;h3 id=&quot;role-descriptors&quot;&gt;&lt;strong&gt;Role Descriptors&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;This is one of the very important members of a SAML metadata definition and used to describe the role or capabilities of the SAML entity. As shown in the following diagram SAML Metadata specification define a set of SAML roles, additionally it also facilitates to derive new SAML roles as needed.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*AA_VyGKhiQqi0_oa.&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;In a later section of this post, we’ll look at a few important roles with details, hence following section limit to provide a very brief introduction about each of the role.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;idpssodescriptor&gt;&lt;/idpssodescriptor&gt;&lt;/strong&gt; — Used to describe identity providers(IdP) supporting SSO.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;spssodescriptor&gt;&lt;/spssodescriptor&gt;&lt;/strong&gt; — Used to describe service providers(SP) supporting SSO.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;authnauthoritydescriptor&gt;&lt;/authnauthoritydescriptor&gt;&lt;/strong&gt; — Used to describe SAML authentication authorities or in an other words SAML entities that can respond to &lt;a href=&quot;samlp:AuthnQuery&quot;&gt;samlp:AuthnQuery&lt;/a&gt; requests.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;attributeauthoritydescriptor&gt;&lt;/attributeauthoritydescriptor&gt;&lt;/strong&gt; — Used to describe SAML attribute authorities or in an other words SAML entities that can respond to &lt;a href=&quot;samlp:AttributeQuery&quot;&gt;samlp:AttributeQuery&lt;/a&gt; requests.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;pdpdescriptor&gt;&lt;/pdpdescriptor&gt;&lt;/strong&gt; — Used to describe XACML policy decision points support for XACML SAML Profile.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;affiliationdescriptor&gt;&lt;/affiliationdescriptor&gt;&lt;/strong&gt; — This role is somewhat different from other roles, instead of describing its own roles this element is used to define an affiliation among SAML entities.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It’s also possible to use one SAML metadata definition to describe a number of SAML entities, in such cases &lt;strong&gt;&lt;entitiesdescriptor&gt;&lt;/entitiesdescriptor&gt;&lt;/strong&gt; element is used as the root element instead of &lt;strong&gt;&lt;entitydescriptor&gt;&lt;/entitydescriptor&gt;&lt;/strong&gt; element. &lt;strong&gt;&lt;entitiesdescriptor&gt;&lt;/entitiesdescriptor&gt;&lt;/strong&gt; element can contain collection of &lt;strong&gt;&lt;entitydescriptor&gt;&lt;/entitydescriptor&gt;&lt;/strong&gt; elements or collection of &lt;strong&gt;&lt;entitiesdescriptor&gt;&lt;/entitiesdescriptor&gt;&lt;/strong&gt; elements**.**&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*bC-VgeLf1FIF6P0oikiUog.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;So far we have discussed a lot of details related to SAML specification, from now onward I will change the style of the post and try to move forward with more examples/practical oriented approach.&lt;/p&gt;
&lt;p&gt;During the &lt;a href=&quot;https://sagarag.dev/posts/saml-basics&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;previous post&lt;/a&gt; we looked at the role of SAML as a SSO implementation technology, in an any usual SSO scenario we can identify two distinct roles as Identity Provider (IdP) who act as the SAML asserting party and Service Provider (SP) who act as the relying party, in next two sections we will look at how SAML metadata can be used to describe IdP and a SP.&lt;/p&gt;
&lt;h3 id=&quot;how-to-describe-saml-sso-supported-idp&quot;&gt;&lt;strong&gt;How to describe SAML SSO supported IdP&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Here is a real-world SAML metadata definition which describes a deployment of WSO2 IS that act as SAML SSO provider.&lt;/p&gt;
&lt;p&gt;We already discussed about &lt;entitydescriptor&gt; and &lt;idpssodescriptor&gt; in the previous section, but in above example &lt;idpssodescriptor&gt; elements contains number of child elements that we haven’t discusse yet, following diagram shows all the possible sub-elements supported by &lt;idpssodescriptor&gt; element.&lt;/idpssodescriptor&gt;&lt;/idpssodescriptor&gt;&lt;/idpssodescriptor&gt;&lt;/entitydescriptor&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*qTC3hgY2a_ztNAeW.&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Additionally &lt;idpssodescriptor&gt; support “&lt;strong&gt;&lt;em&gt;WantAuthnRequestsSigned&lt;/em&gt;&lt;/strong&gt;” attribute as well.&lt;/idpssodescriptor&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;keydescriptor&gt; Element&lt;/keydescriptor&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This element provides information about the cryptographic keys that an entity uses to sign data or receive encrypted keys, along with additional cryptographic details. &lt;keydescriptor&gt; element also support for an attribute called &lt;strong&gt;&lt;em&gt;“use”&lt;/em&gt;&lt;/strong&gt; which can be used to specify the purpose of the key being described and possible values are &lt;strong&gt;&lt;em&gt;“encryption”&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;“signing”&lt;/em&gt;&lt;/strong&gt;.&lt;/keydescriptor&gt;&lt;/p&gt;
&lt;p&gt;Additionally &lt;keydescriptor&gt; element support following sub-elements as well.&lt;/keydescriptor&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&quot;ds:KeyInfo&quot;&gt;ds:KeyInfo&lt;/a&gt;&lt;/strong&gt; element that directly or indirectly identifies a key&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;encryptionmethod&gt;&lt;/encryptionmethod&gt;&lt;/strong&gt; specifying an algorithm and algorithm-specific settings supported by the entity.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In the above example, it included a X509 certificate which is used for signing. I internally skip discussing other elements at this point and when we discuss each profile (which map with each practical use of SAML) I will describe how each of this element is related to each profile.&lt;/p&gt;
&lt;h3 id=&quot;how-to-describe-saml-sso-supported-sp&quot;&gt;&lt;strong&gt;How to describe SAML SSO supported SP&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Like in the previous section, let’s start with the following example which describes Salesforce as a SAML service provider and downloaded from Salesforce SSO settings page.&lt;/p&gt;
&lt;p&gt;Following diagram shows all the possible sub-elements under the &lt;spssodescriptor&gt;.&lt;/spssodescriptor&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*JLLkNnuXjAt5EZS0V-PJzw.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Additionally &lt;spssodescriptor&gt; support “&lt;strong&gt;&lt;em&gt;AuthnRequestsSigned&lt;/em&gt;&lt;/strong&gt;” and “&lt;strong&gt;&lt;em&gt;WantAssertionsSigned&lt;/em&gt;&lt;/strong&gt;” attributes as well.&lt;/spssodescriptor&gt;&lt;/p&gt;
&lt;p&gt;Again for the same reason, I skip the discussion on sub-elements of &lt;spssodescriptor&gt; at this point and will discuss them under each SAML profile.&lt;/spssodescriptor&gt;&lt;/p&gt;
&lt;h3 id=&quot;how-to-exchange-samlmetadata&quot;&gt;&lt;strong&gt;How to exchange SAML Metadata&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;So far we discussed various aspects of SAML Metadata definition, now let’s look at how you can exchange generated metadata with another party, there are two approaches possible.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Static Configuration&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*i2zHag_hpHwoqvfnZTD9Pg.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;In this approach, an administrator receives a SAML metadata definition via an offline channel such as email and deployed into the SAML entity ( such as IDP, SP) by himself. This is a quite popular approach but the main disadvantage of this approach is once some of the metadata belong to one party get invalid there are no automated means to correct them except human interventions.&lt;/p&gt;
&lt;p&gt;To give a real-world example, to configure &lt;a href=&quot;https://wso2.com/identity-and-access-management&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;WSO2 IS&lt;/a&gt; as a trusted IdP for Salesforce, one can use the following two simple steps.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step -1&lt;/strong&gt;: Download the IdP metadata file from WSO2 IS deployment and upload into Salesforce SAML SSO configuration page.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*rWpGQ02rs-x3Cs-x.&quot; alt=&quot;&quot;&gt;
&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*jcoUkapxxD4rlXq9.&quot; alt=&quot;&quot;&gt;
&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*Oft3nesnDyN90Yhd.&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step -2&lt;/strong&gt;: Download the SP metadata file from Salesforce and upload that into WSO2 IS SP configuration page.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*rPKDsca332-HWMvD.&quot; alt=&quot;&quot;&gt;
&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*dO7MaKhLnn-D-Lm81n96Lg.png&quot; alt=&quot;&quot;&gt;
&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*mA48bcW3O7ROoUVY.&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Note&lt;/em&gt;&lt;/strong&gt;&lt;em&gt;: You can find further details about the above example from here&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2. Dynamic exchange&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*ImAsKssvy7Jl-RbhI9uhJQ.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;In this approach, both parties collect metadata definition from a 3rd party service and this 3rd party service is responsible to ensure the accuracy of SAML metadata definitions, compared to the previous approach this is more robust but involve some runtime complexity.&lt;/p&gt;
&lt;p&gt;I believe I have covered most of the basic concepts related to SAML metadata specification including understanding the metadata definitions and transmission mechanisms within this post.&lt;/p&gt;
&lt;h3 id=&quot;other-posts-in-thisseries&quot;&gt;Other posts in this series&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/do-you-really-need-saml&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Reloading SAML: Do you really need SAML?&lt;/strong&gt;&lt;br&gt;
_Recently I have been working closely and directly on Identity and Access Management (IAM) domain, which also raised a…_sagarag.medium.com&lt;/a&gt;&lt;a href=&quot;https://sagarag.dev/posts/do-you-really-need-saml&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/saml-basics&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Reloading SAML : SAML Basics&lt;/strong&gt;&lt;br&gt;
_During the last post, I discussed some of the practical use cases of SAML, within this post I will try to discuss a few…_sagarag.medium.com&lt;/a&gt;&lt;a href=&quot;https://sagarag.dev/posts/saml-basics&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;references&quot;&gt;References&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://sagarag.dev/posts/do-you-really-need-saml&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Reloading SAML 1 : Do you really need SAML?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://sagarag.dev/posts/saml-basics&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Reloading SAML 2 : SAML Basics&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.oasis-open.org/committees/download.php/35391/sstc-saml-metadata-errata-2.0-wd-04-diff.pdf&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Metadata for SAML V2.0 specification&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.wso2.com/display/IS550/SAML+2.0+Web+SSO&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;SAML guide on WSO2 IS&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content:encoded><dc:creator>Sagara Gunathunga</dc:creator><category>SAML</category></item><item><title>SAML Basics: Assertions, Protocols, Bindings and Profiles</title><link>https://sagarag.dev/posts/saml-basics</link><guid isPermaLink="true">https://sagarag.dev/posts/saml-basics</guid><description>The building blocks of SAML 2.0: assertions, protocols, the five bindings (Redirect, POST, Artifact, SOAP, PAOS) and profiles, explained for developers.</description><pubDate>Mon, 26 Mar 2018 13:37:35 GMT</pubDate><content:encoded>&lt;p&gt;During the last &lt;a href=&quot;https://sagarag.dev/posts/do-you-really-need-saml&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;post&lt;/a&gt;, I discussed some of the practical use cases of SAML, within this post I will try to discuss a few basic concepts related to SAML.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/do-you-really-need-saml&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Reloading SAML: Do you really need SAML?&lt;/strong&gt;&lt;br&gt;
_Recently I have been working closely and directly on Identity and Access Management (IAM) domain, which also raised a…_sagarag.medium.com&lt;/a&gt;&lt;a href=&quot;https://sagarag.dev/posts/do-you-really-need-saml&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Generally, we refer SAML as a one stranded but it has been evolved into a complex ecosystem with a number of technical specifications, however in the current post I limit to discuss some core specifications, we mainly focus on &lt;a href=&quot;http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;SAML Core ( Assertions and Protocols )&lt;/a&gt; and &lt;a href=&quot;http://docs.oasis-open.org/security/saml/v2.0/saml-bindings-2.0-os.pdf&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;SAML Bindings&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Following diagram illustrate the relationship among these specifications.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*zf3FGaCJeb1bg0to.&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://www.oasis-open.org/committees/download.php/27819/sstc-saml-tech-overview-2.0-cd-02.pdf&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;SAML technical overview&lt;/a&gt; document use following diagram to illustrate associations between the above specifications.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*GE6RFuTudALW0peW.&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Before we further discuss these concepts we need to understand various actors participate in SAML based interactions. Basically SAML assumes two main actors.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*BILs3rYwZtJG8uTb.&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Note that some of the SAML profiles re-define above roles and provide different names within the scope of a specific profile.&lt;/p&gt;
&lt;h3 id=&quot;saml-assertion&quot;&gt;&lt;strong&gt;SAML Assertion&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;An Assertion is a set of security statements about a subject created by an Asserting Party (AP), in most common use cases it is about an individual.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*bR3N_qE23BkhqQ0qN0nY7Q.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;There are 3 types of assertions are defined in SAML depends on their purposes.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1. Authentication statements&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The asserting party use authentication statements to describe the approach used to authenticate the user (Subject) and authenticated time.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2. Attribute statements&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Used to describe attributes above the authenticated user (Subject).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;3. Authorization decision statements&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Used to express something that the user entitled to perform, such as access a particular page etc.&lt;/p&gt;
&lt;p&gt;Following diagrams further illustrate assertions supported in SAML core with their purposes.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*yVxIY-3nHKF2LjcD.&quot; alt=&quot;&quot;&gt;
&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*Skjh5mFMpFyAh1MB.&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;saml-protocols&quot;&gt;SAML Protocols&lt;/h3&gt;
&lt;p&gt;These are the message formats that can be generated and can be used to exchange SAML assertions. There are 6 such protocols are defined in the SAML Core specification.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*iIPEG7zuUXiKKV2F.&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;saml-bindings&quot;&gt;SAML Bindings&lt;/h3&gt;
&lt;p&gt;SAML does not define its own transport protocols instead of existing transport such as HTTP transport can be used to transmit SAML messages, SAML Binding specifies exact semantics to transmit SAML messages via other protocols. For an example a encode SAML message within HTTP POST request body or encode SAML message within the body of SOAP message etc.&lt;/p&gt;
&lt;p&gt;Most of these bindings assume two roles called Requester and Responder, Requester is the entity requesting some services by sending a SAML request message and Responder is the entity that supply required information as a SAML response. Most of the cases Requester is identical to the Service Provider (SP) concept and Responder is identical to Identity Provider (IdP) but there are few exceptional cases as well.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Understanding RelayState&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;RelayState is a very important aspect of SAML standard, technically SAML requester can send a random string value to the SAML responder as RelayState and SAML responder must send this original RelayState value back to the SAML requester together with SAML response. Generally, this is an opaque reference value and used to keep some application-level context during the SAML invocation. As an example, assume a user requested a protected video content from an application, after successful authentication the application is supposed to return the requested video, in this case, opaque reference for requested video can be kept within RelayState parameter.&lt;/p&gt;
&lt;p&gt;Each SAML binding specifically mentions whether it support for RelayState or not if supported binding also specify how to encode the RelayState value using underlying transport protocol and message format.&lt;/p&gt;
&lt;p&gt;In the following section, we will look at each SAML binding in detail.&lt;/p&gt;
&lt;h3 id=&quot;1-http-redirectbinding&quot;&gt;1. HTTP Redirect Binding&lt;/h3&gt;
&lt;p&gt;This approach uses HTTP Redirect ( 301, 302) as the transport mechanism and SAML messages are encoded as HTTP URL parameters. Generally, this binding assumes the presence of a user agent such as a web browser which can handle HTTP Redirects. It’s hard to use these messages with large SAML messages.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*KJnDvUGRTdWr4sdG.&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;A user tries to access a protected resource in an application, the application realized the user is not authenticated.&lt;/li&gt;
&lt;li&gt;The application sends HTTP redirect (302) back to the user’s browser. The Location HTTP header contains the endpoint URL for the SAML service and SAML request also encoded as with the URL.&lt;/li&gt;
&lt;li&gt;User’s browser follows the received HTTP redirect message and send HTTP GET message to the SAML service endpoint with the received SAML message.&lt;/li&gt;
&lt;li&gt;SAML responder receives the HTTP message at the service endpoint, process the received SAML message and respond accordingly.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Here are some of the important points about HTTP Redirect binding.&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;RelayState is supported but should be limited to 80 bytes and it should be appended to the URL with “RelayState=value” format.&lt;/li&gt;
&lt;li&gt;The SAML request is first compressed using DEFLATE compression mechanism and then encoded using Base64 finally it again need to be URL encoded.&lt;/li&gt;
&lt;li&gt;For the request signing, it should use DSAWithSHA or RSAWithSHA algorithms ( we will discuss why we need to sign here).&lt;/li&gt;
&lt;li&gt;HTTP Cache should not be used with this binding.&lt;/li&gt;
&lt;li&gt;SAML processors should not use HTTP error codes instead SAML error coded need to be used.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Following are the URL parameter names supported in this binding.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;SAMLRequest&lt;/strong&gt; — SAML request message&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;RealyState&lt;/strong&gt; — RealyState value&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SAMLEncoding&lt;/strong&gt; — indicate the SAML encoding mechanism&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SigAlg&lt;/strong&gt; — Signature algorithm identifier&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Signature&lt;/strong&gt; — Base64 encoded signature value&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Example of SAML redirect binding&lt;/p&gt;
&lt;h3 id=&quot;2-http-postbinding&quot;&gt;2. HTTP POST Binding&lt;/h3&gt;
&lt;p&gt;Facilitates to transmit SAML messages as Base64 encoded HTML form parameters. Generally, this binding assumes the presence of a user agent such as a web browser which can handle HTTP Redirects. It’s hard to use these messages with large SAML messages.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*FmVANBOBvWDbz_FY.&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;A user tries to access a protected resource in an application, the application realized the user is not authenticated.&lt;/li&gt;
&lt;li&gt;The application sends HTTP OK (200) back to the user’s browser with HTML form, SAML request is embedded within the HTML form as hidden input control. Generally, this response HTML form consists of JavaScript or similar scripting logic to auto-submit the form.&lt;/li&gt;
&lt;li&gt;User’s browser renders the HTML content received and auto-submission logic submits the HTML form with SAML request to the SAML service using HTTP POST.&lt;/li&gt;
&lt;li&gt;SAML responder receives the HTTP message at the service endpoint, process the received SAML message and respond accordingly.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Here are some of the important points about HTTP Redirect binding.&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;RelayState is supported but should be limited to 80 bytes and it should be mentioned as hidden HTML form input with ‘RelayState’ name.&lt;/li&gt;
&lt;li&gt;The SAML request needs to be encoded using Base64 before transmit as HTML form input.&lt;/li&gt;
&lt;li&gt;HTTP Cache should not be used with this binding.&lt;/li&gt;
&lt;li&gt;SAML processors should not use HTTP error codes instead SAML error coded need to be used.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Following the support URL parameter names&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;SAMLRequest&lt;/strong&gt; — SAML request message in case of sending a request&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SAMLResponse&lt;/strong&gt; — SAML response message in case of request of sending a response.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;RealyState&lt;/strong&gt; — RealyState value&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Example for SAML POST binding&lt;/p&gt;
&lt;h3 id=&quot;3-http-artifactbinding&quot;&gt;3. HTTP Artifact Binding&lt;/h3&gt;
&lt;p&gt;In this binding SAML messages are transmitted via a user agent as an opaque reference value called ‘SAML Artifact. Any successful SAML message exchange consists of 2 steps as follows.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The requestor sends SAML Artifact to the responder through a user agent, usually via HTTP POST or HTTP GET call, this is a front-channel invocation.&lt;/li&gt;
&lt;li&gt;The responder directly calls the requestor with the received SAML Artifact, the responder returns the SAML message related to the provided SAML Artifact to the responder within the response message. SOAP over HTTP is the widely used approach to perform this back-channel invocation.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;According to SAML terminology this binding use request-response protocol and Artifact resolve protocol.&lt;/p&gt;
&lt;p&gt;This binding is relatively slow because each SAML transmission is required to have multiple network calls but this is highly secure approach because original SAML messages are directly passed from the requestor to the requestor, only SAML message reference (Artifact) is exposed to the user agent.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*z5X_GLnpL0ThHzeO.&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Message interaction when HTTP POST is used&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;A user tries to access a protected resource in an application, the application realized the user is not authenticated.&lt;/li&gt;
&lt;li&gt;The application sends HTTP OK (200) back to the user’s browser with HTML form, SAML Artifact is embedded within the HTML form as hidden input control. Generally, this response HTML form consists of JavaScript or similar scripting logic to auto-submit the form.&lt;/li&gt;
&lt;li&gt;User’s browser renders the HTML content received and auto-submission logic submits the HTML form with SAML Artifact to the SAML responder using HTTP POST.&lt;/li&gt;
&lt;li&gt;SAML responder process the SAML Artifact, validate and identify the issuer. Once the Artifact resolver endpoint of the requester is known to the responder, it sends a SAML ArtifactResolve message to the requester within a SOAP message body (SOAP over HTTP ).&lt;/li&gt;
&lt;li&gt;The requester process the ArtifactResolve message and return an ArtifactResponse message within the body section of the SOAP response message. The SAML request is embedded within ArtifactResolve message.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*GKhdjI1UPMruT-rQ.&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Message interaction when HTTP POST is used&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;A user tries to access a protected resource in an application, the application realized the user is not authenticated.&lt;/li&gt;
&lt;li&gt;The application sends HTTP redirect (302) message back to the user’s browser. The Location HTTP header contains the endpoint URL for the SAML service and SAML Artifact also encoded as with the URL.&lt;/li&gt;
&lt;li&gt;User’s browser follows the received HTTP redirect message and send HTTP GET message to the SAML service endpoint with the received SAML Artifact.&lt;/li&gt;
&lt;li&gt;SAML responder process the SAML Artifact, validate and identify the issuer. Once the Artifact resolver endpoint of the requester is known to the responder, it sends a SAML ArtifactResolve message to the requester within a SOAP message body (SOAP over HTTP ).&lt;/li&gt;
&lt;li&gt;The requester process the ArtifactResolve message and return an ArtifactResponse message within the body section of the SOAP response message. The SAML request is embedded within ArtifactResolve message.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Following parameters are used for front-channel SAML Artifact transmission via HTTP.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;For HTTP GET&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;SAMLart URL parameter&lt;/li&gt;
&lt;li&gt;RelayState URL parameter&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;For HTTP POST&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;SAMLart HTML form parameter&lt;/li&gt;
&lt;li&gt;RelayState HTML form parameter&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Format of the SAML Artifact&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;SAML Artifact should have issuer identification, resistance to tampering and forgery, uniqueness, and compactness characteristics. Following diagram graphically illustrate the structure and purpose of SAML Artifact.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*YO9mgDXXyJBjJ7Ip.&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;4-http-soapbinding&quot;&gt;4. HTTP SOAP Binding&lt;/h3&gt;
&lt;p&gt;In this binding body section of the SOAP message is used to carry the SAML message, generally, HTTP is used as the transport level protocol for these SOAP messages. SOAP encoding, SOAP or HTTP headers are not used in this binding.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*2kDoAOEZFKrA2ceP.&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Message interactions&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The requestor generates a SAML message and place it inside the body of a SOAP message and transmit this SOAP message to the responder using HTTP.&lt;/li&gt;
&lt;li&gt;The responder process and generate a SAML response message and place it inside the body of a SOAP message and transmit the SOAP message back to the requestor using HTTP.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;5-http-paosbinding&quot;&gt;5. HTTP PAOS Binding&lt;/h3&gt;
&lt;p&gt;PAOS binding also known as reverse-SOAP binding. Unlike other SOAP binding specifications PAOS or more accurately ‘Reversed HTTP binding for SOAP’ is not a specification developed by W3C instead it was developed by Liberty Alliance Project, you can read more details about this specification from &lt;a href=&quot;http://www.projectliberty.org/liberty/content/download/909/6303/file/liberty-paos-v2.0.pdf&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Usually, SOAP request is carried by a HTTP request message and SOAP response message is carried by HTTP response message and utilize single HTTP request-response cycle, but in PAOS binding SOAP request message is carried by HTTP response message and SOAP response message is carried by HTTP response message and as you can imagine PAOS use two HTTP request-response cycles. SAML ECP profile uses this PAOS binding. Also, note that by default this binding does not support RealyState.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*ftHG8VR8f5LqOZLs.&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Message interactions&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;SAML Responder ( This is the user’s client device, not any kind of IdP or SAML asserting party) advertises its ability to handle PAOS binding by sending HTTP GET/POST message to the requester ( usually the service provider) by using following two HTTP headers.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;2. As the response to the received HTTP message, the requester sends a SOAP message with a SAML request to the responder within the body of HTTP response.&lt;/p&gt;
&lt;p&gt;3. Once the responder in a position to respond with a SAML response, it creates a SOAP message and place SAML response within the SOAP body and use new HTTP request to send this payload to the requester.&lt;/p&gt;
&lt;p&gt;4. Requester process receives SAML response and returns the requested business data to the client.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt;: Once the SAML request is received by the client device in step-2, the client device is responsible to validate it and somehow generate SAML response by contacting an IdP or using some other mean, that part is out of the context of this binding.&lt;/p&gt;
&lt;h3 id=&quot;saml-profiles&quot;&gt;SAML Profiles&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;http://docs.oasis-open.org/security/saml/v2.0/saml-profiles-2.0-os.pdf&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;SAML profiles&lt;/a&gt; are based on practical business use cases, profiles define ruleset on how to SAML assertions, protocols and binding need to be used to achieve each of the practical scenarios. We will discuss some of the important SAML profiles during this series with a great amount of details, just to complete this post I have given a list of SAML profiles below.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;SSO Profiles&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Web Browser SSO Profile&lt;/li&gt;
&lt;li&gt;Single Logout Profile&lt;/li&gt;
&lt;li&gt;Enhanced Client or Proxy (ECP) Profile&lt;/li&gt;
&lt;li&gt;Identity Provider Discovery Profile&lt;/li&gt;
&lt;li&gt;Name Identifier Management Profile&lt;/li&gt;
&lt;li&gt;Artifact Resolution Profile&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Other Profiles&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Assertion Query/Request Profile&lt;/li&gt;
&lt;li&gt;Name Identifier Mapping Profile&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;SAML Attribute Profiles&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Basic Attribute Profile.&lt;/li&gt;
&lt;li&gt;X.500/LDAP Attribute Profile&lt;/li&gt;
&lt;li&gt;UUID Attribute Profile&lt;/li&gt;
&lt;li&gt;DCE PAC Attribute Profile&lt;/li&gt;
&lt;li&gt;XACML Attribute Profile&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;learning-saml&quot;&gt;Learning SAML&lt;/h3&gt;
&lt;p&gt;If you have read this series up to this point, you should have a fair understanding of the SAML standard. In case if you want to explore more about SAML by reading specifications by yourself, following roadmap may help to you.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*eihevYqdee0KAwMC.&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;other-posts-in-thisseries&quot;&gt;Other posts in this series&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://sagarag.dev/posts/do-you-really-need-saml&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;strong&gt;Reloading SAML: Do you really need SAML?&lt;/strong&gt;&lt;br&gt;
_Recently I have been working closely and directly on Identity and Access Management (IAM) domain, which also raised a…_sagarag.medium.com&lt;/a&gt;&lt;a href=&quot;https://sagarag.dev/posts/do-you-really-need-saml&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;references&quot;&gt;References&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Reloading SAML 1: &lt;a href=&quot;https://sagarag.dev/posts/do-you-really-need-saml&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Do you really need SAML&lt;/a&gt;?&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.oasis-open.org/committees/download.php/27819/sstc-saml-tech-overview-2.0-cd-02.pdf&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;SAML Technical Overview&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.oasis-open.org/committees/download.php/35711/sstc-saml-core-errata-2.0-wd-06-diff.pdf&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;SAML2 Core&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.oasis-open.org/committees/download.php/35387/sstc-saml-bindings-errata-2.0-wd-05-diff.pdf&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;SAML2 Bindings&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.oasis-open.org/committees/download.php/35389/sstc-saml-profiles-errata-2.0-wd-06-diff.pdf&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;SAML2 Profiles&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://wiki.oasis-open.org/security/FrontPage&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;SAML2 Wiki page&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content:encoded><dc:creator>Sagara Gunathunga</dc:creator><category>SAML</category></item><item><title>Do You Really Need SAML? What SAML SSO Solves</title><link>https://sagarag.dev/posts/do-you-really-need-saml</link><guid isPermaLink="true">https://sagarag.dev/posts/do-you-really-need-saml</guid><description>What problem SAML single sign-on actually solves, how it works at a high level, and when SAML still makes sense next to OpenID Connect for enterprise SSO.</description><pubDate>Sat, 24 Mar 2018 03:45:10 GMT</pubDate><content:encoded>&lt;p&gt;Recently I have been working closely and directly on Identity and Access Management (IAM) domain, which also raised a necessity to revisit most of the IAM concepts and standards again. As a person with a limited memory capacity I used to blog my studies/readings as much as possible, here is another attempt, this time on SAML.&lt;/p&gt;
&lt;p&gt;Without any doubt I would say, SAML has been used by the vast majority of Internet users, it’s a different question whether they are aware that they have been using SAML or not.&lt;/p&gt;
&lt;p&gt;Well, if I start with old school type question …&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;What is SAML ?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Everyone can easily find an answer from &lt;a href=&quot;https://en.wikipedia.org/wiki/SAML_2.0&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Wikipedia&lt;/a&gt;, but let’s leave that answer for a while and think about what conditions or what problems in our day to day life raise ‘the need’ to formalize such standard because without understanding such background any specification/standard is just a collection of technical jargon only, let me present you few stories ….&lt;/p&gt;
&lt;h3 id=&quot;story-one&quot;&gt;Story One&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*v8-K_0BY7vxtzaN4.&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;An airline called “&lt;strong&gt;MyAirways&lt;/strong&gt;” operates their ticket booking and privilege club as two different business units, in order to reduce management overhead and to provide more efficient service. With this organizational structure, they have two separate web applications called “&lt;strong&gt;myairways.com&lt;/strong&gt;” and “&lt;strong&gt;myprivilege.com&lt;/strong&gt;” for each business unit.&lt;/p&gt;
&lt;p&gt;Even though this sounds like a good business model for them, this set number of technical challenges. First, from the user’s point of view, they access business offerings belong to one airline, the internal management structure is irrelevant for them. As you can imagine, asking users to maintain two set of usernames/passwords for each application or asking users to separately login at each application will seriously break the user experience.&lt;/p&gt;
&lt;p&gt;At this point, someone can ask why can’t we use HTTP Cooke here to share logged-in contexts? According to HTTP protocol Cookies can not be shared among multiple domains, in simple words, a browser does not send cookies created for myairways.com domain when the same user accessing “myprivilege.com” domain. Top of this, synchronization of user stores connected to two applications also cause a lot of practical and security concerns, so we need to find a viable solution for this use case.&lt;/p&gt;
&lt;h3 id=&quot;story-two&quot;&gt;Story Two&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*-sfnQEkpX8ftDUMU.&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Assume a new business partnership established between MyAirways and a leading hotel chain called &lt;strong&gt;HomeLike&lt;/strong&gt;, with this new partnership those who book flights from myairways.com can get discounts from a web application called “&lt;strong&gt;homelike.com&lt;/strong&gt;”. Additionally, regular customers of MyAirways can utilize their privilege club points to make payments on homelike.com. Once the business development teams came up with this win-win partnership, now it’s a challenge for technical teams to provide the right user experience. Compared to the previous story-one the technical complexity of this use case is much higher because practically it’s not possible to share or sync user stores belong to different companies due to many obvious reasons. Top of this some of the customers can have existing accounts on both applications, in such cases they may expect some sort of an association among existing accounts.&lt;/p&gt;
&lt;h3 id=&quot;story-three&quot;&gt;Story Three&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/0*9yXiuHm794bsdo2Y.&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Nowadays it is common to leverage cloud applications by enterprises over on-premise applications due to many advantages enabled by cloud applications. MyAirways also use a bunch of such cloud applications for internal purposes such as sales management, HR management, payroll management, expenses management etc.&lt;/p&gt;
&lt;p&gt;But all of these cloud applications are manage and control by 3rd party companies, MyAirways only got paid subscriptions to use these applications. However in order for employees to use these applications, each employee needs to be provisioned on each and every application, and when they leave the job those people need to be de-provisioned from each application as well, this cause number of administrative issues. Additionally sharing internal employee data with 3rd parties increase great security risk as well.&lt;/p&gt;
&lt;p&gt;So far we have shared three use cases without a proper solution ….&lt;/p&gt;
&lt;h3 id=&quot;so-what-is-the-solution&quot;&gt;So what is the solution?&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Single Sign-On (SSO)&lt;/strong&gt; is the most prominent and widely accepted answer for the above discussed practical problems. Single Sign-On (SSO) facilitates to share the logged-in context of one application with a number of other applications via secure tokens and eliminate the requirement of re-login at each application.&lt;/p&gt;
&lt;p&gt;Historically there was a number of protocols/ technologies developed to cater SSO use cases and some of them still use today, &lt;a href=&quot;https://apereo.github.io/cas/4.2.x/protocol/CAS-Protocol.html&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;CAS&lt;/a&gt; is a good example. However, most of these protocols/ technologies developed their own proprietary protocols and it is required to deploy some sort of a proprietary agent/client within each and every application to communicate with SSO service.&lt;/p&gt;
&lt;p&gt;SAML is the most successful attempt to standardize SSO technologies, it has been widely used during the last 10 years or so on. Additionally, there is a lot of supportive and interoperable specification developed around SAML ecosystem, as an example SAML can co-exist and collaborate with other identity protocols such as XACML and OAuth2. SAML also used as the base for new standards such as EU’s eIDAS standard for eID schemas.&lt;/p&gt;
&lt;h3 id=&quot;how-saml-differ-from-proprietary-sso-technologies&quot;&gt;How SAML differ from proprietary SSO technologies?&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;SAML specifications are developed and maintained as open standards, this means anyone can review those specifications and figure out what really going on behind the scene, also anyone can contribute for further development of these standards as well.&lt;/li&gt;
&lt;li&gt;SAML use standard and highly interoperable text format called XML, any of the modern programing language can understand and process XML data easily, so any modern programing language can be used to generate or process SAML messages.&lt;/li&gt;
&lt;li&gt;Instead of developing own transport mechanisms SAML use existing Internet transport protocol such as HTTP and SOAP.&lt;/li&gt;
&lt;li&gt;SAML also use some concepts from widely used HTML standard as well.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Generic interactions among various roles involved in SAML standard can be summarized as follows.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Generally, user profiles and user credentials are stored centrally within one system, this can be a homegrown system or can be an IAM solution.&lt;/li&gt;
&lt;li&gt;When a user tries to access a secured page/resource on an application it direct users to the central identity service via the user’s agent.&lt;/li&gt;
&lt;li&gt;The central identity service tries to authenticate the user and if it successfully creates a session for the authenticated user, then it creates a SAML token (XML message) and sends it back to the original application directly or indirectly (usually via user agent).&lt;/li&gt;
&lt;li&gt;This SAML token contains all the required identity data such as authentication method, authorization decisions, user attributes etc. The application uses this SAML token to create a local HTTP session and treat the user as logged-in.&lt;/li&gt;
&lt;li&gt;If the same user tries to access another application of the same organization, like in step-2 that application also redirects the user to central identity service.&lt;/li&gt;
&lt;li&gt;At the central identity service, it recognizes this user is already logged-in and skips the authentication steps. The central identity service generates a SAML token and shares with this 2nd application. Generally these 5th and 6th steps are transparent to end-users.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;SAML is not limited to share identity details within the same organization or among partner organizations instead most of the cloud vendors such as &lt;a href=&quot;https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_enable-console-saml.html&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;AWS&lt;/a&gt;, &lt;a href=&quot;https://support.google.com/a/answer/6087519?hl=en&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Google&lt;/a&gt;, &lt;a href=&quot;https://developer.salesforce.com/page/Single_Sign-On_with_SAML_on_Force.com&quot; rel=&quot;noopener noreferrer&quot; target=&quot;_blank&quot;&gt;Salesforce&lt;/a&gt; support for SAML. Instead of duplicating user accounts in each of the cloud application, it’s possible to establish a trust relationship between cloud service and your own Identity Provider (IdP), with that model when someone tries to log-in to a particular cloud service it redirects the user to organizational IdP with a SAML request and expects SAML response back.&lt;/p&gt;
&lt;p&gt;Here is the concrete example based on Salesforce.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn-images-1.medium.com/max/800/1*Vrob8p5Utgi3KZGX1GwUWQ.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;I hope now you have a better idea about why identity experts have created such a standard called SAML and what problems it tries to solve, during the next post of this series I will try to discuss basics of SAML standard.&lt;/p&gt;</content:encoded><dc:creator>Sagara Gunathunga</dc:creator><category>SAML</category></item></channel></rss>