<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Martin Besozzi on Medium]]></title>
        <description><![CDATA[Stories by Martin Besozzi on Medium]]></description>
        <link>https://medium.com/@embesozzi?source=rss-86e67d103504------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*sLZbtSeRidFCjTDb6xB4vA.png</url>
            <title>Stories by Martin Besozzi on Medium</title>
            <link>https://medium.com/@embesozzi?source=rss-86e67d103504------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 06:52:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@embesozzi/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Your Passkey Is Gone. Now What? Native Passkey Recovery with Verifiable Credentials and Keycloak]]></title>
            <link>https://embesozzi.medium.com/your-passkey-is-gone-now-what-native-passkey-recovery-with-verifiable-credentials-and-keycloak-157d04cea459?source=rss-86e67d103504------2</link>
            <guid isPermaLink="false">https://medium.com/p/157d04cea459</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[passkey]]></category>
            <category><![CDATA[verifiable-credentials]]></category>
            <category><![CDATA[keycloak]]></category>
            <dc:creator><![CDATA[Martin Besozzi]]></dc:creator>
            <pubDate>Wed, 02 Sep 2026 19:39:39 GMT</pubDate>
            <atom:updated>2026-09-02T22:00:40.067Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Passkeys give us a secure, phishing resistant way to authenticate without passwords.<br>But what happens when you lose your passkey?<br>What if recovery could maintain the same level of assurance?</blockquote><h3>What Happens When Your Passkey Is Gone?</h3><p>Passwordless authentication solves the password problem. It does not automatically solve the account recovery problem.</p><p>Passkeys are phishing resistant authentication: the user unlocks them with face, fingerprint, or PIN, backed behind the scenes by the User Verification (UV) configured on the device. It’s a much better experience than passwords. But how do you provide a recovery mechanism with the same level of assurance, without falling back to something weaker than the passkey they just lost?</p><p>Most recovery flows quietly reintroduce the exact weaknesses passwordless was supposed to remove: a password reset, an SMS OTP, a support ticket. Every one of those is a phishable, socially engineerable fallback sitting underneath an otherwise strong authenticator. The recovery path is only as strong as its weakest link, and if that link is a six-digit code sent by SMS, the passkey didn’t actually raise the security bar for the account. It just moved the attack surface to the recovery flow.</p><p>If passwordless is going to mean anything, recovery has to be passwordless too.<br>At TwoGenIdentity, we’ve been exploring Verifiable Credentials (VCs) as a way to close that gap: a second, independent, cryptographically verifiable way to establish identity, used specifically at the moment a user needs to recover access. Not as a replacement for the passkey, but as what proves you’re allowed to register a new one.</p><h4><strong>A Verifiable Credential Is Not an Authentication Protocol</strong></h4><p>Before getting into the recovery flow, it’s worth being precise about what a Verifiable Credential actually is, because it’s easy to conflate it with authentication.</p><p>A Verifiable Credential is a digitally signed set of claims issued by a trusted <strong>Issuer</strong> about a <strong>Subject</strong>, which a <strong>Holder</strong> stores and later presents to a <strong>Verifier</strong>.</p><p>Think of it as a digital Employee Credential. The organization (Issuer) issues it. The employee (Holder) stores it in a wallet. When needed, the employee presents it, and the party checking it (Verifier) can cryptographically confirm it’s genuine, unaltered, and actually theirs, without calling the issuing organization to check.</p><h4><strong>The Credential Format Landscape</strong></h4><p>There isn’t one standard Verifiable Credential (VC) format. Three formats are commonly used today.</p><ul><li>W3C VC is defined by the W3C and typically encoded as JSON or JSON LD, using Data Integrity or JOSE/COSE.</li><li>SD JWT VC is defined by the IETF and is based on JWT/JWS.</li><li>ISO mdoc is defined by ISO/IEC 18013 5 and is based on CBOR/COSE.</li></ul><p>The important part is that OpenID4VCI and OpenID4VP are format agnostic.</p><ul><li>OpenID4VCI handles credential issuance between an issuer and a wallet.</li><li>OpenID4VP handles credential presentation between a wallet and a verifier.</li></ul><p>Both protocols can work with W3C VC, SD JWT VC, and ISO mdoc.</p><p>For this employee credential recovery use case, SD JWT VC is a natural fit. It is JWT based, integrates well with existing OAuth and OIDC infrastructure, and supports selective disclosure, allowing the employee to reveal only the claims needed for recovery.</p><p>One important ecosystem note is that Google Wallet and Apple Wallet digital IDs are currently based on ISO mdoc, rather than SD JWT VC. This lab uses SD JWT VC because it integrates directly with the existing Keycloak deployment.</p><h3><strong>Practical Case: Native Passkey Recovery with Keycloak</strong></h3><p>Here’s where the theory turns into something a user actually experiences.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_j2kIY0557nXMmx2nLLPHw.png" /></figure><p>In the following demo, Keycloak has already issued a Verified Employee ID for the employee. The credential is stored in the employee’s digital wallet and can later be presented when identity verification is required.</p><p>The recovery experience is simple:</p><ul><li>Lost passkey</li><li>Present Employee Credential</li><li>Verify identity</li><li>Register a new passkey</li></ul><p>This integration uses the <strong>Digital Credentials API</strong> to talk directly to the wallet, combined with the <strong>TwoGenIdentity Keycloak Advanced Authentication Extensions</strong> to give a native experience. The whole exchange happens in band, inside the application the user is already in.</p><h4><strong>Demo: Native Passkey Recovery</strong></h4><p>The employee:</p><ol><li>Selects “Other ways to sign in.”</li><li>Chooses “Recover with Verified Employee ID.”</li><li>Presents their Verified Employee ID from their digital wallet.</li><li>Their identity is verified.</li><li>They create a new passkey.</li><li>Their account is recovered and the new passkey is ready to use.</li></ol><p>The entire experience happens directly in the application, start to finish.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FujmKFD0HO2I%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DujmKFD0HO2I&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FujmKFD0HO2I%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/81663967e24e7b21e7730a30bf08838b/href">https://medium.com/media/81663967e24e7b21e7730a30bf08838b/href</a></iframe><h3><strong>Beyond Recovery</strong></h3><p>Account recovery is just one use case. The same foundation, a trusted issuer, a holder controlled wallet, and a verifier that can check a presentation cryptographically without a phone call to the issuer, extends to passwordless authentication, step up authentication, employee onboarding, access to sensitive applications and resources, identity proofing, and other scenarios where an organization needs to verify trusted attributes about a user.</p><p>Going passwordless was never just about removing passwords from login. It’s about making the entire authentication lifecycle stronger, including the moment things go wrong and a user needs to get back in.</p><h3><strong>Looking Ahead</strong></h3><p>This builds on the ongoing efforts of the Keycloak team, the FIDO Alliance’s work on passkeys and Verifiable Credentials, and the OpenID Foundation’s work on Verifiable Credentials and digital identity standards.</p><p>The European Digital Identity (EUDI) Wallet is another strong example of how digital wallets and verifiable credentials are becoming part of the future of digital identity in Europe.</p><p>Verifiable Credentials are still evolving, and there are areas where the ecosystem and standards need further definition and alignment.</p><p>The Digital Credentials API is also relatively new, and wallet, browser, and platform support will continue to evolve.</p><p>But the direction is promising.</p><p>The ability to combine trusted digital credentials, native wallet experiences, and passkeys opens new possibilities for identity, authentication, onboarding, and recovery.</p><p>For us, this is an exciting area to continue exploring and bringing into our identity platform as the ecosystem matures.</p><h4>Want to explore this topic further?</h4><p>This is a condensed version of the article. The complete version here:</p><p><a href="https://embesozzi.github.io/posts/martin-besozzi/verifiable-credentials-keycloak-native-passkey-recovery/">Your Passkey Is Gone. Now What? Native Passkey Recovery with Verifiable Credentials and Keycloak | Martin Besozzi</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=157d04cea459" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Applying Zero Trust to AI Agents with Intent Agent Native Authorization]]></title>
            <link>https://embesozzi.medium.com/applying-zero-trust-to-ai-agents-with-intent-agent-native-authorization-b7a421f745e8?source=rss-86e67d103504------2</link>
            <guid isPermaLink="false">https://medium.com/p/b7a421f745e8</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[zero-trust]]></category>
            <category><![CDATA[passkey]]></category>
            <category><![CDATA[ai-agent]]></category>
            <dc:creator><![CDATA[Martin Besozzi]]></dc:creator>
            <pubDate>Tue, 21 Jul 2026 17:58:49 GMT</pubDate>
            <atom:updated>2026-07-21T17:58:49.773Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_BsITSGEMPOqcgml7AzGQQ.png" /></figure><p>Intent Agent Native Authorization for Agentic Profiles (IANA-AP) defines a four-phase framework that enables first-party AI agents to discover authorization requirements, compute structured intent from user prompts, obtain cryptographic human approval via Passkeys, and enforce it at execution time.</p><h4><strong>Why Agents Must Earn the Right to Act</strong></h4><blockquote>Agents earn the right to act. They do not assume it.</blockquote><p>AI agents introduce a new authorization challenge. Unlike deterministic software, an AI agent may determine which tools and resources it needs only after it understands the user’s request. As a result, the required authorization is often discovered at the moment of execution, rather than upfront during authentication.</p><p>Existing authorization systems can determine whether an individual request is permitted. What they do not define is how an agent discovers the authorization requirements of the services it plans to invoke, obtains explicit approval for its planned operations before execution, and ensures that every runtime invocation remains consistent with that approval.</p><p>This distinction is important. Traditional authorization answers a single question:</p><blockquote>Is this request allowed?</blockquote><p>Agentic systems require an additional runtime guarantee:</p><blockquote>Does this request still belong to the execution plan the user explicitly and cryptographically approved?</blockquote><p>The plan-before-execute principle addresses this challenge directly. Before invoking any tool, the agent computes its planned operations, derives the required authorization, and presents that authorization request to the user. The user reviews the planned operations, explicitly approves them with a phishing-resistant cryptographic gesture using a Passkey, and only then does execution begin. Every subsequent runtime invocation is verified against that approved execution plan, ensuring the agent cannot silently expand the scope of its behavior after approval.</p><p>This approach applies Zero Trust principles to agentic execution. Authorization is established before execution and continuously verified during execution. Rather than granting broad permissions at login time, the agent requests authorization for the specific operations it plans to perform, the user explicitly approves those operations, and every runtime invocation is validated against that approved authorization.</p><h3><strong>Introducing Intent Agent Native Authorization for Agentic Profiles (IANA-AP)</strong></h3><p>Existing standards provide many of the building blocks required for secure AI agents. OAuth defines delegated authorization and structured authorization requests through Rich Authorization Requests (RAR). AuthZEN standardizes authorization requests and policy decisions, while protocols such as MCP standardize tool discovery.</p><p>What is still missing is the runtime authorization lifecycle that connects these capabilities. Before an AI agent can execute on behalf of a user, it must answer four fundamental questions:</p><ul><li>What authorization does each service require?</li><li>Which operations is the agent planning to execute?</li><li>Has the user explicitly approved those operations?</li><li>Does every runtime invocation remain within that approval?</li></ul><p>Intent Agent Native Authorization for Agentic Profiles (IANA-AP) defines a runtime authorization framework for first-party AI agents that answers these four questions. Rather than introducing a new authorization model or replacing existing open standards, IANA-AP composes and extends them into a complete runtime authorization lifecycle, enabling organizations to adopt agent-native authorization using their existing identity infrastructure.</p><p>IANA-AP extends traditional login-time authorization with runtime authorization for agentic interactions. Rather than authorizing broad capabilities once during authentication, the framework computes a structured authorization intent from the user’s prompt, obtains explicit user approval before execution, and cryptographically binds that approval to the resulting authorization token. Every runtime invocation is then verified against that approved authorization intent.</p><p>The framework is available as an <a href="https://github.com/embesozzi/draft-embesozzi-intent-agent-native-authorization"><strong>open specification on GitHub</strong></a>. This article introduces the motivation, concepts, and architecture. Readers interested in the normative protocol definitions, message formats, and processing rules should refer to the specification.</p><p>The following sections describe the framework through four consecutive phases that together implement the complete runtime authorization lifecycle.</p><h3><strong>The Four-Phase Runtime Authorization Lifecycle</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WHQFWc4lbf78QLTBdxRQJg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZsUiG-vq4ebbLgeUtt3AvA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q9tdoTROWPt7Z5dutHsyvg.png" /></figure><h4>Phase 1: Discover Required Authorization</h4><p>Before an agent can ask for authorization, it needs to understand what authorization each service requires. Rather than embedding this knowledge inside the agent, IANA-AP lets services advertise it through machine-readable Agentic Profiles. This means agents can work with any service dynamically, without requiring service-specific authorization logic built in.</p><p>For MCP, the agent reads the Agentic MCP Profile from each server via the MCP Server Card or <em>tools/list</em> response. Each tool that participates in IANA-AP declares its authorization requirements through an <em>x-authz-mapping</em> extension field inside its <em>_meta</em> object. The presence of this field is the opt-in signal that the tool supports pre-computed authorization.</p><p>IANA-AP uses the <strong>SARC model</strong> (Subject, Action, Resource, Context) to represent each authorized operation. This is the same model used by the OpenID AuthZEN Authorization API, which means the intent entries computed in Phase 2 map directly to the structure the PDP expects at enforcement time, with no translation layer.</p><p>The <em>x-authz-mapping</em> field carries three sub-objects expressed as CEL (Common Expression Language) expressions:</p><ul><li>action: the SARC action component (e.g. which MCP method is being called)</li><li>resource: the SARC resource component (e.g. which tool on which server)</li><li>arguments: argument names mapped to CEL expressions that resolve values from the user’s prompt (e.g. which specific `userId` was mentioned)</li></ul><h4>Phase 2: Compute Authorization Intent</h4><p>Once the authorization requirements are known, the agent determines exactly which operations it plans to execute and translates them into a structured authorization request. This phase does not issue a token yet. It prepares the request that will later be reviewed by the user and approved by the Authorization Server.</p><p>Using the authorization mappings discovered during Phase 1 together with the user’s prompt, the framework produces an authorization_details array containing one or more agent_intent entries. Each entry represents a planned operation for which the agent requests authorization before execution.</p><p>IANA-AP introduces agent_intent, a proposed Rich Authorization Request (RAR) type for representing an agent’s planned operations. Each entry describes a planned tool invocation at a conceptual level: the action the agent wants to perform, the resource it wants to act on, the intended audience, and the contextual arguments needed to keep runtime execution aligned with the user’s approval.</p><p>At this stage, think of the structure like this. It is not meant to be a final wire-level payload; it is a reader-friendly shape of what the approved token will later carry:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4mjgHLfnd3RPsk8mSxoy6Q.png" /></figure><p>Conceptually, this says: “the agent wants to call this kind of tool, on this kind of resource, for this audience, with these contextual arguments.” The specific values are derived from the user’s request and from the authorization mapping published by the MCP server.</p><p>The agent produces one agent_intent entry per planned tool invocation and collects them into an authorization_details array. One possible implementation is to delegate this phase to a dedicated Intent Agent. This component is responsible only for authorization planning. It never invokes tools or executes operations; its sole responsibility is to compute the agent_intent entries that will later be presented to the user.</p><p>The agent must present the computed authorization details to the user for review before submitting the authorization request.</p><p>IANA-AP uses the OAuth 2.0 Rich Authorization Requests (RAR) format to represent agent_intent. This design choice enables interoperability with existing Authorization Servers, such as Keycloak, Ping Identity, Gluu and others, by building on an established authorization mechanism rather than introducing a completely new request format. Future iterations of the specification may define additional token representations optimized for agent-native authorization; however, this initial version focuses on leveraging existing standards to simplify adoption and implementation.</p><h4>Phase 3: Review and Approve</h4><p>At this point, the agent knows exactly which operations it intends to perform. Before executing any of them, those operations must be explicitly approved by the user.</p><p>The user now reviews exactly what the agent intends to execute. Nothing has happened yet. This is the moment where explicit human approval enters the flow — and it happens natively, without any browser redirect or context switch. I call this Agent Native Authorization: an authorization pattern in which the agent orchestrates the authorization flow defined by the Authorization Server (Identity Provider) directly within its own interface. Unlike traditional browser-based OAuth flows, IANA-AP delivers the authorization challenge to the agent in a structured, machine-readable format. The agent renders the challenge within its own interface, allowing the user to review the planned operations — including the tools to be invoked, the target resources, and the associated arguments — before explicitly approving them. Once approved, the agent completes the required authentication challenge without interrupting the conversational or terminal experience.</p><p>This phase is delegated to two existing specifications:</p><ul><li>OAuth 2.0 First-Party Applications (FiPA) defines the challenge/response flow. The agent submits the authorization request carrying the authorization_details to the Authorization Server.</li><li>OAuth 2.0 Agent Native Authorization (ANA) defines the structured elicitation format. When the Authorization Server receives the request, it returns HTTP 400 with error: insufficient_authorization and an elicitations array. The elicitations array carries a human-readable message summarizing the planned tool invocations and a requestedSchema that asks the user to select an authenticator.</li></ul><p>For more information about the specification, refer to the following Agent Native Authorization <a href="https://datatracker.ietf.org/doc/draft-embesozzi-oauth-agent-native-authorization/">proposal</a>.</p><p>The agent renders this challenge natively to the user. The user reviews the planned invocations and approves with a Passkey, a phishing-resistant FIDO credential unlocked using the device’s biometrics, PIN, or security key. The WebAuthn ceremony is performed in-band by the agent. On successful authentication, the Authorization Server issues a new token containing the approved authorization_details with the agent_intent entries.</p><p>The following shows how the agent presents the planned actions for the user to review:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DZxNLWXbyO3qk3S7I0wxKg.png" /></figure><p>The user then approves the planned actions with a Passkey gesture:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h40KmjffrvwGa6hVN2qE9g.png" /></figure><p>The issued token is not a broad credential. It is a cryptographically bound record of exactly which tools, on exactly which resources, with exactly which arguments the user chose to authorize.</p><p>This article focuses on the interactive case where the user is present and can approve the request directly from the agent experience. Because the architecture is built on open standards and composable authorization flows, the same pattern can be extended to Asynchronous Authentication with CIBA when the user is not currently present.</p><h4>Phase 4: Runtime Enforcement</h4><p>Receiving a token does not automatically authorize every future action. Every invocation must still match one of the approved operations from the token. This is what closes the gap between what the user approved and what the agent actually executes.</p><p>Approval alone is not sufficient. Every runtime invocation must still be verified before it executes. Runtime enforcement ensures that each tool call remains consistent with the authorization previously approved by the user.</p><p>In the simplified architecture shown in this article, the MCP server acts as the Policy Enforcement Point (PEP). It intercepts every tool call and delegates the authorization decision to a Policy Decision Point (PDP): remote via AuthZEN, or local via Cedar or OPA.</p><p><a href="https://openid.net/wg/authzen/">OpenID AuthZEN</a> is a standard that defines a vendor-neutral interface for fine-grained authorization decisions between a PEP and a PDP, enabling centralized policy governance across the agentic stack. Any AuthZEN-compliant PDP can be plugged in: Keycloak, Axiomatics, OpenFGA, and others.</p><p>In production architectures, a common recommendation is to place additional Policy Enforcement Points (PEPs) at gateway layers, such as AI gateways and API gateways, so authorization decisions can be enforced at multiple stages throughout the request lifecycle. This follows the Zero Trust principle of continuously verifying and enforcing authorization decisions rather than relying on a single enforcement point.</p><p>When the agent calls a tool with a Bearer token, the PEP:</p><ol><li>Validates the token (signature, expiry, audience)</li><li>Extracts the authorization_details claim and identifies the matching agent_intent entry for the current invocation</li><li>Extracts the SARC fields from the matching agent_intent entry and translates them into a PDP authorization request: when using AuthZEN, this is an Authorization API access request; when using a local engine such as Cedar or OPA, the same SARC fields are mapped to the engine’s native input format</li><li>On allow, executes the tool and returns the result; on deny, rejects the request</li></ol><p>A critical enforcement detail: the PEP compares the actual call arguments against the approved resource.properties.arguments carried in the agent_intent entry. The user approved a specific resource, not just a tool. If the token was approved for userId: alice and the agent calls with userId: bob, the PEP rejects the invocation. This closes the time-of-check to time-of-use gap at the resource level.</p><p>If no matching agent_intent entry exists for an invocation, the PEP can request just-in-time re-authorization following the Agent Native Authorization (ANA) framework.</p><h3>Putting It Together</h3><p>The previous sections described each phase independently. The following example shows how the four phases work together during a single user request. A user instructs the agent:</p><blockquote>Disable alice’s account, delete her data, and list all disabled users</blockquote><p>The agent has access to one MCP server (an Identity MCP Server) exposing three tools: disable_user, delete_user, and list_users, each with an x-authz-mapping.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qlDwef5m4XFLvZMr59yEPw.png" /></figure><p>The Intent Agent operates only in phases 1 and 2. It receives the tool definitions fetched from the Identity MCP Server in phase 1 (each with their x-authz-mapping) together with the user’s prompt, and produces the three agent_intent entries. From phase 3 onward it plays no further role. The Agent drives the authorization flow, and in phase 4 each tool call is intercepted by the PEP, matched against the corresponding agent_intent entry in the token, and verified via an AuthZEN access request before execution.</p><p>This is a simplified view of the flow. Here the Identity MCP Server is the visible PEP, because it is the component receiving the tool calls. In a production deployment, the same enforcement pattern can also be applied at gateway layers, such as an AI gateway or API gateway, so policy checks happen before traffic reaches the MCP server and at the service boundary.</p><h3>Reference Implementation</h3><p>The framework described in this post is not purely conceptual. The following demo shows an end-to-end prototype covering the full runtime authorization lifecycle: Agentic Profile discovery, authorization intent computation, user approval via Passkeys, OAuth Rich Authorization Requests, AuthZEN-based policy evaluation, and runtime enforcement across agent interactions.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F2IoPhwswXyE%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D2IoPhwswXyE&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F2IoPhwswXyE%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/98152dab32024659bf0e50d66bfb4019/href">https://medium.com/media/98152dab32024659bf0e50d66bfb4019/href</a></iframe><p>The implementation is built on <a href="https://twogenidentity.com/">TwoGenIdentity</a> components, including the TwoGenIdentity Agent Native Authorization (ANA) Framework and authorization gateways for coarse-grained and fine-grained authorization across the agentic stack. The agent orchestrator supports MCP, Agent-to-Agent (A2A), and MCP Apps protocols, with Keycloak as the Identity Provider extended with advanced authentication and authorization capabilities.</p><p>While the prototype demonstrates one concrete realization of IANA-AP, the framework is designed to remain implementation-agnostic and interoperable through open standards.</p><h3>Want to explore this topic further?</h3><p>This is a condensed version of the article. The complete version, including additional technical details, diagrams, and examples, is available on my personal blog:</p><p><a href="https://embesozzi.github.io/posts/martin-besozzi/intent-agent-native-authorization-agentic-profiles/">Applying Zero Trust to AI Agents with Intent Agent Native Authorization | Martin Besozzi</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b7a421f745e8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Secure APIs and AI Agents with Zero Trust and Fine-Grained Authorization Based on OpenID…]]></title>
            <link>https://embesozzi.medium.com/mastering-secure-apis-and-ai-agents-with-zero-trust-and-fine-grained-authorization-based-on-openid-c90cd6985721?source=rss-86e67d103504------2</link>
            <guid isPermaLink="false">https://medium.com/p/c90cd6985721</guid>
            <dc:creator><![CDATA[Martin Besozzi]]></dc:creator>
            <pubDate>Tue, 03 Feb 2026 18:04:52 GMT</pubDate>
            <atom:updated>2026-02-11T18:56:28.438Z</atom:updated>
            <content:encoded><![CDATA[<h3>Mastering Secure APIs and AI Agents with Zero Trust and Fine-Grained Authorization Based on OpenID AuthZEN</h3><p>A practical guide to standardizing authorization for APIs, MCP servers, and AI-powered interactive applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*jKMyDyIB5UTwXgDL22TGzQ.png" /></figure><p>This paper presents the results of extensive work. I decided to structure it around a single paper in which you determine the technology to protect, such as APIs, agents, or MCP/MCP Apps.</p><h4>Key Takeaways</h4><ul><li><strong>AuthZEN</strong> is an OpenID Foundation standard that defines how Policy Enforcement Points (PEPs) communicate with Policy Decision Points (PDPs)</li><li>It enables <strong>interoperable, fine-grained authorization</strong> across APIs, MCP servers, and AI applications without vendor lock-in</li><li>AuthZEN can operate as a <strong>complementary layer to OAuth 2.1</strong> handling fine-grained decisions that scopes cannot express</li><li>The same infrastructure supports <strong>multiple authorization models</strong>: ReBAC, PBAC, ABAC, or combinations</li><li>For <strong>MCP and MCP Apps</strong>, AuthZEN enables<strong> dynamic, context-aware authorization</strong> for AI tool invocations and interactive UI experiences</li></ul><p>Throughout this paper, we will illustrate AuthZEN concepts using our <a href="https://twogenidentity.com/homes/apisixauthzen/">AuthZEN Gateway</a>. This gateway serves as a implementation of AuthZEN-compliant Policy Enforcement Point, demonstrating how Zero Trust, externalized authorization can be applied consistently across APIs and AI Agents. Additional technical details about the gateway are provided where relevant to ground the discussion in real-world implementation.</p><p>Before diving into the more advanced concepts, it’s important to emphasize a core principle of this work: use <strong>open security standards</strong>. Avoid custom solutions and vendor-specific implementations that lead to lock-in.</p><p>This paper is deliberately grounded in open standards for that reason. While this section focuses in more detail on OpenID AuthZEN, it’s worth remembering that the foundation of MCP security also relies on the core OAuth 2.0 / OAuth 2.1 specifications (with more details in the conclusion).</p><h3>The Hardest Problem in Building Secure Platforms</h3><p>Authorization remains one of the most challenging and often underestimated aspects of building secure platforms. While authentication- proving who you are — has been largely solved through standards like OpenID Connect and passkeys (see the <a href="https://fidoalliance.org/">FIDO Alliance</a> for more information), authorization — determining what you can do — continues to fragment across proprietary implementations, homegrown solutions, and tightly coupled application logic.</p><p>The emergence of AI agents changes everything. With the Model Context Protocol (MCP), AI assistants can now dynamically discover and invoke arbitrary tools across multiple servers. MCP Apps extends this further, enabling interactive user interfaces delivered directly within AI conversations.</p><p>Traditional authorization approaches struggle with three fundamental problems:</p><p>1. Poor interoperability leading to vendor lock-in: Each authorization system speaks its own language, making it impossible to switch PDPs or integrate across platforms without significant rework.</p><p>2. Growing complexity that doesn’t scale: As systems expand, authorization rules multiply exponentially. Embedded logic becomes unmaintainable and inconsistent across services.</p><p>3. Tight coupling of authorization logic in application code: When policies live inside application code, every policy change requires development cycles, testing, and deployment, a recipe for security drift and technical debt.</p><p>The solution? AuthZEN an OpenID Foundation standard that finally addresses authorization interoperability.</p><h3>What is AuthZEN?</h3><p>The <a href="https://openid.net/wg/authzen">OpenID Foundation AuthZEN Working Group</a> has developed and approved the <a href="https://openid.net/specs/authorization-api-1_0-01.html">Authorization API version 1.0</a>. This is a stable version of a specification providing intellectual property protections to implementers — this is production-ready technology with industry backing.</p><p>AuthZEN standardizes the communication interface between Policy Enforcement Points (PEPs) and Policy Decision Points (PDPs). If you’re familiar with the XACML standard from years past, think of AuthZEN as its modern, REST-native successor — simpler, lighter, and designed for today’s distributed architectures.</p><p>The concept is elegant in its simplicity: instead of embedding authorization logic in every application, you externalize decisions to a dedicated policy engine. The PEP — whether it’s an API gateway, MCP server, or application component — asks the PDP a simple question: “Should this subject be allowed to perform this action on this resource?”</p><p>The PDP encapsulates all the complexity of policy evaluation. It might check role memberships, evaluate attribute conditions, traverse relationship graphs, or apply custom business rules. The PEP doesn’t need to know how the decision is made, it only needs to enforce the result.</p><h4>Core Benefits</h4><ul><li>Interoperability: Connect any AuthZEN-compliant PDP such OpenFGA, Cerbos or Alfa Axiomatics without changing application code</li><li>Decoupled authorization: Policy decisions separated from enforcement logic</li><li>Flexibility: Support multiple authorization models (ReBAC, PBAC, ABAC) with the same interface</li><li>Policy as code: Manage policies as versioned artifacts with audit trails</li><li>Dynamic evaluation: Runtime context evaluation for adaptive authorization</li></ul><h4>The AuthZEN Evaluation Request</h4><p>Every AuthZEN request follows a consistent structure with four primary components:</p><pre>{<br> &quot;subject&quot;: {<br>   &quot;type&quot;: &quot;&lt;subject_type&gt;&quot;,<br>   &quot;id&quot;: &quot;&lt;subject_identifier&gt;&quot;,<br>   &quot;properties&quot;: {}<br> },<br>  &quot;resource&quot;: {<br>    &quot;type&quot;: &quot;&lt;resource_type&gt;&quot;,<br>    &quot;id&quot;: &quot;&lt;resource_identifier&gt;&quot;,<br>    &quot;properties&quot;: {}<br> },<br>  &quot;action&quot;: {<br>   &quot;name&quot;: &quot;&lt;action_name&gt;&quot;,<br>   &quot;properties&quot;: {}<br> },<br>  &quot;context&quot;: {}<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*0t8LMpiW8ndkIk1JSqyOZw.png" /></figure><p>The PDP evaluates this request against its policies and returns a decision:</p><pre><br>{<br> &quot;decision&quot;: true<br>}</pre><p>Or:</p><pre>{<br> &quot;decision&quot;: false<br>}</pre><p>That’s it. A standardized question and a standardized answer. The complexity of policy evaluation, whether it involves checking relationships, evaluating attributes, or running policy rules, is entirely encapsulated within the AuthZEN PDP.</p><h3>API Security with AuthZEN</h3><p>Before diving into AI-specific scenarios, let’s establish how AuthZEN transforms API security. The pattern is straightforward: an API gateway acts as the PEP, intercepting requests, extracting context, and consulting the PDP before allowing operations to proceed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yuLYZ4AuJWz4jEBRf1fGRg.png" /></figure><p>The gateway extracts subject information from JWT claims, determines the resource and action from the HTTP request, and constructs an AuthZEN evaluation request. The PDP, whatever implementation you choose, evaluates the request and returns a decision.</p><h4>API Security PBAC Example: Policy-Based Access Control</h4><p>Consider a financial services requirement:</p><blockquote>Only admin users authenticated with a phishing-resistant authenticator can access confidential documents based on their roles and tenant</blockquote><p>A phishing-resistant authenticator, such as passkeys, is indicated by the <strong>acr</strong> (Authentication Context Class Reference) claim containing <strong>inherence</strong> and the <strong>amr</strong> (Authentication Methods References) claim containing <strong>passkeys</strong>.</p><p>Here’s how you’d configure the gateway plugin:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dv37wdihgUciU68qxY8XDQ.png" /></figure><p>When a request arrives, the gateway:</p><ol><li>Extracts preferred_username, roles, tenant, acr, and amr from the JWT</li><li>Builds an AuthZEN request with the resource set to the HTTP URI and action as the HTTP method</li><li>Sends the request to the AuthZEN PDP</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dv37wdihgUciU68qxY8XDQ.png" /></figure><p>4. AuthZEN PDP evaluates whether the policy allows the action for this user</p><p>5. The gateway enforces the decision</p><h3>MCP Security: Fine-Grained Authorization for AI Tool Invocation</h3><p>APIs are just the beginning. The Model Context Protocol (MCP) enables AI agents to discover and invoke tools dynamically across multiple servers. This introduces authorization challenges that OAuth scopes alone cannot address.</p><h4>Why OAuth Scopes Fall Short for MCP</h4><p>OAuth scopes operate at broad permission levels - read, write, admin. But MCP requires granular decisions:</p><ul><li>Can this user invoke fintech_approve_expense with amount $5000?</li><li>Can this analyst delete expenses, or only view and approve them?</li><li>Should step-up authentication be required for high-value operations?</li></ul><p>These questions involve runtime context, resource attributes, and complex policy logic that scopes cannot express.</p><p>Scopes are determined at token issuance time and cannot adapt to runtime context. A scope like expenses:write grants broad permission, but it cannot distinguish between approving a $100 expense and approving a $100,000 expense. It cannot enforce that analysts can only approve expenses in their assigned department. It cannot require step-up authentication for high-risk operations.</p><h4>AuthZEN as a Complementary Layer</h4><p>AuthZEN doesn’t replace OAuth. it complements it. OAuth handles coarse-grained authorization (CGA) through scopes and token validation. AuthZEN handles fine-grained authorization (FGA) through dynamic policy evaluation.</p><p>The flow for MCP:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M-AsM5si4ecVcE72j143ow.png" /></figure><p>The MCP server first validates the OAuth token (401 on failure). Then, it extracts context from JWT claims and the MCP request, builds an AuthZEN evaluation request, and queries the PDP. Only if the PDP returns “decision”: true does the server execute the requested tool.</p><h4>MCP Security: Expense Approval</h4><p>In this example we are going to configure the gateway to supports dynamic MCP request mapping:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QNQgeIzV85dFTLD9mM8iSw.png" /></figure><p>Key features:</p><ul><li><em>mcp::tool::name:</em> Dynamically extracts the tool name from the JSON-RPC body</li><li><em>mcp::tool::arguments:&lt;name&gt;</em>: Extracts specific tool arguments</li><li><em>enforce_on.methods</em>: Configures which MCP methods trigger policy enforcement</li></ul><p>So, given this MCP request:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hynNtTIlAlfwd9FkAbSJoA.png" /></figure><p>And a JWT containing:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1v3BcZNWtINoBZ5Ew5vmng.png" /></figure><p>The gateway constructs this AuthZEN request:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qLn0Am3KSs3MAKMFV32G7Q.png" /></figure><p>The PDP can now evaluate complex policies: Is this user an analyst? Are they authenticated with a phishing-resistant authenticator? Is the amount within their approval limit? Is the expense in their assigned department?</p><p><strong>Important</strong>: The MCP Mapping described above is non-normative and provided as an illustrative example. The OpenID Foundation AuthZEN Working Group intends to define an AuthZEN Profile for MCP to standardize this mapping as an extension of the AuthZEN specification.</p><p><strong>Considerations:</strong></p><ul><li><strong>Subject sources</strong>: While this example derives subject information from JWT claims, AuthZEN is flexible about subject sources. Depending on your deployment architecture, subject information can come from other sources — the key is that the PEP constructs a consistent AuthZEN request regardless of where the data originates.</li><li><strong>PDP data enrichment</strong>: The AuthZEN PDP is not limited to the data provided in the evaluation request. The PDP can retrieve and incorporate external data sources (user directories, relationship graphs, resource metadata) when making policy decisions. This enables sophisticated authorization scenarios without bloating the evaluation request.</li></ul><h3>MCP Apps: Securing Interactive AI Experiences</h3><p>MCP Apps (Model Context Protocol Apps Extension — SEP-1865) represents a paradigm shift in how AI agents interact with users. While base MCP standardizes tool invocation, MCP Apps extends this to deliver interactive user interfaces directly within AI conversations.</p><p>Think about what this means: instead of text-only responses, AI assistants can render forms, dashboards, buttons, and interactive elements. Users can approve expenses, view charts, click actions , all within the AI conversation flow. The AI host (Claude, Copilot or other compatible clients) renders rich UI components directly in the conversation.</p><p>This changes everything about authorization. It’s no longer just about whether a user can invoke a tool, it’s about whether they can see certain UI elements, click specific buttons, and perform interactive actions.</p><h4>Why MCP Apps Changes the Authorization Game</h4><p>Traditional MCP authorization answers: “Can this user invoke this tool?” MCP Apps requires answering more nuanced questions:</p><ul><li>Can this user see the “Delete” button in the expense dashboard?</li><li>Should the “Approve” button be enabled for expenses over $10,000</li><li>What happens when an unauthorized action is attempted through the UI?</li></ul><p>The authorization flow remains the same, AuthZEN evaluation requests to a PDP, but the integration with interactive UI elements creates a more responsive user experience. Users receive immediate feedback about what they can and cannot do, rather than encountering errors after attempted actions.</p><h3>Security MCP App: Fintech Expense Management</h3><p>Consider a financial services company deploying an AI-powered expense management system:</p><ul><li>AI assistants help employees manage expenses through natural conversation</li><li>Interactive dashboards display expense lists with action buttons (not just text)</li><li>Policy-driven access controls who can view, approve, and delete expenses</li></ul><p>The security requirements:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Doev8QmffUdUkNeHH3GR5w.png" /></figure><p>Additionally, all users must authenticate with a phishing-resistant authenticator (passkeys).</p><h4>Case 1 MCP App: View Expenses as Analyst</h4><p>a) User prompt: “Please list the expenses”</p><p>b) AI Assistant action: Calls fintech_list_expenses tool</p><p>c) MCP Gateway flow:</p><ul><li>Extracts JWT claims (sub, roles, acr, amr)</li><li>Retrieves the MCP tool name from the JSON-RPC body</li><li>Verifies the method is tools/call</li><li>Sends AuthZEN evaluation request to PDP</li><li>PDP evaluates: User is analyst, authenticated with passkeys, action is list → ALLOW</li><li>Gateway forwards request to MCP Server</li></ul><p>Result: User sees an interactive expense dashboard with action buttons (Approve, Delete)</p><h4>Case 2 MCP App: Approve Expense as Analyst</h4><p>a) User action: Clicks “Approve” button on expense #123 in the MCP Apps UI</p><p>b) AI Assistant action: Calls fintech_approve_expense(123)</p><p>c) MCP Gateway flow:</p><ul><li>Same context extraction process</li><li>AuthZEN request with action fintech_approve_expense</li><li>PDP evaluates: User is analyst, authenticated with passkeys, action is approve → ALLOW</li><li>Gateway forwards request</li></ul><p>Result: Expense approved, user sees success confirmation in the interactive UI</p><h4>Case 3 MCP App: Delete Expense as Analyst</h4><p>a) User action: Clicks “Delete” button on expense #123</p><p>b) AI Assistant action: Calls fintech_delete_expense(123)</p><p>c) MCP Gateway flow:</p><ul><li>Same context extraction</li><li>AuthZEN request with action fintech_delete_expense</li><li>PDP evaluates: User is analyst (not admin), action is delete → DENY</li><li>Gateway returns 403 Forbidden</li></ul><p>Result: User sees error message “You don’t have permission to delete expenses”</p><p>The MCP Apps UI can render this gracefully, showing a contextual error message when the action is attempted.</p><h4>Live Demo:</h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FwegISLqGKF4%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DwegISLqGKF4&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FwegISLqGKF4%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/dcd4187d0d901095e411cf294cce04fe/href">https://medium.com/media/dcd4187d0d901095e411cf294cce04fe/href</a></iframe><h3><strong>Multi-Layer Security Architecture</strong></h3><p>Enterprise MCP deployments typically involve multiple PEPs at different trust boundaries:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Os0QtjjTAZv7F2wKlM3rSw.png" /></figure><p>Here is an implementation in which PEP #1 (an AuthZEN MCP Gateway) enforces authorization at the MCP layer by communicating with an AuthZEN PDP, and PEP #2 (an API Gateway) enforces fine-grained, resource-level policies closer to the API.</p><p>The MCP server and the API can also act as AuthZEN PEPs, and you can use multiple AuthZEN PDPs with different authorization models. Additionally, you can combine CGA at the MCP/Gateway level with FGA applied deeper in the request journey.</p><h3>Zero Trust Architecture for AI Applications</h3><p>The patterns described throughout this article align with Zero Trust principles: never trust, always verify. Every request, whether from a human user or an AI agent, must be explicitly authorized based on all available context.</p><h4><strong>Benefits of AuthZEN for AI Security</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8IsasDMrnAT2cQIFjbc-Ew.png" /></figure><h4><strong>Policy as Code and Governance</strong></h4><p>Once AuthZEN is adopted, organizations should follow a policy-as-code approach:</p><ul><li>Store policies in version control alongside application code</li><li>Apply code review processes to policy changes</li><li>Test policies in staging environments before production deployment</li><li>Implement policy governance workflows for sensitive changes</li><li>Maintain audit logs of policy decisions for compliance</li><li>The AuthZEN standard makes this possible by separating policy definition (in the PDP) from policy enforcement (in the PEP).</li></ul><h3>Conclusion</h3><p>Authorization is heading in a clear direction: standardized, decoupled, and interoperable. The OpenID Foundation AuthZEN specification provides the foundation for this transformation, and AI applications, with their dynamic, context-rich interactions. are accelerating the need for adoption.</p><p>The patterns demonstrated in this paper work today:</p><ul><li>API Security: Deploy an AuthZEN-compliant gateway PEP in front of your APIs</li><li>MCP Security: Extend the same gateway to handle MCP tool invocations with dynamic context extraction</li><li>MCP Apps Security: Secure interactive AI experiences with fine-grained, policy-driven authorization</li></ul><p>Thanks to interoperability, the sky is the limit.</p><p>What excites me most about this direction is how it changes the conversation around AI security. Instead of debating whether AI agents are “safe enough” to deploy, we can focus on building the right policies and enforcing them consistently. The authorization is the core product, not a secondary feature.</p><p>If you’re building AI-powered applications today, consider how AuthZEN can simplify your authorization architecture. The specification is stable, implementations are available, and the patterns work across both traditional APIs and emerging MCP-based AI workflows.</p><p><strong>Important Personal View:</strong> When you talk to AI security “experts”, you’ll hear about lots of custom implementations, please don’t go down that road. I firmly believe in <strong>open security standards</strong>, which is why this entire approach is based on them. See below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*esWrsejtMEx56vax" /></figure><p>If you’re curious about implementing AuthZEN for your API or AI applications, or want to discuss MCP Apps security patterns, open security standards, I’d be happy to connect.</p><h4>Other Related Articles</h4><p>[a] <a href="https://www.linkedin.com/pulse/bringing-authzen-oss-space-apache-apisix-martin-besozzi-6ve4f">AuthZEN: Standardized Authorization for API and AI Security</a></p><p>[b] <a href="https://www.linkedin.com/pulse/securing-mcp-apps-authzen-fga-interactive-ai-martin-besozzi-tqtkf">Securing MCP Apps with the AuthZEN MCP Gateway: Fine-Grained Authorization for Interactive AI Experiences</a></p><p>[c] <a href="https://www.linkedin.com/pulse/security-design-securing-our-keycloak-mcp-app-authzen-martin-besozzi-zu5me">Agentic AI Security: Protecting Interactive Keycloak MCP App with OpenID AuthZEN Gateway for FGA</a></p><p>[d] <a href="https://twogenidentity.com/blog/">TwoGenIdentity - Security Blog</a></p><h4>References</h4><p>[1] <a href="https://openid.net/wg/authzen/">OpenID Foundation AuthZEN Working Group</a></p><p>[2] <a href="https://openid.net/specs/authorization-api-1_0-01.html">AuthZEN Authorization API 1.0</a></p><p>[3] <a href="https://twogenidentity.com/homes/apisixauthzen">TwoGenIdentity API/AI AuthZEN Gateway</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c90cd6985721" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Agentic AI Platform for Enterprise IAM: Secure Agent-Driven Governance Based on Zero-Trust…]]></title>
            <link>https://embesozzi.medium.com/agentic-ai-platform-for-enterprise-iam-secure-agent-driven-governance-based-on-zero-trust-289a52f42790?source=rss-86e67d103504------2</link>
            <guid isPermaLink="false">https://medium.com/p/289a52f42790</guid>
            <category><![CDATA[keycloak]]></category>
            <category><![CDATA[agentic-ai]]></category>
            <category><![CDATA[mcp-server]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[ai-agent]]></category>
            <dc:creator><![CDATA[Martin Besozzi]]></dc:creator>
            <pubDate>Sat, 07 Jun 2025 21:13:36 GMT</pubDate>
            <atom:updated>2025-10-17T13:29:32.289Z</atom:updated>
            <content:encoded><![CDATA[<h3>Agentic AI Platform for Enterprise IAM: Secure Agent-Driven Governance with Keycloak MCP, Based on Zero-Trust Principles and Fine-Grained Authorization - From Vision to Implementation</h3><p>The advent of Agentic AI platforms marks a significant leap in enterprise automation and intelligence. These platforms leverage AI Agents - software systems that use Artificial Intelligence (AI) to pursue goals and complete actions on behalf of users. At their core, these agents utilize large language models (LLMs) as reasoning engines. The ability of AI Agents to dynamically access and execute external tools and resources is facilitated thanks to the Model Context Protocol (MCP), an open protocol that enables AI Agents to interact with and access external tools and resources. While incredibly powerful, this capability also introduces new and complex security risks.</p><p>At <a href="https://twogenidentity.com/">TwoGenIdentity</a>, our journey began with an interactive AI Agent scenario - an exploration of how agents can act on behalf of users in enterprise environments. We then introduced our broader vision: the Agentic AI Platform, combining identity, security, and open standards.</p><p>Now, we bring it all together to showcase how our <a href="https://twogenidentity.com/homes/identityaccessplus">Agentic AI Identity Access Plus Platform</a>, powered by the Oryon Agent, enables real-world implementations that follow open standards, enforce robust security, and elevate the user experience. This isn’t just theory -it’s a fully operational solution designed to address the growing complexity of enterprise Identity and Access Management (IAM).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UzJTq54_-Ku3UpK49VH6MQ.png" /><figcaption>Agent AI Identity Access Plus | Oryon AI Agent</figcaption></figure><p>In this scenario, the AI agent is integrated with our <a href="https://twogenidentity.com/homes/mcp/">Keycloak MCP Server</a>, enabling it to take secure actions within the IAM platform. This is made possible by our MCP server’s support for open standards and fine-grained authorization policies. With this integration, you can govern your IAM platform simply by chatting with the agent. We’ll cover more details about the Keycloak MCP Server in a separate article.</p><p>What makes our approach innovative is the agent’s ability to orchestrate IAM processes, enforce dynamic authorization policies in real time, and control the authentication flow — what we call the OAuth Ceremony to strengthen security during critical operations. By integrating native passkey support and step-up authentication, we create a seamless and secure experience for users, all while maintaining full alignment with enterprise IAM standards and open protocols.</p><p>In my view, we often overcomplicate things by introducing too many new concepts and complex standards — ones that may work well in theory but are difficult to implement in practice. That said, such standards can be valuable in complex scenarios, as long as we clearly define those scenarios. My approach is to keep things as simple as possible when the context allows. In this article, we shift from theory to practice in an enterprise context. We’ll demonstrate how open standards can be effectively used to build a secure Agentic AI architecture.</p><p>While we use our own platform in the demonstration, the core concepts are transferable and can be applied to your own AI framework as well.</p><h3>Beyond Vision: What We Want to Enhance</h3><p>Building an AI-driven platform for enterprise use is not just about having a powerful agent or just talking about MCP - it’s about doing it right: securely, scalably, and in alignment with existing enterprise policies and standards. To provide a complete picture, we implement all the AI components, ensuring we have the tools to apply access control at every step of the AI journey.</p><p>Our implementation focuses on:</p><ul><li>Adhering to open standards such as OAuth 2.0 and OpenID Connect.</li><li>Enabling dynamic, real-time authorization.</li><li>Following OpenID AuthZen Guidelines for decoupling authorization and policy as code.</li><li>Enforcing fine-grained policies based Relationship-Based Access Control (ReBAC).</li></ul><p>Innovations introduced through <a href="https://twogenidentity.com/">TwoGenIdentity</a> AI and IAM components include:</p><ul><li>Oryon, our AI agent, operates within an agentic framework to orchestrate authentication and dynamic authorization flows, delivering enhanced security and user experience through native authentication with passkeys. This approach leverages API-based authentication based on OAuth 2.0 for First-Party Applications, where the application controls the login experience and dynamically requests higher levels of assurance using information from the Identity Provider.</li><li>Implement and enforce security at multiple stages of the AI journey using multiple Policy Enforcement Points (PEPs) across different layers of the AI ecosystem. Adopt a Zero-Trust-Ready Architecture that supports identity-centric Zero Trust principles, including continuous verification, least-privilege access, and adaptive security.</li></ul><p>Some of the topics — such as decoupling authorization and policy as code, Fine-Grained Authorization (FGA), and native authentication with passkeys — are subjects I’ve covered in conferences and written about. If you’d like to learn more, you’ll find references at the end of this article.</p><h3>Understanding the Agentic AI Ecosystem in the MCP scenario (The Theory)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*2CDHEw-WfLHvp9cpmIejvA.png" /><figcaption>MCP Architecture</figcaption></figure><p>To securely expose your Agentic AI ecosystem, it’s essential to have a clear understanding of all the components involved. In an Agentic Platform focused on implementing MCP, you typically have the following elements - I’m not going into the details, as there is already a lot of information available on this topic:</p><ul><li>The end user who interacts with the Agentic AI Platform (MCP Host) and the AI Agent.</li><li>MCP Host: The local execution environment where the AI Agent operates and interacts with the AI model and the MCP server.</li><li>AI Agent: The software agent that orchestrates actions, decides when to use tools, and manages conversations or workflows based on context.</li><li>AI Model: the language model instance used for generating responses or processing user input.</li><li>MCP Client (Remote): A module within the MCP Host that connects to a remote MCP Server. It fetches tools, resources, and prompts defined remotely for dynamic use.</li><li>LLM Service: An external service providing access to large language models (LLMs). The AI Model communicates with this service to generate text-based responses.</li><li>MCP Server: The remote service that stores and manages tools, resources, and prompts used by the AI Agent.It acts as a backend to extend the agent’s capabilities.</li><li>MCP: is an open protocol that standardizes how applications provide context to LLMs.</li><li>API: The interface used by the MCP Server to access data sources and resources — such as databases, knowledge graphs, or RESTful services.</li></ul><p>Before jumping into our scenario, it’s worth noting that the MCP Base Protocol now includes an Authorization section that recommends using OAuth 2.1. This provides a solid foundation to build upon. As a result, you’ll encounter several technical concepts related to the OAuth 2.1 standard.</p><p>Here is a great <a href="https://aaronparecki.com/2025/04/03/15/oauth-for-model-context-protocol">article</a> by <a href="https://www.linkedin.com/in/aaronparecki/">Aaron Parecki</a> that clarifies the roles of the OAuth 2.0 Authorization Server and Resource Server in the MCP scenario, which will be used as a pillar here. So, check it out if those roles aren’t clear to you.</p><p>Just to provide a bit of context before we continue, OAuth is an access delegation standard that enables an application (such as a service or agent, in our case) to securely obtain temporary permission to access a user’s resources without the user needing to share their actual credentials. After successful authentication, the Identity Provider issues a temporary access token to the application, allowing it to act on the user’s behalf securely and within a limited scope.</p><h3>Our IAM Enterprise Scenario: Interactive AI Agent in a Single-Trust Domain</h3><p>In the broad landscape of AI agents, many different scenarios exist. We specifically focus on one critical enterprise scenario: the interactive AI agent acting on behalf of the user to execute operations using enterprise tools, all within a single-trust domain in a first-party context. This means the enterprise retains full control over all AI components.</p><p>This particular scenario addresses key enterprise requirements and concerns:</p><ul><li>No Dependency on third-party MCP Hosts or AI Agents: In some cases Enterprises do not want to rely on third-party MCP Hosts such as Claude, Cursor, or VS Code Copilot, especially those using fixed bearer tokens or static authorization. Instead, they want to deploy and manage their own Agents and MCP servers within their enterprise environment or private cloud.</li><li>Integration with Enterprise Identity Providers (IdPs): MCP servers and AI agents must integrate seamlessly with the enterprise’s existing Identity Provider (e.g., Keycloak, Azure AD, Okta) using open standards like OAuth 2.0 or OIDC. This ensures that authentication and authorization flows are consistent with corporate security policies.</li><li>Full Control Over Agents and LLMs: Enterprises demand complete control over which AI agents and LLM models are deployed, updated, and used.</li><li>Add Layers of Fine-Grained Authorization (FGA) and dynamic authorization policies at multiple points.</li></ul><p>To provide further clarity for this case, we will outline some key premises relevant to this specific scenario. While many scenarios exist, these premises are crucial for real-world implementation, as we will guide you on a case-by-case basis. We will also introduce some technical aspects, which we will explain in more detail later</p><p>a) First-Party Scenario within a Single Trust Domain: The enterprise controls and owns the MCP Host, Agent, MCPs, and Identity Provider. This classification approach was introduced by <a href="https://www.linkedin.com/in/gffletch">George Fletcher</a>, along with other members, during discussions of AI topics in the context of <a href="https://idpro.org/">IDPro</a>. If you want to know more about the delegation scenario, you MUST follow him, as he often publishes interesting articles about it.</p><p>b) Single Agent, Single MCP Server: To simplify this case we have a single Agent that initializes the MCP Client, which communicates with one MCP Server, all operating within the same trust domain.</p><p>c) Interactive AI Agent acting on behalf of a User: The interactive AI Agent acts on behalf of a user. In an access delegation scenario, OAuth 2.0 will be instrumental, as its fundamental purpose is to facilitate access delegation, and we can leverage scopes for granular access control. The MCP Base Protocol now includes an Authorization section that specifically recommends OAuth 2.1, thereby providing a robust foundation for this.</p><p>f) AI Agent manages the authentication ceremony (OAuth 2.0 flow) in coordination with the Agentic AI Portal, to handle dynamic authorization. Identity Propagation via digital tokens is crucial for a secure and efficient interaction. It ensures that once you’ve successfully authenticated and authorized your access, your identity and granted permissions seamlessly follow your requests across the system. This not only verifies who you are to the MCP Server but also enforces exactly what you’re allowed to do.</p><p>What we leave behind:</p><ul><li>This is explicitly not an agent-to-agent (A2A) scenario; we are dealing with a single Agent and a single MCP Server within one trust domain.</li><li>There is only one Identity Provider (IdP) involved; we avoid multi-IdP complexity.</li><li>We aim to avoid unnecessary architectural complexity and minimize the number of calls within the AI flow — no 100+ round trips! The goal is to keep things as simple and efficient as possible.</li></ul><p>Once we’ve explained the basics of this case, we can use the same framework to extend it to other scenarios as well.</p><h3>Agentic AI Identity Access Plus Platform: Elevating Enterprise Security Through Innovation</h3><p>Our Agentic AI Identity Access Plus Platform directly addresses these pain points by offering a unified, intelligent, and highly secure environment for your enterprise applications and AI agents. We demonstrate a real-world implementation of how we securely approach this, focusing on an interactive AI Agent in a single-domain first-party scenario where the enterprise maintains full control over all AI components.</p><p>Here’s how we transform the current scenario:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NNR58_fqAtSbPOKWF2-fQQ.png" /><figcaption>Agentic AI Identity Access Plus Platform Diagram</figcaption></figure><h4>Agentic AI Identity Access Plus Platform</h4><p>The Agentic AI Identity Access Plus Platform is an enterprise-grade solution built on a robust foundation, offering complete control over AI agents. This unified platform addresses all your identity needs — streamlining operations, maximizing revenue, and enhancing security with AI-powered agents. It delivers advanced Identity Governance and Administration (IGA) capabilities through our intelligent AI Agent.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9FpIfQ9EI5NaHtVz" /><figcaption>Agentic AI Identity Access Plus Platform | TwoGenIdentity</figcaption></figure><h4>AI Agent (Oryon)</h4><p>At the heart of our platform is our proprietary Oryon AI Agent, which intelligently orchestrates security policies and understands the security policies. Oryon is fully integrated with the Keycloak MCP Server, enabling natural language interaction with Keycloak through secure protocols like OAuth 2.0 and the Model Context Protocol (MCP). This proactive intelligence is crucial for maintaining a strong security posture in dynamic enterprise environments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z1cGGqzbl1vuGATssu2ORA.png" /><figcaption>Oryon Agent connect with Keycloak MCP</figcaption></figure><p>As shown below, Oryon is able to detect interactive OAuth error responses from the MCP server to trigger additional actions -such as step-up authentication or just-in-time authorization step — to enforce dynamic authorization.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b5uec6qclI1H9eeTjVF3DQ.png" /><figcaption>Oryon Agent Conversation Ceremony</figcaption></figure><h4>IAM Keycloak MCP Server Integration</h4><p>In our scenario, we use the <a href="https://twogenidentity.com/">TwoGenIdentity</a><strong> Keycloak MCP Server </strong>as a reference implementation, but the approach can be extended to other MCP servers as well. Keycloak is an open-source identity and access management solution, and thanks to the MCP standard, we are exposing the tools for managing and monitoring the platform to the Agent.</p><p>The MCP Server enforces access control rules for features such as step-up authentication and supports integration with <a href="https://openfga.dev/">OpenFGA</a> to enable fine-grained authorization (FGA) and enhance security through Relationship-Based Access Control (ReBAC) policies.</p><p>It also includes support for approximately 31 Keycloak tools, spanning key areas like User, Client, Authentication Flows, Roles, Groups, Organizations, Events, and Cache Management, and we continue to evolve it. We thank to <a href="https://www.linkedin.com/in/osorionicolas95/">Nicolas Osorio</a> for participating in the evolution of this component.</p><h4>Keycloak Authentication / Authorization Extensions</h4><p>At <a href="https://twogenidentity.com/">TwoGenIdentity</a>, we developed and maintained custom extensions (SPI ) to extend capabilities to the Keycloak platform to enhance both security and user experience (UX) by adopting the latest open standards, including Native Authentication with Passkeys. We also provide the OpenFGA Event Publisher Keycloak extension, which synchronizes authorization-relevant data between Keycloak and OpenFGA models -enabling seamless integration for the Fine-Grained Authorization (FGA) step.</p><h3>Simplified Agentic AI Flow</h3><ol><li>User Authentication (User → Agentic AI Portal): The user logs in to the Agentic AI Portal (MCP Host) via OpenID Connect (OIDC).</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_3ir8eXDq8El8eAo" /><figcaption>Agentic AI Identity Access Plus Login | TwoGenIdentity</figcaption></figure><ul><li>During this process, the user gives consent for certain tools or capabilities to be accessed on their behalf by an Agent [AC1].</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J73w4Vvet1Yui9977Xu6Zw.png" /></figure><p>2. User to Agentic AI Portal (Agentic AI Portal → Agent API): Opens an AI Agent and requests an action based on the available tools.</p><ul><li>The Agentic AI Portal communicates with an Agent using an OAuth 2.0 access token, treating the Agent API as a OAuth 2.0 Resource Server.</li><li>In this step we are applying access control based scoped and filtering the tools more the details in the next steps [AC2].</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4dImMSiUnGmkmtz3" /><figcaption>Oryon Agent Chat | TwoGenIdentity</figcaption></figure><p>3. Oryon Agent to MCP Server (MCP Client → MCP Server): The Agent initializes the MCP Client with an access token to call the MCP Server.</p><ul><li>The MCP Server acts as an OAuth 2.0 Resource Server that exposes the tools the Agent needs.</li><li>Access token validation includes checking the required scope or identity claim for the tool to be executed [AC3].</li><li>In this case, we can apply step-up or just-in-time authentication for executing critical tools if an interactive OAuth response is present [AC4]. See the diagrams below.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IdBLcEhqB6nkuy1DzOEZIg.png" /><figcaption>AI Agent Step-Up or JIT Authorization Ceremony</figcaption></figure><ul><li>[A] User: Human prompt related to tools execution</li><li>[B] Agent: LLM prompt resolution and tool (MCP) selection</li><li>[C] Agent (MCP client): Sends an MCP request for the specified tool</li><li>[D] MCP Server: Returns an OAuth step-up response when the required authentication level is not met.</li><li>[E] Agent: Detects when an interactive OAuth response is present and triggers an interruption to request step-up authentication.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6jbTVVD8T_kUSAPb" /><figcaption>Oryon AI Agent</figcaption></figure><ul><li>[F] Agentic AI Portal: The OAuth ceremony is initiated by the Agentic AI Portal (MCP Host) thanks to the information of the AI Agent. This is why we are able to secure the process while at the same time enhancing the user experience with native authentication.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZnSKzrNzodROsZQV" /></figure><ul><li>The resulting tokens are then propagated across the AI components (Agents and MCPs). These new tokens meet the security requirements of the MCP server.</li></ul><p>4. MCP to FGA (MCP → FGA): The MCP can perform authorization checks based on a ReBAC policy in the context of the authenticated user, verifying whether the user has a direct or implied relationship with a specific tool. For example, to simplify our scenario, we used a roles model that links business roles to technical roles associated with the tools used by the client representing the MCP server.</p><h3>Deep Dive: Distributed Access Control Across in Agentic AI Components</h3><p>In this section, we combine the core concepts of securing access to the Agentic AI components, the distributed enforcement of access control levels (PEPs), and concrete use cases demonstrating these mechanisms in action. By doing so, we present a cohesive and practical framework for implementing layered security in the Agentic AI platform.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OlRJ3P6Lq-7nT0gsAqepRA.png" /><figcaption>Agentic AI platform Distributed Access Control</figcaption></figure><h4>Access Control Architecture Overview</h4><p>Our implementation follows a multi-layered approach, where Policy Enforcement Points (PEPs) are deployed across different AI components. These components include the Agentic AI Portal, the AI Agent (Oryon), and the MCP Server. This architecture allows fine-grained and dynamic authorization enforcement tailored to each context.</p><p>We adopt the AuthZEN Working Group P*P architecture model:</p><ul><li>Authentication Server (AS): Keycloak acts as the OAuth 2.1 Authorization Server.</li><li>Policy Decision Point (PDP): OpenFGA evaluates authorization decisions based on ReBAC / ABAC policies.</li><li>Policy Enforcement Points (PEP): Distributed in the Agent, MCP, and portal.</li></ul><p>Simplified OAuth 2.1 role mappings:</p><ul><li>Enterprise Identity Provider → OAuth 2.0 Authorization Server.</li><li>MCP Host (Agentic AI Portal) → OAuth 2.0 Client.</li><li>AI Agent → Trusted component.</li><li>AI Agent API and MCP Server → OAuth 2.0 Resource Servers.</li></ul><p>Each component applies access control as follows:</p><p><strong>Access Delegation</strong></p><ul><li>[AD-AC1] User: gives consent to the agent based scopes.<br>[AD-AC2] Agent: Policy Enforcement Point (PEP) is used for tool filtering.</li><li>[AD-AC3] MCP Server: Enforces PEP-based scopes or claims for each tool.</li></ul><p><strong>Dynamic Authorization</strong></p><ul><li>[DA-AC4] MCP Server: Makes real-time access decisions based on identity claims (such as acr and amr), triggering an OAuth 2.0 step-up error response.<br>The OAuth 2.0 flow is orchestrated by the AI agent. Step-up authentication is performed using OIDC and OAuth 2.0 for First-Party Apps (FiPA), implemented by the Agentic AI Portal to ensure a secure and seamless user experience.</li></ul><p><strong>Fine-Grained Authorization (FGA)</strong></p><ul><li>[AD-AC3] MCP Server: FGA based ReBAC (Relationship-Based Access Control) policies acting as Policy Decision Point (PDP) integrated with OpenFGA, following the principles of decoupled authorization as defined by the AuthZEN Working Group.</li></ul><h4>Diagram Walkthrough: Applying Access Controls in Practice</h4><p><strong>Case 1: Agentic AI → View IAM User Details</strong></p><p>Here, the user logs into the Agentic AI Portal and chats with the Oryon AI Agent to list IGA users.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*A9_hohG3IqYOw5Gm" /><figcaption>Diagram Agentic AI View IAM User Details</figcaption></figure><p><strong>Case 2: Agentic AI → Delete IAM User</strong></p><p>The user initiates a chat with the Oryon AI Agent to delete the IGA user Peter Michael. The MCP Server identifies insufficient assurance and responds with an OAuth step-up challenge. The Oryon Agent triggers a native biometric login (passkey), required for this critical operation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OYJBQpc-g2tmhL7P" /><figcaption>Diagram Agentic AI Delete IAM User</figcaption></figure><h4>Agentic AI Platform: Built on Open Standards</h4><p>The standards we build upon any secure Agentic AI implementation should follow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sUjNHQdPS8axH0ionFglQg.png" /><figcaption>Open Standards</figcaption></figure><ul><li>OAuth 2.0 / OAuth 2.1 (RFC 6749).</li><li>OpenID Connect (OIDC).</li><li>Bearer Token Usage (RFC 6750).</li><li>Step-Up Authentication Challenge Protocol (RFC 9470).</li><li>Authentication Method Reference (RFC 8176).</li><li>OpenID AuthZEN specs.</li><li>FGA with ReBAC based Zanzibar approach.</li></ul><p>What we leave behind for this case:</p><ul><li>There is no need for Dynamic Client Registration, as this is a first-party scenario, and the enterprise controls all OAuth 2.0 components, allowing clients to be pre-registered.</li><li>No need for Token Exchange (RFC 8693), as all components operate within a single trust domain, meaning the AI Agent does not require its own OAuth client or token translation.</li><li>No need for OAuth 2.0 Rich Authorization (RAR) → No need more complex things in the scenario we use FGA with ReBAC and ABAC features.</li><li>No need for OAuth 2.0 Protected Resource Metadata (RFC 9728), as the MCP servers and their capabilities are known and managed internally.</li><li>No need for Identity Assertion Authorization Grant or cross-IdP SSO, as we are not dealing with multiple Identity Providers or trust domains; a single IdP is used in this case.</li></ul><p>Just to clarify, for the purposes of this scenario, we are not using these standards. In future articles, as we explore additional AI scenarios, we’ll introduce them within our Agentic AI Framework where appropriate.</p><h3>Showcasing the Agentic AI Identity Access Plus Platform</h3><p>As described earlier, access will be granted through our Agentic AI Identity Access Platform. In this showcase, you’ll see the Oryon AI Agent in action, performing real-world IAM tasks:</p><p>🔐 Integration with our Keycloak MCP Server to manage the platform<br>🤖 Oryon AI-driven execution of:<br> a) 🧑‍💻 Listing all Keycloak users<br> b) 🧑‍💻 Retrieving Keycloak user details<br> c) 🧑‍💻 Deleting a Keycloak user (biometric login required)</p><p>In step c), things get more interesting: Oryon detects the need for step-up authentication or just-in-time authorization step, which is triggered by the MCP Server. It automatically initiates a native passkey flow within our Agentic AI Identity Access Plus platform. No redirects. No pop-ups. Just a secure, seamless user experience. This is a preview of what an AI Agent done right looks like — secure by design, user-friendly by default.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fh7gQoCKnym8%3Fstart%3D4%26feature%3Doembed%26start%3D4&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dh7gQoCKnym8&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fh7gQoCKnym8%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/13e837884bffce2f2fd8740102c000c1/href">https://medium.com/media/13e837884bffce2f2fd8740102c000c1/href</a></iframe><h3>Wrapping Up: From Vision to Execution</h3><p>What began as a theoretical vision for a secure, agent-driven enterprise platform has now become a reality. Through our <a href="https://twogenidentity.com/homes/identityaccessplus">Agentic AI Identity Access Plus Platform</a>, we demonstrated how enterprises can implement secure, standards-based access control across every layer of the AI agent flow — without compromising user experience.</p><p>By leveraging open protocols such as OAuth 2.1 and the AuthZEN guidelines, we’ve implemented distributed access control through dynamic Policy Enforcement Points (PEPs) and integrated fine-grained authorization using Relationship-Based Access Control (ReBAC).</p><p>Our innovation, Oryon, enables dynamic authorization at every step of the AI agent flow, enhancing security in line with Zero Trust principles.</p><p>Agentic AI platforms are more than just hype — they represent a real opportunity. With the right identity and access strategy, they can unlock new levels of productivity, transparency, and control. As always, the key is not just building intelligent agents, but ensuring those agents act securely, transparently</p><p>We’re excited to be part of this next chapter in identity innovation — and we’d love to hear from you. Whether you’re exploring agentic AI platforms, modern access control, or just beginning your journey, <a href="https://twogenidentity.com/">TwoGenIdentity</a> is here to help.<br>Let’s stay connected: follow us for insights, reach out with questions, or collaborate on building secure, user-centric identity solutions that scale with your needs. If you’re working on your own implementation, we hope this article provides a strong starting point — and we’re always open to connecting.</p><p>Last but not least, if you are in the IAM space, we recommend joining <a href="https://idpro.org/">IDPro</a>, where you’ll have the opportunity to advance your skills alongside experts in the field.</p><h3>References</h3><h4>Articles</h4><ul><li>TwoGenIdentity Blog Featuring Articles and Papers by Martin Besozzi: <a href="https://twogenidentity.com/blog/">https://twogenidentity.com/blog/</a></li><li>Deep Dive into Enhancing User Experience with Native Authentication (OAuth 2.0 for First-Party Apps) and Passkeys in Keycloak: <a href="https://medium.com/@embesozzi/deep-dive-into-enhancing-user-experience-with-native-authentication-and-passkeys-in-keycloak-86fb72c64278">https://medium.com/@embesozzi/deep-dive-into-enhancing-user-experience-with-native-authentication-and-passkeys-in-keycloak-86fb72c64278</a></li><li>Mastering Access Control: Low-Code Authorization with ReBAC, Decoupling Patterns and Policy as Code: <a href="https://medium.com/@embesozzi/mastering-access-control-implementing-low-code-authorization-based-on-rebac-and-decoupling-pattern-f6f54f70115e">https://medium.com/@embesozzi/mastering-access-control-implementing-low-code-authorization-based-on-rebac-and-decoupling-pattern-f6f54f70115e</a></li><li>Keycloak integration with OpenFGA (based on Zanzibar) for Fine-Grained Authorization at Scale (ReBAC): <a href="https://medium.com/@embesozzi/keycloak-integration-with-openfga-based-on-zanzibar-for-fine-grained-authorization-at-scale-d3376de00f9a">https://medium.com/@embesozzi/keycloak-integration-with-openfga-based-on-zanzibar-for-fine-grained-authorization-at-scale-d3376de00f9a</a></li></ul><h4>Conferences</h4><ul><li>Enhancing User Experience with Native Authentication and Passkeys: <a href="https://www.youtube.com/watch?v=fY1sJ8AX1fg&amp;t=32s">https://www.youtube.com/watch?v=fY1sJ8AX1fg&amp;t=32s</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=289a52f42790" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building Scalable Multi-Tenancy Authentication and Authorization using Open Standards and…]]></title>
            <link>https://embesozzi.medium.com/building-scalable-multi-tenancy-authentication-and-authorization-using-open-standards-and-7341fcd87b64?source=rss-86e67d103504------2</link>
            <guid isPermaLink="false">https://medium.com/p/7341fcd87b64</guid>
            <category><![CDATA[openfga]]></category>
            <category><![CDATA[keycloak]]></category>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[authorization]]></category>
            <category><![CDATA[multi-tenant]]></category>
            <dc:creator><![CDATA[Martin Besozzi]]></dc:creator>
            <pubDate>Sun, 08 Dec 2024 17:53:00 GMT</pubDate>
            <atom:updated>2024-12-12T14:49:19.386Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building Scalable Multi-Tenancy Authentication and Authorization using Open Standards and Open-Source Software</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qvVR-SzMkeZU6b7JrC5_gA.png" /><figcaption>Multi-tenancy Mickey Cake</figcaption></figure><p>In today’s interconnected digital ecosystem, businesses are increasingly adopting multi-tenancy to serve multiple organizations (or tenants) using a single instance of an Identity and Access Management (IAM) platform. This architecture offers significant benefits, including scalability, cost efficiency, and flexibility, by allowing multiple organizations to coexist within the same infrastructure. However, this approach introduces unique challenges in ensuring that authentication and authorization mechanisms can meet the diverse needs of each tenant.</p><p>Let’s start at the beginning. As an IAM Architect, throughout this article, I will address each problem by following open standards and using an open-source software (OSS). This article builds on the principles and ideas detailed in the articles linked below. Feel free to review them to grasp the core concepts.</p><ul><li><a href="https://medium.com/@embesozzi/keycloak-integration-with-openfga-based-on-zanzibar-for-fine-grained-authorization-at-scale-d3376de00f9a">Keycloak integration with OpenFGA (based on Zanzibar) for Fine-Grained Authorization at Scale (ReBAC)</a></li><li><a href="https://medium.com/@embesozzi/mastering-access-control-implementing-low-code-authorization-based-on-rebac-and-decoupling-pattern-f6f54f70115e">Mastering Access Control: Low-Code Authorization with ReBAC, Decoupling Patterns and Policy as Code</a></li></ul><p>Here is a high-level diagram showing how you can connect all the pieces in IAM landscape with the related standards and open-source solutions. Usually, my approach is <strong>standards-first</strong>, and then we move to the platform-specific.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pXPlJE8lNF6mZMAiGK5fZg.png" /></figure><p>Let’s dive explain each bubble adding some references to the multi-tenancy scenario — I will not add to much detail of the point described in the previous articles.</p><p>Everything is related to the <strong>identity</strong> therefore we start from there. Then, we move to the <strong>authentication</strong> stage, where we implements OpenID Connect standard. <strong>Keycloak</strong>, acting as an Identity Provider (IdP), will be responsible for handling authentication as well as the identity, organization, and permission model. In relation to the last point, Keycloak offers a new feature called the <strong>Organizations</strong> feature, which facilitates Business-to-Business (B2B) scenarios. Thanks to this feature, we are now using the Organization model to represent each tenant — more details are described in the next sections.</p><p>In the <strong>authorization</strong> stage, we follow the specifications provided by the OpenID <a href="https://openid.net/wg/authzen/">AuthZEN</a> working group. This is why we describe the architecture using “P*P” components and externalize authorization through an API served by the Policy Decision Point (PDP). This component is implemented using <strong>OpenFGA</strong>, an advanced fine-grained authorization platform that supports Relationship-Based Access Control (ReBAC).</p><p>ReBAC enables dynamic access decisions based on relationships, such as “User X is a member of Organization Y” or “User Z has the role Auditor and is a member of Organization B”. With Keycloak’s new organization model, OpenFGA now supports handling the relationship between users and organizations. All event synchronization behind the scenes is managed by the <a href="https://github.com/embesozzi/keycloak-openfga-event-publisher"><strong>Keycloak OpenFGA Event Publisher</strong></a> extension — how it works was described in previous articles.</p><p>Finally, by adopting a decoupled authorization architecture and implementing Policy as Code, we leverage <strong>Apache APISIX</strong> — a cloud-native, identity-aware API gateway integrated with OpenFGA — to enforce ReBAC policies at the API level using the <a href="https://github.com/embesozzi/apisix-authz-openfga"><strong>Authorization OpenFGA plugin</strong></a>.</p><p>Based on the points described above, let’s begin by outlining a multi-tenant scenario to apply these concepts, followed by the workshop.</p><h3>Use Case: Payment Platform PayPlus B2B (Multi-Tenant Scenario)</h3><h4>Business Requirements</h4><p>Consider a payment platform, PayPlus, which processes transactions for multiple customers (businesses). Each customer has its own set of users (e.g., employees, finance teams, auditor) with distinct authentication and authorization requirements.</p><p>In this scenario, each customer is represented as an organization within Keycloak. Within these organizations, users are assigned to global roles, which define their access to platform features.</p><p>One of the goals is to explore how to protect multi-tenant APIs by leveraging organizational and permission model relationships in authorization policies. For the sake of this use case, we are going to expose the transaction API (GET /api/orgs/{orgId}/transactions). Access to this endpoint will require that only organization members with the global role Account Manager are allowed to view the information.</p><p>The integration of Keycloak and OpenFGA creates a scalable, secure, and flexible authentication and authorization system that adapts to each customer’s needs while ensuring consistent access control. Additionally, the protection based on ReBAC authorization rules by the API Gateway integrated with OpenFGA simplifies the overall authorization process.</p><p><strong>Considerations</strong>: At the time of writing this article, Keycloak’s Organization feature had just been released. As a result, many features are still on the <a href="https://github.com/keycloak/keycloak/issues/30180">roadmap</a> for future implementation, such as support for assigning authentication flows per organization and the ability to create a new permission model tied to organizations. Once these features are supported by Keycloak, I plan to further enhance the workshop. For now, my goal is to provide a general overview of the current state and future possibilities.</p><h3>Workshop Architecture: Payment Platform PayPlus B2B</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/1*u-9QZirXC-AMqZTt9tT_3Q.png" /><figcaption>Workshop Architecture</figcaption></figure><p>To review the integration between components, you can refer to the previous articles. Below, I will introduce the new features that support this multi-tenancy scenario.</p><h4>Keycloak: New Organization Feature</h4><p>Simplifying the idea here, Keycloak introduce the feature Organization, where a user can be member either by invitation link, through identity brokering (which means you can associate the organization domain to an external IdP) or manually by an administration.</p><p>Therefore, the administrator can manage the identity lifecycle and authentication per organization. Another point to keep in mind is that authentication is identity-first, and you can have organization-specific claims.</p><p>Well, let’s jump into our example scenario: we created two organizations to represent each tenant — Org A and Org B — and assigned demo users as members in the PayPlus realm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jLwP8-8TNSL95onz1nk5Hg.png" /><figcaption>Keycloak Organization Model</figcaption></figure><p>Here is the organization member visualization of the the demo user called paula.smith.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Wk5uHSumZPphAp8dnk2AQ.png" /><figcaption>Org A members</figcaption></figure><p>We created a global role for the account manager that is related to the permission view:transaction:any resulting in this model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5LdP6ovKogs0XroGj7QxnQ.png" /><figcaption>Workshop Model</figcaption></figure><p>The authorization model is synchronized in real-time from Keycloak to the OpenFGA ReBAC model.</p><h4>Keycloak OpenFGA Extension: New Support for Synchronizing the Organization Model</h4><p>To support the Keycloak Organization model, we extended the Keycloak OpenFGA Event Publisher to handle organization events. Therefore, when you assign an organization to a user in Keycloak, this event is synchronized to the new OpenFGA model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1h8rmkHnJLNrfhGP" /><figcaption>New OpenFGA Model with Support for Organizations Introduced</figcaption></figure><h4>Apache APISIX Authorization OpenFGA plugin: New support for multiples policies with condition</h4><p>We added a feature to support multiple authorization requests with conditional criteria, such as AND or OR. As a result, we can expose APIs with more complex authorization policies, such as a user having a relation to a role and being a member of an organization.</p><p>In this case, the transaction API implements the authorization policy declared in the business requirements — no further explanation is needed, as it is super easy to understand.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_K-Guw5TmVfj3sY-bMaveg.png" /><figcaption>API Gateway with ReBAC Policies</figcaption></figure><h4>Demo App: New PayPlus Multi-tenant app</h4><p>This is another lovely ❤️ web application showcasing the use cases. It is integrated with OIDC via the Keycloak platform and displays both identity information and organization details. Additionally, it consumes the transaction API exposed by the API gateway to support multi-tenancy scenarios.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1017/1*he20MKj6MNi9cXBElAOGzQ.png" /></figure><h3>Hands-on Workshop: Payment Platform PayPlus B2B</h3><p>The demo is available in the GitHub repo, which deploys all the components with just one click.</p><ul><li><a href="https://github.com/embesozzi/keycloak-openfga-multitenancy-workshop">https://github.com/embesozzi/keycloak-openfga-multitenancy-workshop</a></li></ul><h4><strong>Use Case: Access PayPlus as Account Manager for Organization A</strong></h4><ol><li>Access the Pay Plus platform with Paula (paula.smith@orga.com) into the Pay Plus platform and click in the login button.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1017/1*he20MKj6MNi9cXBElAOGzQ.png" /><figcaption>PayPlus demo app</figcaption></figure><p>2. Login in using credentials for paula.smith in Keycloak in identity-first experience.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KUqAsB2AQKUR-3JEGviX3w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*duS1XWBYLdj-wR0TsMAqxA.png" /></figure><p>3. Pay plus demo shows the transaction information for the organization A.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mccZdqdDwrJx7GKHBV9EZw.png" /><figcaption>PayPlus Transactions</figcaption></figure><p>Let’s dive into what happened behind the scenes</p><ul><li>In the step 1 , the application integrated with OIDC and requested the organization scope to retrieve the organization information.</li><li>In the step 3, here are several points to consider. First, the application displayed the user’s organization based on the organization claim within the identity token.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*2EAPV3rUZQdiBcnUM8EL_w.png" /></figure><ul><li>Next, the application made a request to list transactions for Organization A (GET /api/orgs/org-a/transactions). The authorization policy enforced by the API Gateway, as defined below, validated the access token and checked that the user belongs to org-a and has the view:transaction:any permission using the OpenFGA platform.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*O-2cl-KhVIWb7sd6tKZonQ.png" /><figcaption>Authorization Policy</figcaption></figure><p>As you can see, the user is allowed because, in the OpenFGA authorization model detailed in the workshop below, Paula (sub claim value) is assigned to the account-manager role, which has the parent relation with the view:transaction:any permission, and she is a member of the Organization org-a. All of this model was synchronized from Keycloak to OpenFGA thanks to the custom extension ❤️.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZIYlvdxw95akiWB5zyUIOg.png" /><figcaption>OpenFGA Workshop model</figcaption></figure><h3>Conclusions</h3><p>Everything becomes easier when you follow open standards. You’ll achieve <strong>interoperability</strong>, avoid <strong>vendor lock-in</strong>, and, most importantly, <strong>not reinvent the wheel.</strong></p><p>By leveraging <strong>open-source software</strong> (OSS)<strong> </strong>such as <strong>Keycloak</strong>, <strong>OpenFGA</strong>, and <strong>Apache APISIX</strong>, along with the <a href="https://github.com/embesozzi/keycloak-openfga-event-publisher"><strong>Keycloak OpenFGA Event Publisher</strong></a> extension and <a href="https://github.com/embesozzi/apisix-authz-openfga"><strong>Authorization OpenFGA plugin</strong></a><strong> </strong>we’ve developed and maintained, you gain several benefits:</p><ul><li><strong>Transparency and flexibility</strong>: You can inspect the code and ensure it meets your security and business requirements.</li><li><strong>Community support</strong>: Active communities contribute improvements, fixes, and new features.</li><li><strong>Cost efficiency</strong>: Avoid expensive vendor licenses and reduce the total cost of ownership.</li></ul><p>Lastly, as an Identity and Access Management Architect, I believe this is a straightforward approach for addressing a complex scenario like multi-tenancy, guided by a standards-first mindset, open-source software (OSS), and the KISS (Keep It Simple, Stupid) principle.</p><p>By using modern standards and technologies described in this article, we can achieve:</p><ul><li><strong>Delegation of authentication</strong> to the Identity Provider: <strong>Keycloak.</strong></li><li><strong>Delegation of fine-grained authorization</strong> to the OpenFGA platform.</li><li><strong>Decoupling of authorization logic</strong> through the API Gateway<strong>:</strong> Apache APISIX).</li></ul><p>This makes the IAM and authorization landscape more flexible, scalable, and <strong>maintainable</strong>.</p><p>Stay connected.</p><p>That’s all for this post!</p><p>Thank you for reading. If you like it, then share it!</p><h4>Reference</h4><ul><li>Github Multi-tenancy Workshop: <a href="https://github.com/embesozzi/keycloak-openfga-multitenancy-workshop">https://github.com/embesozzi/keycloak-openfga-multitenancy-workshop</a></li><li>Keycloak Extension: <a href="https://github.com/embesozzi/keycloak-openfga-event-publisher">Keycloak OpenFGA Event Publisher</a> — new version soon.</li><li>Apache APISIX plugin: <a href="https://github.com/embesozzi/apisix-authz-openfga">Authorization OpenFGA</a> — new version soon.</li><li>Previous Article: <a href="https://medium.com/@embesozzi/keycloak-integration-with-openfga-based-on-zanzibar-for-fine-grained-authorization-at-scale-d3376de00f9a">Keycloak integration with OpenFGA (based on Zanzibar) for Fine-Grained Authorization at Scale (ReBAC)</a></li><li>Previous Article: <a href="https://medium.com/@embesozzi/mastering-access-control-implementing-low-code-authorization-based-on-rebac-and-decoupling-pattern-f6f54f70115e">Mastering Access Control: Low-Code Authorization with ReBAC, Decoupling Patterns and Policy as Code</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7341fcd87b64" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deep Dive into Enhancing User Experience with Native Authentication (OAuth 2.0]]></title>
            <link>https://embesozzi.medium.com/deep-dive-into-enhancing-user-experience-with-native-authentication-and-passkeys-in-keycloak-86fb72c64278?source=rss-86e67d103504------2</link>
            <guid isPermaLink="false">https://medium.com/p/86fb72c64278</guid>
            <category><![CDATA[keycloak]]></category>
            <category><![CDATA[native]]></category>
            <category><![CDATA[app-authentication]]></category>
            <category><![CDATA[passkey]]></category>
            <category><![CDATA[enhance-user-experience]]></category>
            <dc:creator><![CDATA[Martin Besozzi]]></dc:creator>
            <pubDate>Thu, 25 Jul 2024 23:18:31 GMT</pubDate>
            <atom:updated>2024-12-18T20:21:22.377Z</atom:updated>
            <content:encoded><![CDATA[<h3>Deep Dive into Enhancing User Experience with Native Authentication (OAuth 2.0 for First-Party Apps) and Passkeys in Keycloak</h3><h3>Introduction</h3><p>As an IAM Architect, one common question I encounter from many customers when discussing about authentication experience is:</p><blockquote>I don’t want to open a browser when using a mobile app because it kills the user experience.</blockquote><p>or</p><blockquote>I want to implement the login process within the app, as I don’t want to redirect to the Identity Provider because it increases friction and potential drop-off.</blockquote><p>I won’t delve into the reasons why, in some scenarios, you must delegate the authentication process to the Identity Provider (IdP) using OIDC with the traditional redirection method. Instead, I will describe how to implement <strong>native authentication</strong> in <strong>Keycloak </strong>to <strong>eliminate</strong> the need for<strong> redirecting or launching a browser</strong> to handle the authentication process.</p><p>Nowadays, we have a proposed standard called <a href="https://datatracker.ietf.org/doc/html/draft-parecki-oauth-first-party-apps">OAuth 2.0 for First-Party Applications</a>, which offers an<strong> API-based authentication</strong> when the <strong>application controls the login experience</strong> based on the information returned by the IdP. As usual, I always advocate following identity standards (or proposed standards) to avoid reinventing the wheel and to ensure interoperability.</p><p>In this article, I will describe the implementation of this standard in <strong>Keycloak</strong> to demonstrate the benefits of this approach. Currently, this standard is not supported, so we developed a series of <strong>custom extensions </strong>(SPIs)<strong> </strong>we called Keycloak Advanced Authentication in the context of<strong> </strong><a href="https://twogenidentity.com/"><strong>TwoGenIdentity</strong></a><strong>.</strong> These include the support OAuth 2.0 for First-Party Applications and also a custom Native passkey authenticator. However, our intention is to add other passwordless authentication mechanisms as well.</p><p>I decided that the first authenticator that support this standard will be <strong>passkeys,</strong> to offer a secure and enhanced experience. <a href="https://fidoalliance.org/passkeys">Passkeys</a> based on <a href="https://fidoalliance.org/">FIDO Alliance</a> and W3C standards. Passkeys replace passwords with cryptographic key pairs, offering strong credentials, protection from server leaks, and defense against phishing.</p><p>In the native login experience with passkeys, you can implement something like this:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FgZ4SlLO8KCg%3Ffeature%3Doembed%26rel%3D0&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DgZ4SlLO8KCg&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FgZ4SlLO8KCg%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/15c31f5a105a9790d7ee77acd5d162fa/href">https://medium.com/media/15c31f5a105a9790d7ee77acd5d162fa/href</a></iframe><p>Lastly, as usual, my articles will show the theory behind the scenes and a real implementation to glue all the pieces together.</p><h3>Overview</h3><p>OAuth 2.0 for First-Party Applications is an extension of the <a href="https://datatracker.ietf.org/doc/html/rfc6749">OAuth 2.0</a> standard, so you will notice many common parameters and formats in the authorization request. To explain the details, I’ll walk you through the developed implementation in Keycloak using using a real-world example. For a review of the generic specifications, you can refer to the proposed RFC site.</p><h4>You are a First-Party Application, right?</h4><p>First-party application means that the application and the identity server are controlled by the same entity, therefore you have control and trust over them. This is the basic definition, but there are other concepts at play. The standard mentions that the Identity Provider must ensure the application is a first-party client to prevent client impersonation. This is especially critical for public clients, which cannot securely store secrets. I would say upfront that this is not an easy topic, so I will provide some recommendations to address this in the context of a native application.</p><p>First of all, you have the possibility to implement application attestation using Apple’s and Google’s app attestation APIs. Google offers this service on Android through the <a href="https://developer.android.com/google/play/integrity">Play Integrity API</a>, which checks that user actions and requests are coming from your unmodified app binary, installed via Google Play, and running on a genuine Android device. Apple provides a similar service on iOS with App Attest and <a href="https://developer.apple.com/documentation/devicecheck">DeviceCheck</a>, which serve as anti-fraud tools to safeguard the application.</p><p>Now, you might be wondering how to use this feature in the context of OAuth. Well, there is a proposed standard called <a href="https://datatracker.ietf.org/doc/draft-ietf-oauth-attestation-based-client-auth/">OAuth 2.0 Attestation-Based Client Authentication</a>. It introduces key-bound attestation that can be used when interacting with the Authorization Server to prove authenticity. Even after reviewing the standard, you still need to perform app attestation, which means you might still rely on Apple’s and Google’s attestation APIs.</p><p>I won’t go into further detail here for now. To simplify this version of the article, I will not include the app attestation or how to generate the Client Attestation JWT and Client Attestation Proof of Possession (PoP) JWT for use when calling the Token endpoint. However, I have provided some general points to give a high-level idea.</p><h4>Deep Dive into Native Authentication Sequence Diagram</h4><p>The standard added a new endpoint called the authorization challenge endpoint (/authorization-challenge) which will receive the HTTP POST authorization request from the first-party client for navigating the defined authentication flow in the Identity Provider.</p><p>In this example, the Digital Bank portal wants to offer passkey login while maintaining control over the UX, knowing that passwordless authentication improves security for their customers. On the other hand when managing their account it will require step-authentication.</p><p>Now we are going to review the steps involved in the native authentication illustrated in the following diagram in this case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hvm0HsEkOBCY1TurbF5yzg.png" /><figcaption>OAuth 2.0 First-Party Apps Diagram Sequence</figcaption></figure><p>Based on this, Keycloak is configured with the custom extension and a new flow called “first party login” with the new passkey authenticator in the bank realm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qM2qGEc-7D-fK6ch" /><figcaption>Keycloak authentication flows</figcaption></figure><p>The “first-party login” flow includes the new passkeys authenticator, as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6B853HifQggokQZX" /><figcaption>First party login flow</figcaption></figure><p>This new authenticator supports sending the Authorization Challenge Response, which indicates to the application the details of the authentication step needed to continue the login process based the information from the IdP. This is how API-based authentication works.</p><p>In relation to the Bank Portal, it uses a customization of the keycloak-js that we developed, which supports communication with the authorization endpoint and handles the authorization challenge response.</p><p>Let’s look into each step of the sequence diagram to understand how the login process is done.</p><p><strong>Step 1)</strong> The user accesses the bank portal to manage their accounts.</p><p><strong>Step 2)</strong> The bank portal initializes the SDK and sends the authorization request. In this first step, the app is expected to receive an authorization challenge request error because it needs the metadata to trigger the passkeys selection. Here is the request in cURL format for simplicity.</p><pre>curl --location &#39;https://labs.identityaccessplus.com/realms/bank/authorization-challenge&#39;<br>  --header &#39;Accept: application/json&#39;<br>  --header &#39;Content-Type: application/x-www-form-urlencoded&#39;<br>  --data-urlencode &#39;client_id: {client-id}&#39;<br>  --data-urlencode &#39;scope=openid profile&#39;</pre><p><strong>Step 3)</strong> The IdP challenge response endpoint receives the request and generates the authorization challenge error response (HTTP 400), indicating with the error insufficient_authorization that the authorization server is requesting the client to take additional steps to complete the login process. Here it is in JSON format, as shown below</p><pre>{<br>    &quot;error&quot;: &quot;insufficient_authorization&quot;,<br>    &quot;error_description&quot;: &quot;Missing passkeys parameters&quot;,<br>    &quot;auth_session&quot;: &quot;0b574dc89d3982120237HjLOEScM0qc&quot;,<br>    &quot;metadata&quot;: [ <br>       {<br>         &quot;type&quot;: &quot;passkeys&quot;,<br>         &quot;config&quot;: {<br>           &quot;createTimeout&quot;: 0,<br>           &quot;userVerification&quot;: &quot;not specified&quot;,<br>           &quot;shouldDisplayAuthenticators&quot;: false,<br>           &quot;challenge&quot;: &quot;7uIxhFHZQS2KnKbe99j0FA&quot;,<br>           &quot;rpId&quot;: &quot;labs.identityaccessplus.com&quot;,<br>           &quot;isUserIdentified&quot;: &quot;false&quot;<br>         }<br>      }<br>   ]<br>}</pre><p>To clarify a few things, the standard specifies the format of the error with parameters such as error, error_description, and auth_session. However, there are no specifications for how the IdP returns the metadata needed to define the next step of the authentication. Therefore, I have designed a simple method for specifying the metadata with the required configuration for the authenticator type passkeys. In the config parameter, the application will find all the required configuration to initialize el authentication mechanism.</p><p><strong>Step 4) </strong>The application SDK identifies that the authenticator type is passkeys and then it initializes navigator.credentials.get() with the information provided in the metadata to initiate authentication with a passkey.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/370/1*k5r0ZG9sH0QbVIwQhtKLhg.png" /><figcaption>Native Login Experience with Passkeys Selection</figcaption></figure><p><strong>Step 5)</strong> The user selects the passkey and signs in with the fingerprint option. More technically speaking, after the user selects an account and consents using the device’s touch, the promise is resolved, returning a PublicKeyCredential object under the application’s control.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/370/1*vt3BGvHpR-HP0eeyzjoehQ.png" /><figcaption>Native Passkeys Authentication</figcaption></figure><p><strong>Step 6) </strong>The application SDK completes all the required parameters for passkeys authentication and sends back the authorization challenge response. The payload of this request includes the SAME auth_session value from the previous request.</p><pre>curl - location &#39;https://labs.identityaccessplus.com/realms/bank/authorization-challenge&#39;<br> --header &#39;Accept: application/json&#39;<br> --header &#39;Content-Type: application/x-www-form-urlencoded&#39;<br> --data-urlencode &#39;client_id={client-id}&#39;<br> --data-urlencode &#39;scope=openid profile&#39;<br> --data-urlencode &#39;clientDataJSON={client-json-data}&#39;<br> --data-urlencode &#39;signature={signature-data}&#39;<br> --data-urlencode &#39;credentialId={credential-id}&#39;<br> --data-urlencode &#39;auth_session=0b574dc89d3982120237HjLOEScM0qc&#39;</pre><p>Again, to enter a bit more technically, all the parameters are related to passkeys (public key credential object). For example, the signature is the core of the credential and needs to be verified by the Identity Provider.</p><p><strong>Step 7)</strong> The IdP challenge response endpoint receives the request and continues with the passkey authentication flow. It finalizes the authentication process because the presented information is valid meaning that credential’s signature is verified with the stored public key.</p><p><strong>Step 8) </strong>The application receives an OAuth 2.0 authorization code, as specified by the OAuth 2.0 standard, in JSON format, as shown below.</p><pre>{<br>   &quot;authorization_code&quot;: &quot;{code-value}&quot;,<br>}</pre><p>At this point, we are on common OAuth 2.0 standard ground, meaning the application negotiates the token and show the user information based on the identity tokens.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/362/1*dN4MA6dTeFnIv1v_uM9zTA.png" /><figcaption>User Authenticated</figcaption></figure><p>Another exciting scenario is step-up authentication. The user experience is enhanced because the user remains within the app, and no redirection to the Identity Provider is needed, thanks to the native authentication experience. It is triggered when user wants to access to managing the accounts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/372/1*3B0a1-lfwxH7vucUTbI0PQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/370/1*MY3hhvf6ydCTDT7vuqfXqw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/370/1*ypkK7Oe4mLiK4GJsPokb1w.png" /><figcaption>Native Step-Up Authentication with Passkeys</figcaption></figure><p>In this case, the API behind the scenes is triggering the step-up because it follows <a href="https://datatracker.ietf.org/doc/rfc9470/">OAuth 2.0 Step-up Authentication Challenge Protocol</a>. I explained in other article, but it gives the possibility to the API to implement step-up authentication thanks to understand the required Authentication Context Level (acr) and then, if the level is not enough, tells to the client that it needs to trigger step-up authentication ( RFC thanks to Vittorio Bertocci ❤).</p><p>If you want to compare the user experience in MFA and step-up with the traditional approach (which means redirection to the IdP), you can check out my <a href="https://medium.com/@embesozzi/keycloak-workshop-for-step-up-with-mfa-biometrics-authentication-passkeys-b7020ea9ae1b">previous article</a> that talks about those topics.</p><h3>Live Demo</h3><p>In the first use case, I will walk through the login process on both a mobile device and a desktop to highlight the differences in how each device requests passkeys. You will see all the steps described earlier.</p><p>In both cases, the user has already registered the passkey in Keycloak. They will access the portal and attempt to manage their user accounts (this last step will require step-up authentication as it is considered a critical operation). For the sake of the demo, I used a web application to simplify the PoC, but in a real scenario, it can be a native app.</p><h4>Bank Portal native login experience with passkeys and step-up in a Mobile scenario</h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FqRRvaZf0Lak%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DqRRvaZf0Lak&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FqRRvaZf0Lak%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/d37ab84961eabc3d248d62a34d7d442b/href">https://medium.com/media/d37ab84961eabc3d248d62a34d7d442b/href</a></iframe><h4>Bank Portal native login experience with passkeys and step-up in a Browser scenario</h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FhIN0pp4eRtQ%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DhIN0pp4eRtQ&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FhIN0pp4eRtQ%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/c695300823af08f1bd051ea980cc7d0d/href">https://medium.com/media/c695300823af08f1bd051ea980cc7d0d/href</a></iframe><h3>Conclusions</h3><p>Well, here we are. If you went through the articles and watched the videos, it is crystal clear all the benefits of following this approach. Having a standard for API-based authentication is great, as UX and security are enhanced when the application controls the login experience based on the IdP information.</p><p>Another thing to keep in mind is that, due to the deprecation of the Resource Owner Credentials Grant in <a href="http://draft-ietf-oauth-v2-1-11 1">OAuth 2.1</a>, this will be an alternative to offer to users. However, it provides an enhanced experience because the standard supports smooth interaction with the IdP.</p><p>If you are interested in this approach, DM me for more information or a demo. In the context of <a href="https://twogenidentity.com/">TwoGenIdentity</a>, we will continue evolving the extension for <a href="https://datatracker.ietf.org/doc/html/draft-parecki-oauth-first-party-apps">OAuth 2.0 for First-Party Applications</a> and adding other authenticator to further enhance both enhancing the platform.</p><p>Lastly, here is the <a href="https://github.com/keycloak/keycloak/discussions/25014">discussion</a> I posted in the Keycloak community to gain traction there.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86fb72c64278" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Access Control: Low-Code Authorization with ReBAC, Decoupling Patterns and Policy as Code]]></title>
            <link>https://embesozzi.medium.com/mastering-access-control-implementing-low-code-authorization-based-on-rebac-and-decoupling-pattern-f6f54f70115e?source=rss-86e67d103504------2</link>
            <guid isPermaLink="false">https://medium.com/p/f6f54f70115e</guid>
            <category><![CDATA[rebac]]></category>
            <category><![CDATA[authorization]]></category>
            <category><![CDATA[low-code]]></category>
            <category><![CDATA[apache-apisix]]></category>
            <category><![CDATA[openfga]]></category>
            <dc:creator><![CDATA[Martin Besozzi]]></dc:creator>
            <pubDate>Fri, 28 Jun 2024 22:25:23 GMT</pubDate>
            <atom:updated>2024-07-02T17:42:26.898Z</atom:updated>
            <content:encoded><![CDATA[<h3>In Short</h3><p>In the rapidly evolving world of software development, maintaining security, compliance, and efficiency is paramount. Traditional methods of policy enforcement and authorization often fall short in meeting these demands, making <strong>authorization</strong> a <strong>critical</strong> aspect.</p><p>Following my previous article, <a href="https://medium.com/@embesozzi/keycloak-integration-with-openfga-based-on-zanzibar-for-fine-grained-authorization-at-scale-d3376de00f9a">Keycloak integration with OpenFGA for FGA</a>, I aimed to continue improving the authorization architecture and provide an agnostic approach for exposing and protecting APIs. In this case, I want to solve this problem by following these premises and best practices:</p><ul><li><strong>Policy as Code</strong> (PaC): Policy as Code involves defining and managing security and compliance policies through code.</li><li><strong>Decoupling Authorization</strong>: Separating policy code from business logic allows each application component to enforce policies independently. Problems arise when authorization logic is deeply embedded in core application code.</li><li><strong>Low-Code Authorization</strong>: It offers a simplified, visual approach to implementing authorization logic, with an intuitive interface for defining access control rules that require little to no coding.</li></ul><p>With these points in mind, this article will describe a new authorization architecture that simplifies access control to publish and protect your services with just a few clicks.</p><p>I added an identity-aware API gateway, <a href="https://apisix.apache.org/">Apache APISIX,</a> as an API sidecar to the authorization architecture to enforce authorization and decouple it from the backend. The gateway will use a plugin that supports Relationship-Based Access Control (ReBAC) policies. Following this approach, you can simply plug and play it in front of your APIs for fine-grained authorization based on the OpenFGA platform. Using ReBAC as the authorization model allows for more granular policies. Decoupling the policies as code in the gateway offers a low-code authorization approach by validating authorization policies to determine if the user is related to the permission/object in your model.<br>As usual in my articles, I start by describing an overall idea, and then you will be able to try it yourself in a hands-on implementation. My belief is that theory and standards are essential, but hands-on practice is where you connect all the dots.</p><h3>TL;DR</h3><p>Here, we described the typical authorization components in an authorization architecture. As outlined in the <a href="https://openid.net/wg/authzen/">AuthZEN</a> Working Group, these are commonly called “P*P” architectures (PIP, PDP, PEP, etc.).</p><ul><li><strong>Authentication Server</strong>: Responsible for handling the authentication, Keycloak supports identity standards such as OpenID Connect and OAuth 2.0. Reinventing the wheel here is unnecessary. As an Identity Architect, I can’t implement this differently.</li><li><strong>Policy Decision Point (PDP)</strong>: A component that makes authorization decisions based on policies and context information. In this case, OpenFGA is based on the ReBAC Model.</li><li><strong>Policy Enforcement Point (PEP)</strong>: Responsible for enforcing access control. In this example, the API gateway, based on the authorization policy, communicates with the PDP (OpenFGA platform). In a microservice architecture, Apache APISIX can use a sidecar design pattern to provide additional functionality to application components for protecting the endpoints.</li></ul><p>Other Concepts:</p><ul><li>Decoupling the policy logic from the enforcement point in a microservice architecture is even more essential. This separation of concerns is critical in reducing the complexity of the authorization process, enabling communication with PDPs and better lifecycle management of policies. It also keeps the application code focused on functional logic instead of mixing in permissions where they are irrelevant.</li><li>Following Policy as Code (PaC) involves uniform writing, maintaining, and implementing these policies across the development lifecycle using code. This method provides automation, centralized policy management, version control, and an agnostic approach.</li></ul><h3>Architecture Overview</h3><p>Based on my previous article <a href="https://medium.com/@embesozzi/keycloak-integration-with-openfga-based-on-zanzibar-for-fine-grained-authorization-at-scale-d3376de00f9a">Keycloak integration with OpenFGA for FGA</a>, I have improved the architecture by adding an application gateway, as highlighted in the diagram below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*EQpVET7MnrL-_yJLR2DF_Q.png" /><figcaption>Authorization Architecture</figcaption></figure><p>Just to give a high-level review, I have previously synchronized the Keycloak authorization model based on roles with the OpenFGA platform to delegate fine-grained authorization to that platform while the model is still managed in Keycloak.</p><p>In this new edition, instead of implementing access control at the API level, I delegated it to Apache APISIX acting as an application authorization gateway. It uses a plugin we developed called <a href="https://github.com/embesozzi/apisix-authz-openfga"><strong>authz-openfga</strong></a>, which is responsible for enforcing authorization policies through a simple check to see if the subject is related to a specific object using the OpenFGA authorization check endpoint.</p><p>In line with the authorization architecture describe above, we will continue using the identities and roles described in the workshop to illustrate the use case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*Za6PF-E50XBwjNLm9Uit7w.png" /><figcaption>Workshop Identity Model</figcaption></figure><p>The authorization model is synchronized in real-time from Keycloak to the OpenFGA ReBAC model for the sake of the demo. Here is how you can see it in the OpenFGA Playground console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yqJG4s136Odkoecl.png" /><figcaption>OpenFGA Keycloak Model</figcaption></figure><p>In this example with a simple YAML file in the API Gateway, you can declare the API definition and define the required authorization rules for accessing the API products.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GZF_WoPy4A4gb7YN" /><figcaption>Authorization Policy with ReBAC</figcaption></figure><p>As you can see, the structure is quite easy to follow. For each endpoint, you will define the required relationship with the object. Since this example is based on roles, here I am showing that modifying products requires the role products-editor, while viewing them requires the role products-view.</p><p>Let’s go over this example when Paula wants to view the product catalog:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*OjdunJktFRCGO1DRaQLLbg.png" /><figcaption>Authorization Arquitecture Workshop</figcaption></figure><h4>Step 1) Authentication with Keycloak using OpenID Connect</h4><p>Firstly, Paula accesses the store app and authenticates via Keycloak using OpenID Connect. As a result, the app receives an ID token and an access token.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*p6nnRR6RNtNZX46A.png" /><figcaption>Store Demo App</figcaption></figure><p>With the ID token, the app builds the session based on the identity claims.</p><h4>Step 2) View product information with OAuth 2.0</h4><p>Then, Paula wants to view the product catalog. In this case, we are using OAuth 2.0, which means the app requests the API by sending the access token in Bearer format, exposed by the API Gateway. This is how we transport the identity information downstream.</p><h4>Step 3) Access Control at API Gateway Level (Cool stuff happens here)</h4><p>Once the request matches the API path and method declared in the API definition, in this case, GET /api/products, the OpenFGA authorization plugin performs the following actions:</p><p>a. Identifies the user based on the access token received using the standard sub claim, which means that the API is using OAuth 2.0 as one of the authorization protocols.</p><p>b. Checks if the user has the defined relationship with the object invoking the authorization check endpoint that comes with the OpenFGA platform.</p><p>In this case the user identified by claim sub Paula MUST have a relationship as an assignee with the role product-view. This is how easy it is to define a ReBAC policy, and it is super easy to understand.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/1*3geUwAAD8Sk1hUEgr53CHg.png" /><figcaption>ReBAC Policy for viewing products</figcaption></figure><p>If the user is allowed, the API Products returns the catalog information, and the store displays it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DNK5N-Vs8t8XroB7.png" /><figcaption>Product Catalog</figcaption></figure><p>The plugin Apache APISIX Authorization OpenFGA community edition is available in the following GitHub <a href="https://github.com/embesozzi/apisix-authz-openfga">repo</a>. You can visit there to get more technical information. The enterprise edition, which includes additional features and supports multiple authorization models, is maintained by <a href="https://twogenidentity.com/">TwoGenIdentity</a>.</p><h3><strong>Hands-On</strong></h3><p>The demo is available in GitHub repo which deploy all the components and the API protected by the authorization sidecar.</p><ul><li><a href="https://github.com/embesozzi/keycloak-openfga-workshop">https://github.com/embesozzi/keycloak-openfga-workshop</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nzhx40Rz_7Uy6DzulrSmAg.png" /><figcaption>Workshop Docker environment</figcaption></figure><p>This repo describes how to deploy the following components (some of them were describe before) running as containers:</p><ul><li><strong>Keycloak</strong> is responsible for handling the authentication with the standard OpenID Connect and is managing the user access with his Role Model.</li><li>Keycloak is configure with a custom extension <strong>keycloak-openfga-event-publisher</strong> which listens to the Keycloak events, parses this event into an OpenFGA tuple key and publishes the event to OpenFGA.</li><li><strong>OpenFGA</strong> platform is configured with the Keycloak Authorization Model in the store called “keycloak”.</li></ul><p><em>Apps:</em></p><ul><li>Product catalog web application is integrated with Keycloak with OpenID Connect to authenticate the users</li><li>Store <strong>Authorization Gateway </strong>based on Apache APISIX<strong> </strong>exposes and protects the Store API with ReBAC policies using the plugin <strong>authz-openfga, </strong>which is integrated with the OpenFGA Platform (Protection at API Gateway).</li></ul><p>All the use case details are described in the other article and the workshop. Therefore, I’ll just review some of the configuration of the authorization gateway.</p><p>All the components are automatically configured. Thus, the authorization gateway uses the image ghcr.io/embesozzi/apisix-authz-openfga:latest and the <a href="https://github.com/embesozzi/keycloak-openfga-workshop/blob/main/store-authz-gateway/routes.yml">routes.yml</a> file includes ReBAC policies for the authz-openfga plugin to handle various use cases.</p><pre>routes:<br>  - uris:<br>      - &quot;/api/products/**&quot;<br>    methods: [&quot;POST&quot;, &quot;PUT&quot;, &quot;DELETE&quot;]<br>    upstream_id: &#39;store-api&#39;<br>    plugins:<br>      authz-openfga:<br>        host: ${{FGA_HOST}}<br>        user_jwt_claim: sub<br>        relation: assignee<br>        object_type: role<br>        object: edit-product <br>  - uris:<br>      - &quot;/api/products&quot;<br>    methods: [&quot;GET&quot;]<br>    upstream_id: &#39;store-api&#39;<br>    plugins:<br>      authz-openfga:<br>        host: ${{FGA_HOST}}<br>        user_jwt_claim: sub<br>        relation: assignee<br>        object_type: role<br>        object: view-product</pre><p>As I described before, with just this simple YAML file, you can expose and protect the API Product using ReBAC, while also decoupling authorization through access control at the API Gateway level.</p><h3>Conclusions</h3><p>This approach simplifies the architecture of authorization. This is the first step of many improvements in this area. This approach may not fit every scenario, but it shows some guidelines for protecting an API with the same architectural pattern and modern authorization platforms such as OpenFGA.</p><p>My view is that this approach will show another way of thinking about authorization, following the premises of managing your policies as code, decoupling the authorization, and using modern authorization models such as ReBAC powered by OpenFGA. You can also extend to use other authorization models such as ABAC and other PDP such OPA.</p><h4>Next Steps</h4><p>In the next article, I will show how to integrate your identity model and authorization model with an LLM to have an Artificial Intelligence assistant manage your authorization and digital identity journey.</p><p>Stay connected.</p><p>That’s all for this post!</p><p>Thank you for reading. If you like it, then share it!</p><h4>Resources</h4><ul><li>Previous Article: <a href="https://embesozzi.medium.com/keycloak-integration-with-openfga-based-on-zanzibar-for-fine-grained-authorization-at-scale-d3376de00f9a">https://embesozzi.medium.com/keycloak-integration-with-openfga-based-on-zanzibar-for-fine-grained-authorization-at-scale-d3376de00f9a</a></li><li>Apache APISIX Plugin Authorization OpenFGA: <a href="https://github.com/embesozzi/apisix-authz-openfga">https://github.com/embesozzi/apisix-authz-openfga</a></li><li>Workshop GitHub Repo: <a href="https://github.com/embesozzi/keycloak-openfga-workshop">https://github.com/embesozzi/keycloak-openfga-workshop</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f6f54f70115e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Keycloak Workshop for Step Up with MFA Biometrics Authentication (Passkeys) and Passwordless…]]></title>
            <link>https://embesozzi.medium.com/keycloak-workshop-for-step-up-with-mfa-biometrics-authentication-passkeys-b7020ea9ae1b?source=rss-86e67d103504------2</link>
            <guid isPermaLink="false">https://medium.com/p/b7020ea9ae1b</guid>
            <dc:creator><![CDATA[Martin Besozzi]]></dc:creator>
            <pubDate>Thu, 20 Jul 2023 21:30:51 GMT</pubDate>
            <atom:updated>2023-11-17T13:22:47.104Z</atom:updated>
            <content:encoded><![CDATA[<h3>Keycloak Workshop for Step Up with MFA Biometrics Authentication (Passkeys) and Passwordless experience with Passkey autofill</h3><h3>In Short</h3><p>This article primarily explains two main concepts: <strong>step-up authentication</strong> involving Multi-Factor Authentication (<strong>MFA</strong>) using Biometric authentication, specifically using <a href="https://fidoalliance.org/passkeys"><strong>Passkeys</strong></a>. It also outlines the process of transitioning to a <strong>passwordless</strong> experience through the use of <strong>Passkeys</strong>.</p><p>It doesn’t matter whether your current application utilizes authentication via username and password. I will demonstrate how you can also provide Passkey login, offering a remarkably smooth experience through <a href="https://github.com/w3c/webauthn/wiki/Explainer:-WebAuthn-Conditional-UI"><strong>WebAuth Conditional UI</strong></a> or Passkey autofill during the transition to a passwordless login. Additionally, we will explore how we can <strong>gradually</strong> encourage existing users to <strong>register a passkey</strong> during the <strong>sign-in process</strong> 😄.</p><p>All resources are available on the following <a href="https://github.com/embesozzi/keycloak-workshop-stepup-mfa-biometrics"><strong>workshop</strong></a> ❤️ on GitHub. Therefore this article is more focused on the practical aspect, allowing you to try deploying the sample project with one click in a Docker Compose environment.</p><h4><strong>Step-up + MFA with Biometric Authentication (Passkeys)</strong></h4><p>As the first step, if you are not familiar with the basic concept of step-up authentication with OpenID Connect, please check out my previous <a href="https://embesozzi.medium.com/keycloak-step-up-authentication-for-web-and-api-3ef4c9f25d42">article</a>. It will provide the groundwork and an overview of the idea</p><p>So, you’re still here. I will now explain the new additions I’ve made to the PoC that haven’t been described yet. I decided to use <a href="https://fidoalliance.org/passkeys">Passkeys</a> based on <a href="https://fidoalliance.org/">FIDO Alliance</a> and W3C standards. Passkeys replace passwords with cryptographic key pairs, offering strong credentials, protection from server leaks, and defense against phishing. In the workshop, I use Passkeys as a <strong>2-factor authentication</strong> method for the <strong>Global Bank Portal</strong>, leveraging the security capabilities of devices like Touch ID and Face ID. Additionally, I implement a <strong>passwordless</strong> experience in the <strong>Bank Loan Portal</strong> using Passkeys.<br>Keycloak supports WebAuthn, and Passkeys are essentially the platform’s implementation of WebAuthn. I won’t go into too much detail here because there is a lot of content available.</p><p>Another cool thing — at least for me, the sample shows how to implement <strong>OAuth 2.0 Step-up Authentication</strong> based on the <a href="https://datatracker.ietf.org/doc/draft-ietf-oauth-step-up-authn-challenge/">OAuth 2.0 Step-up Authentication Challenge Protocol</a> standard (RFC 9470) - thanks to 🖤 Vittorio . This enables the API to implement step-up authentication by understanding the required Authentication Context Level (acr). If the level is not sufficient, the API informs the client that it needs to trigger step-up authentication. This significantly improves the user experience, as demonstrated in the demo.</p><h4>Passworless experience with Passkey autofill</h4><p>When moving from passwords to passkeys, there might be challenges. User experience matters a lot. The default “modal” experience might not be good in some cases. But using the passkey with autofill (<a href="https://github.com/w3c/webauthn/wiki/Explainer:-WebAuthn-Conditional-UI"><strong>WebAuth Conditional UI</strong></a><strong>) </strong>feature can improve the login process. Currently, Keycloak doesn’t have this feature, but I’ve made a custom SPI authenticator called <a href="https://github.com/embesozzi/keycloak-webauthn-conditional-mediation">keycloak-webauthn-conditional-mediation</a> to add it.</p><p>As they say, a picture speaks a thousand words. In the demo, you’ll be able to see the difference between the Out-of-the-Box Passkey login [1] experience and the Passkey Autofill feature [2]:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4FGvQoJCzATkYH_0_hgR5A.png" /><figcaption>Default Passkey Login experience [1]</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SI-npr5VkBZx9zCg21jDTQ.png" /><figcaption>Improved Passkey with Autofill [2]</figcaption></figure><h4>Progressive passkey enrollment during the sign-up or sign-in process</h4><p>In the latest version of the workshop, we added the feature of allowing the user to decide when they want to register the Passkey with the custom SPI (WebAuthn Authenticator Conditional Enrollment), either during the sign-up or sign-in process.</p><p>If the user doesn’t have any passkey registered, it will be a common scenario when transitioning from a password-based to a passwordless experience. The sign-in process will ask the user if they want to upgrade to a Passkey to improve the security and UX experience.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hvRkfTkobBJHm3l1EBXpzg.png" /></figure><h3>Workshop Overview</h3><h4>Components Summary</h4><p>In the demo, you will log in to the <strong>Global Bank Portal</strong>, which is an SPA integrated with Keycloak using OpenID Connect. It supports login with one-factor username and password, and two-factor with Passkeys. Only authenticated users with MFA Passkeys can access and manage their bank accounts.<br>On the backend side, the <strong>Bank Account API</strong> is a Spring Boot application protected by OAuth 2.0, acting as an <a href="https://docs.spring.io/spring-security/site/docs/current/reference/html5/#oauth2resourceserver">OAuth2 Resource Server</a>. The API follows the <a href="https://datatracker.ietf.org/doc/draft-ietf-oauth-step-up-authn-challenge/">standard</a> (RFC 9470) to trigger the OAuth step-up authentication challenge if the presented access token offers insufficient authentication based on the acr claim. Additionally, the Bank Portal is capable of handling unauthorized access gracefully and performs the step-up authentication process in a lovely way.</p><p>The <strong>Bank Loan Portal</strong> is a Vue application integrated with Keycloak using OpenID Connect. The Portal is authenticated with Keycloak, providing a passwordless experience with Passkeys.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A8qtOOa8LhZWui8VaT-MUQ.png" /><figcaption>Workshop Architecture</figcaption></figure><p>On the <strong>Keycloak</strong> side, I’ve configured the authentication flow to support Web Authn and the following authentication level mapping:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1HL8rMKB8ibN_FZB" /><figcaption>Keycloak ACR to Loa Mapping</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_mq1DyH4BXdDkn31" /><figcaption>Keycloak Browser MFA with Passkeys (Web Authn)</figcaption></figure><p>I’ve split the login process into several steps. First of all, I only request the username. <strong>Please avoid asking the user too many things in the first step</strong>, like the traditional username and password form — we are not in the eighties anymore 😄. With just the username, it’s enough to personalize the login user experience in the next steps. Then, if needed, I’ve requested the completion of the remaining MFA login steps. This flow utilizes the OOTB Webauthn Passwordless Authenticator since passkeys autofill is unnecessary.</p><p>The OOTB Keycloak Browser Passwordless appears as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aIf5fpievjCsA55yc4rblQ.png" /><figcaption>Keycloak OOTB Browser Passwordless</figcaption></figure><p>In the demo, I utilized the custom SPI called “webauthn conditional mediator.” This allows me to offer Passkey autofill while retaining the option for login through a username and password. Also we use the custom SPI “WebAuthn Conditional Enrollment “ , which will help by asking the user if they want to move to a passwordless experience with a Passkey.</p><p>Here’s what you’ll see in the demo:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R2xroWvSTyfGMtN_th7P1Q.png" /></figure><p>This flow supports the following features, thanks to the custom SPI:</p><ul><li>Enabling passkey autofill when supported by the browser.</li><li>Displaying the “Sign with passkeys” button if passkey autofill is not available.</li><li>If Passkeys (Webauthn) are not supported, it will present the traditional username and password login option.</li><li>The user will be asked to register a Passkey if they don’t have any passkey registered.</li></ul><p>It will be used for the Bank Loan portal. The app becomes cooler as it removes the need for passwords and simplifies the login experience with this cool feature of passkeys autofill.</p><h3>Workshop Sequence diagram</h3><p>Here is a sequence diagram that explains how the components work together.</p><h4>Scenario: Step-Up MFA with Passkeys for Managing Global Bank Accounts</h4><p>In the case of the <strong>Global Bank Portal </strong>(use cases #1 and #2). It’s quite easy to follow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t2ZHMp96zSKM4jaJBKtbxA.png" /><figcaption>Global Bank step-up authn sequence diagram</figcaption></figure><p>Not too much to add here, but I love the communication between the Bank API and Portal to be on the same page regarding the desired authentication mechanism based on the acr claim (step #2). This means that the API will return a <strong>401 Unauthorized</strong> status code along with the <strong>WWW-Authenticate</strong> header containing the error message ‘insufficient_authentication_level’ and the defined <strong>acr_values</strong>, indicating to the Bank Portal what ACR value to request from the identity provider. On the client side, the Bank Portal is able to interpret this error and redirect the user to perform the step-up authentication.</p><p>Then, the possibility of doing MFA biometric authentication with Passkeys (step #3). In my case, my Mac Touch ID is making me cry tears of happiness.</p><p>Points #1 and #2 follow the OpenID Connect Standard, where the Bank portal specifies the desired authentication mechanism (acr claim) to the IdP. You can also use the acr_values parameter in the authentication request for that.</p><h3>Test Cases</h3><p>Here is a summary of the main test cases, but you can try deploying the workshop yourself:</p><ul><li><a href="https://github.com/embesozzi/keycloak-workshop-stepup-mfa-biometrics">https://github.com/embesozzi/keycloak-workshop-stepup-mfa-biometrics</a></li></ul><p>The workshop has <strong>Global Bank</strong> portal (Use case 1 and 2) with the following requirements:</p><ul><li>Supports OIDC login with one-factor username and password and two factor (MFA) with Passkeys</li><li>Only authenticated user with MFA Passkeys can access and manage their bank accounts</li><li>If the user is not authenticated with MFA when managing bank accounts, it triggers the step-up to MFA :) in a lovely way thanks to the step-up authn challenge provided by the API.</li></ul><p>The <strong>Bank Loan </strong>portal (Case 3) has the following requirements:</p><ul><li>Supports OIDC login with Passkeys → A super nice way to do the login with Passkeys autofill</li><li>Only authenticated users can view and apply for the loans</li></ul><h4>Use case 1: Sign up on the Bank Portal</h4><p>1.1) Access to the Bank Portal and proceed with user registration:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XWjWMuV2iXM99ewzP-Bqlw.png" /></figure><p>1.2) Complete the user information (step 1):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MPg_j1wIdABYel3TgAIfHA.png" /></figure><p>3) Click in Upgrade to Passkey button. You can do it during the sign-up or sign-in process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hvRkfTkobBJHm3l1EBXpzg.png" /></figure><p>4) Register the Passkeys (step 2):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xXbAZgSLfaZF2oxN2QYFZA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sz44pozbA2FgOesUBepr4g.png" /></figure><p>1.4) You will see the Bank Portal Home</p><h4>Use case 2 : Sign in to the Bank Portal for Managing Bank Accounts</h4><p>2.1. Access to the Bank Portal and Sign In:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XWjWMuV2iXM99ewzP-Bqlw.png" /></figure><p>2.2 Complete the username and password (1 factor):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VCG1_m7hpsIZdK_c0sT8UA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ognrZtBsTO3uHsYPkDEeHg.png" /></figure><p>2.3 You will see to the Bank Portal Home and Go to the Identity Profile section and check your ACR claim: <strong>loa1</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nn3Mz4S4rxDdlJwptpMQgQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fhjc3b7dEV0fRE5g2D4mSg.png" /></figure><p>2.4 Go to the Manage Bank Accounts. You will see that Authn Level is not enough, with a lovely modal that handles the step-up authentication based on the access denied information. Proceed to access with MFA</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Eclo_UUVVl0PytiSIiPGvw.png" /></figure><p>2.5 Complete the user name and password (1 factor):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5VklmpdY7Z2ILISLoaD3_A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6UYCkRsersJYQquhaev9BA.png" /></figure><p>2.6 Choose your passkey (in the MFA scenario, Passkey will appear as a modal), and then proceed to verify your identity, in this case with Touch ID (2 factor). In the passwordless scenario, you’ll enjoy an enhanced experience with passkey autofill (use case #3).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Gy91wzuQYNGrl_zRU9C6LA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9TwY97ZNNXu879_NOiNVIw.png" /></figure><p>2.7 You will see the Bank Account Information since you have signed in with MFA. Go to the Identity Profile section and check your ACR claim: <strong>loa2</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mEeRGdhXD84glSyK3u2_wg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P9vyEYLKGW5hild8N-uhPw.png" /></figure><h4>Use case 3: Sign in Passkey autofill on the Bank Loan (Web)</h4><p>3.1 Access the Bank Loan Portal and sign in</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cr6PA3HicwgwCnN5UigFRw.png" /></figure><p>3.2 Simply click on the username, it will the passkey with autofill 🥰 and choose the passkey.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SI-npr5VkBZx9zCg21jDTQ.png" /></figure><p>3.3 Verify your identity and the you will see will see the Loan portal home:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zr_STe3N7eRD92_Mxs6Obw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NtA8c2r8dhH-iUYvxCKZog.png" /></figure><p>(Optional) If the user doesn’t have any passkey registered, it will be a common scenario when transitioning from a password-based to a passwordless experience. The sign-in process will ask the user if they want to upgrade to a passkey.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hvRkfTkobBJHm3l1EBXpzg.png" /></figure><h4>Use case 4: Sign in passwordless default experience on the Bank Loan Portal</h4><p>Here are additional examples using the OOTB Keycloak Browser Passwordless feature, providing you with a better understanding of the default user experience.</p><p>Here is the login with passkey in default modal experience:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4FGvQoJCzATkYH_0_hgR5A.png" /><figcaption>Passkey login with modal experience</figcaption></figure><p>Here is the login with passkey in a mobile app:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*BIBpPe1OJzODnnFG_0d-ww.jpeg" /><figcaption>Passkey login with modal experience (mobile)</figcaption></figure><h3>Conclusions</h3><p>I hope you’ve enjoyed the article. In my opinion, this approach solves several problems in modern applications. Having the opportunity to use these standards will improve security and enhance the user experience.</p><p>Transitioning from password-based to passkey-based authentication, I believe that the <strong>passkey autofill</strong> feature enhances the user experience. This integration allows you to incorporate login within your existing username and password form. On the other hand, enabling the feature of<strong> progressive passkey registration</strong> in the sign-in process will improve the user experience in the transition to passwordless for existing users.</p><p>That’s all for this post!</p><p>Thank you for reading. If you like it, then share it!</p><p>Follow me on Twitter and GitHub: <strong>@embesozzi</strong></p><h4>Reference</h4><ul><li>Workshop: <a href="https://github.com/embesozzi/keycloak-workshop-stepup-mfa-biometrics">https://github.com/embesozzi/keycloak-workshop-stepup-mfa-biometrics</a></li><li>Custom Authenticator keycloak-webauthn-conditional-mediation: <a href="https://github.com/embesozzi/keycloak-webauthn-conditional-mediation">https://github.com/embesozzi/keycloak-webauthn-conditional-mediation</a></li><li>Previous reference article: <a href="https://medium.com/@embesozzi/keycloak-step-up-authentication-for-web-and-api-3ef4c9f25d42">https://medium.com/@embesozzi/keycloak-step-up-authentication-for-web-and-api-3ef4c9f25d42</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b7020ea9ae1b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Keycloak integration with OpenFGA (based on Zanzibar) for Fine-Grained Authorization at Scale…]]></title>
            <link>https://embesozzi.medium.com/keycloak-integration-with-openfga-based-on-zanzibar-for-fine-grained-authorization-at-scale-d3376de00f9a?source=rss-86e67d103504------2</link>
            <guid isPermaLink="false">https://medium.com/p/d3376de00f9a</guid>
            <category><![CDATA[openfga]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[keycloak]]></category>
            <category><![CDATA[authorization]]></category>
            <category><![CDATA[auth0]]></category>
            <dc:creator><![CDATA[Martin Besozzi]]></dc:creator>
            <pubDate>Sat, 22 Oct 2022 00:36:38 GMT</pubDate>
            <atom:updated>2024-12-09T18:59:33.489Z</atom:updated>
            <content:encoded><![CDATA[<h3>Keycloak integration with OpenFGA (based on Zanzibar) for Fine-Grained Authorization at Scale (ReBAC)</h3><h3>In Short</h3><p>With the growing importance of <strong>zero-trust architecture</strong> which is based on the principle that nothing can be trusted, questions around the level of access granted have become critical. Furthermore, <strong>security and compliance</strong> are mandatory problems to tackle in any architecture, and <strong>authorization</strong> is a crucial part of any solution having in mind that the 2021 top OWASP risk was a broken access control. And last but not least, how to make authorization <strong>flexible, fast and scalable</strong>.</p><p>Taking into consideration the aim of the article is to provide an open-source authorization framework to solve those problems thanks to the implementation of <strong>Keycloak</strong> open-source Identity and Access Management platform integrated with <strong>OpenFGA</strong>, which is an open source solution for Fine-Grained Authorization that applies the concept of ReBAC (created by the Auth0 inspired by <strong>Zanzibar</strong>).</p><p>Therefore, I have implemented Keycloak for handling the authentication with the standard OpenID Connect and also taking advantage of the Keycloak role model for managing the user access. I am still using the standard OAuth 2.0 for API protection, since the application is sending the access token when it is calling the service but I have just used it for getting identity claims. This architecture is focused on decoupling the authorization part.</p><p>Additionally, OpenFGA is responsible for applying fine-grained access control in a high performance and flexible authorization / permission system. The OpenFGA service answers authorization checks by determining whether a relationship exists between an object and a user. It uses the authorization model of the system and the relationship tuples present in the system at that time in order to make a decision.</p><h4>What’s new: October 8, 2023 😀</h4><p>A new version of the PoC is now available. We have achieved <strong>direct integration</strong> between the Access Manager platform and the OpenFGA solution, thanks to the use of the <a href="https://github.com/openfga/java-sdk">OpenFGA Java SDK</a> to publish events over HTTP. In the past, we used a Kafka cluster to synchronize events between platforms when the SDK wasn’t available. Therefore, I’ve updated some sections to showcase the newly improved and simplified ❤️ authorization architecture.</p><h4>What’s new: June 29, 2024</h4><p>I wrote a new article explaining the approach for low-code authorization with OpenFGA and the decoupling pattern by applying access control at the API Gateway. If you are interested, check out the <a href="https://medium.com/@embesozzi/mastering-access-control-implementing-low-code-authorization-based-on-rebac-and-decoupling-pattern-f6f54f70115e">Mastering Access Control: Low-Code Authorization with ReBAC, Decoupling Patterns and Policy as Code article</a>.</p><h4>What’s new: Dec 9, 2024 🚀</h4><p>Checkout new article about the <a href="https://medium.com/@embesozzi/building-scalable-multi-tenancy-authentication-and-authorization-using-open-standards-and-7341fcd87b64">Building Scalable Multi-Tenancy Authentication and Authorization using Open Standards and Open-Source Software</a>: Keycloak, OpenFGA and Apache APISIX.</p><p>So, one thing is still missing: how do we connect the Keycloak permission model events with the OpenFGA authorization model (ReBAC) ?</p><p>Well, I developed a new custom extension known as Service Provider Interfaces (SPI) called <strong>keycloak-openfga-event-publisher</strong> which basically:</p><ol><li>Listens to the Keycloak events, for instance, an User Role Assignment.</li><li>Translates this event to an OpenFGA tuple key using the OpenFGA SDK (more details are available further).</li><li>Publishes the event directly to the OpenFGA Solution</li></ol><p>Here is a basic example of how all the components work together, for instance, for allowing an Analyst to have rights to see the product catalog:</p><p>a) We have modeled the <strong>Analyst role</strong> related to the <strong>view product role</strong> and the former has been assigned to the user <strong>Peter</strong> in Keycloak</p><p>b) The custom Keycloak extension “listens” to two events in this case, parses them and creates two OpenFGA tuples, which represents the relationship between those roles and that the user Peter is related to the Analyst role. As a final step, it publishes the event to the OpenFGA solution</p><p>c) Then the application or API can do an authorization check invoking the OpenFGA service asking for example:<br>“Is Peter related to the role view product as assignee?” Allowed</p><p>In this case OpenFGA allows the operation because the user has an implied relationship to the child role thanks to the parent role.</p><p>Another cool feature of this extension is its capability to discover the OpenFGA authorization model and determine which events are handled. This gives you the flexibility to choose your authorization model, whether it’s RBAC, GBAC, or both 🙌.</p><p>Here I described the most simple scenario; other details are described in the article to give you a complete idea.</p><h3>Some Background</h3><h4>Authentication vs Authorization</h4><p>Authentication (or AuthN) is a process that ensures a user’s identity. Authorization (or AuthZ) means determining if a user can perform a certain action on a particular resource.</p><h4>OpenID Connect (OIDC)</h4><p>Identity layer on top of the OAuth 2.0 protocol. OIDC provides authentication by the ID token which contains information about the identity.</p><h4>OAuth 2.0</h4><p>It is one of the most well-known security policies. It provides authorization via an access token (JWT) containing:</p><ul><li>Scopes: are used to express what an application can do on behalf of the user.</li><li>Identity claims: are used to provide identity user attributes information.</li></ul><h4>JSON web token (JWT)</h4><p>Open standard used to share information between two parties, it is signed using a cryptographic algorithm to ensure that the claims cannot be altered after the token is issued and it could also be encrypted.</p><h4>Access Control</h4><p>Access control involves users, resources and applications, and it is a complex model. Role-based Access Control — or RBAC: is an authorization model used to determine access control based on predefined roles. In this approach you proceed to assign roles to users, and permissions to roles, and use those to decide who can do what. E.g. Simon is an Admin who can administer the Store application. Keycloak permissions model is based on RBAC.<br>On the other hand, the OpenFGA authorization model is based on Relationship-based authorization, or ReBAC, which means organizing permissions based on relationships between resources.<br>Nevertheless, there is no fixed path to follow, depending on the business requirements we can apply one or a mix of the access control models.</p><h4>Relationship-based authorization (ReBAC)</h4><p>ReBAC allows expressing rules based on relations that users have with objects and that objects have with other objects. For example, a user can view a document if they can view its parent folder.<br>In many cases, roles would fit in well as relations on an object type. In this case I implemented custom roles for accomplishing the integration with the Keycloak permission model.</p><h4>Zanzibar</h4><p>Zanzibar is “Google’s Consistent, Global Authorization System” for “determining whether online users are authorized to access digital objects” across their products (Google Drive, YouTube, Google Photos, etc..). It uses (object, relation, user) tuples to store relation data and traverses those relations to check if there is a relation between a user and an object.<br>Zanzibar scales to trillions of objects, billions of users and millions of authorization requests per second.</p><h3>Proposed Authorization Framework</h3><p>The components involved in the authorization framework are described below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/1*AaeSBST50z4Z-Wm_0PvxKA.png" /><figcaption>Authorization Architecture (v2.0.0)</figcaption></figure><p>The diagram described before has the following components:</p><ul><li>Keycloak: Responsible for handling the authentication</li><li>OpenFGA: Responsible for applying fine-grained access control. The OpenFGA service answers authorization checks by determining whether a relationship exists between an object and a user</li><li>New Custom extension Keycloak OpenFGA Event Publisher: Responsible for parsing and sending the events to the OpenFGA Solution</li></ul><p>Each component is described below in more detail.</p><h3>OpenFGA - Authorization Layer</h3><p>OpenFGA is an open source solution to Fine-Grained Authorization that applies the concept of ReBAC. It was created by the Auth0 FGA team and was inspired by Zanzibar. It was designed for reliability and low latency at a high scale. It offers an HTTP API and has SDKs for programming languages including Node.js/JavaScript, GoLang and .NET.<br>The OpenFGA service answers authorization checks by determining whether a relationship exists between an object and a user.</p><h4>OpenFGA Concepts</h4><p>OpenFGA is based on the ReBAC model, this is why it’s built to quickly and reliably make authorization checks. This means providing an answer to a question: “Can user U perform action A on object O?”<br>ReBAC systems determine access from a user’s relation to an object. Authorization decisions are then yes or no answers to the question: “Does user U have relation R with object O?”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1iLRiTQYr2WIzIQg" /><figcaption>Source of the image: <a href="https://zanzibar.academy/">https://zanzibar.academy/</a></figcaption></figure><p>Please visit the <a href="https://openfga.dev/docs/concepts">official link</a> to review the main concepts of OpenFGA, the most important ones are below:</p><ul><li>An <strong>authorization model</strong> is a combination of one or more type definitions. This is used to define the permission model of a system</li><li>An <strong>user</strong> is an entity in the system that can be related to an object</li><li>An <strong>object</strong> represents an entity in the system.</li><li>A <strong>relation</strong> is a string defined in the type definition of an authorization model that defines the possibility of a relationship between an object of the same type as the type definition and a user in the system.</li><li>A <strong>relationship tuple </strong>is a tuple consisting of a user, relation and object stored in OpenFGA.</li><li>A <strong>check request</strong> is a call to the OpenFGA check endpoint that returns whether the user has a certain relationship with an object.</li></ul><p>There are a lot of super cool examples about the data modeling and theory behind the scenes, this is why I recommend reviewing the oficial <a href="https://openfga.dev/docs/modeling">doc</a>.</p><p>In our case, I have implemented the authorization model of <a href="https://openfga.dev/docs/modeling/custom-roles">custom roles</a> based on the Keycloak Role and Group model. This authorization model is based on the following premises:</p><ul><li>Keycloak administrators are able to create arbitrary sets of roles with different permissions that govern the users’ access to objects.</li><li>It is not known beforehand (at the time of Authorization Model creation) what the application roles are.</li></ul><h4>OpenFGA Keycloak Authorization Model</h4><p>Based on the Keycloak’s model (see section Keycloak — Role model) we can define the following cases (I will start with the simpler to the more complex case)</p><ul><li>A certain user can be assigned to a certain role (user role assignment)</li><li>A certain role can be related to a parent role (role to role assignment)</li><li>A certain user can be assigned to a certain group (user group</li><li>membership)</li><li>A certain group can be related to a certain role (group role assignment)</li></ul><p>Take into consideration these premises, we can represent all of these cases with the following Keycloak authorization model (OpenFGA playground):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pm3hT_qlXFIEIlflpaP5YQ.png" /><figcaption>OpenFGA Keycloak Authorization Model (new)</figcaption></figure><p>It is amazing that with this simple authorization model we can represent all the use cases.</p><p>In this new version of the authorization model, I’ve used the feature of <a href="https://openfga.dev/docs/configuration-language#the-direct-relationship-type-restrictions">direct type restriction</a> to control the type of object allowed in the relation.</p><p>Furthermore, OpenFGA supports <strong>implied relationships</strong>. This means that an implied (or computed) relationship R exists between user X and object Y if user X is related to an object Z that is in a direct or implied relationship with object Y, and the OpenFGA authorization model allows it. In other words, in our case OpenFGA knows the implicit roles the user has inherited by the direct assignment of a parent role or group.</p><h4>OpenFGA SDK</h4><p>It offers an HTTP API and has SDKs for programming languages including Node.js/ JavaScript, GoLang and Java (new). Here I will show an example how to perform a check request to determine whether a user has a certain relationship with an object.</p><pre>// Run a check<br>const { allowed } = await fgaClient.check({<br>  tuple_key: {<br>    user: &#39;user:paula&#39;,<br>    relation: &#39;assignee&#39;,<br>    object: &#39;role:view-product&#39;,<br>  },<br>});ty<br>// allowed = true</pre><p>In my scenario, I have used the SDK in two different cases:</p><ul><li>API: When performing the access control check in the API.</li><li>Keycloak extension: When parsing and synchronizing the events from Keycloak to OpenFGA</li></ul><h3>Keycloak - Identity Layer</h3><p>Open Source Identity and Access Management system, built and maintained by Red Hat. It provides single sign-on with strong session management capabilities. It means allowing users to access multiple applications, while only having to authenticate once. Keycloak builds on industry standard protocols supporting OAuth 2.0, OpenID Connect and SAML 2.0.</p><h4>Authentication</h4><p>In our scenario each application is integrated with Keycloak through OpenID Connect. This means that the application is delegating the authentication process to the SSO platform.<br>On the other hand, OAuth 2.0 is a delegated authorization framework for REST / APIs. It enables apps to obtain limited access (scopes) to user’s data (without giving away a user’s password).<br>After the user was authenticated the application receives two tokens, the id token as identity token includes information about the user and it is meant to be used by the application only. The access tokens are used to inform an API that the bearer of the token has been authorized to access the API and perform a predetermined set of actions.</p><h4>Keycloak Roles Model</h4><p>Keycloak supports role modeling and it also has different kinds of roles: Realm roles, Client roles and composite Roles:</p><ul><li>Realm Role: It is a global role, belonging to that specific realm. You can access it from any client and map to any user. Ex Role: ‘Global Admin, Admin’</li><li>Client Role: It is a role which belongs only to that specific client. You cannot access that role from a different client. Ex Roles: Product Analyst, Customer’</li><li>Composite Role: It is a role that has one or more roles (realm or client ones) associated with it.</li></ul><p>It also supports modeling Groups, which can hold users as members and roles.</p><p>By implementing this model you can define the user’s access based on roles, groups or both. These operations produce events in Keycloak, for instance, when you assign a user to a role that you can “listen” to the event and decide which the next steps are. This functionality is used by the following custom extension.</p><h3>Keycloak OpenFGA Event Publisher (SPI)</h3><p>Keycloak has a series of Java Service Provider Interfaces (SPI) that allows adding new functionalities where needed. The main purpose of this SPI is to listen to the Keycloak events and publish these events to an OpenFGA solution.<br>In this case, the extension listens to the Admin Events related to operation in Keycloak Identity, Role and Group model. So far, the extension proceeds with the following steps:</p><p>Step 1) Parse and enrich the default Keycloak events in the following cases:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BO8DC94BIngsKzee5QOyfQ.png" /></figure><p>Step 2) Transform the Keycloak event into a OpenFGA tuple key based on the Keycloak Authorization Model (see section OpenFGA - Keycloak Authorization Model) using the OpenFGA SDK:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OrQGtv6CbvSYXYHm2_Le_Q.png" /></figure><p>Step 3) Publish the event to the OpenFGA solution:</p><p>Publishes the Tuple Key as ClientWriteRequest object to the OpenFGA server over an HTTP request fgaClient.write(request) with the <a href="https://github.com/openfga/java-sdk">OpenFGA SDK client</a>.</p><p>Here is a high level overview of the extension:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*N4oGnoL8ZzysqNlFDRQcfA.png" /></figure><p>The extension supports the discovery of the OpenFGA authorization model and uses it to determine which events are handled.</p><p>Full details of the SPI component and the configuration is available in the <a href="https://github.com/embesozzi/keycloak-openfga-event-publisher">GitHub repo</a>.</p><h3>Use case: How Does It Work?</h3><h4>Overview</h4><p>As an example, we will implement an Product Catalog web application that has the following requirements:</p><ul><li>Only authenticated user with MFA can access to the application</li><li>Product can be viewed by their Analyst</li><li>Product can be edited by their Admin</li><li>Global Admin users can view or edit any Product</li></ul><h4>Involved Components</h4><p>The PoC is available in the following GitHub repo:</p><ul><li><a href="https://github.com/embesozzi/keycloak-openfga-workshop"><strong>https://github.com/embesozzi/keycloak-openfga-workshop</strong></a></li></ul><p>This repo describes how to deploy and configure the following components (some of them were describe before) running as containers:<br><em>Core:</em></p><ul><li><strong>Keycloak</strong> is responsible for handling the authentication with the standard OpenID Connect and is managing the user access with his Role Model</li><li>Keycloak is configure with a custom extension <strong>keycloak-openfga-event-publisher</strong> which listens to the Keycloak events, parses this event into an OpenFGA tuple key and publishes the event to OpenFGA.</li><li><strong>OpenFGA</strong> is configured with the Keycloak Authorization Model in the store called “keycloak”</li></ul><p><em>Apps:</em></p><ul><li>Product catalog web application is integrated with Keycloak to authenticate the users</li><li>API product catalog is protected by OAuth and it utilizes the OpenFGA SDK to enforce relationship-based access control (ReBAC)</li></ul><p>All the components are detailed below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/1*AaeSBST50z4Z-Wm_0PvxKA.png" /><figcaption>New Authorization Model (v2.0.0)</figcaption></figure><h4>Step 1) Deploy and configure the PoC</h4><p>Follow the instructions detailed in the github repo <a href="https://github.com/embesozzi/keycloak-openfga-workshop">keycloak-openfga-workshop</a> to deploy and configure the components.</p><p>As the result you will have up and running all the components described before. You will also have created all the users and role model, here are detailed below:</p><p><em>Roles:</em></p><ul><li>Admin Catalog role (admin-catalog) is related to the roles: View (view-product) and Edit product (edit-product)</li><li>Analyst Catalog role (analyst-catalog) is related to the role View product (view-product)</li></ul><p><em>Users:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*BbG0hIuJtOkNOR-e" /><figcaption>Keycloak Identity and Role Model</figcaption></figure><p>Once these steps are finished, the Keycloak OpenFGA Event Listener extension has to proceed to publish these events to the OpenFGA server using the SDK. Here are all tuples stored</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eJOyKSJzHu9z1ZXZPaqtSg.png" /><figcaption>OpenFGA tuples</figcaption></figure><p>The users are identified by the value of the claim sub in the <a href="http://localhost:3000/playground">OpenFGA Playground</a>, see the Tuples tab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mJoNaqUgfBp5Tan0lJShAQ.png" /></figure><h4>Step 2.1) Try it Out: Check User Access thru OpenFGA Playground</h4><p>The OpenFGA Playground can be accessed by opening a browser to <a href="http://localhost:3000/playground">http://localhost:3000/playground</a></p><p>Click the Tuple Queries &gt; section below the Types Previewer. Enter the following in the query prompt field and press the Enter key:</p><p>In this case, OpenFGA is evaluating the relationships and evaluating true or false responses according to the authorization model and relationship tuples.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RqK6XuxsTt1ANwkYIaPNkA.png" /></figure><p>For instance, the assertion #4 is True because Paula has implied relationships to the view-product role for having a direct relationship to the Analyst role.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qJ2Kbh4K1E0kZgjXeJQmAQ.png" /><figcaption>Assertion #4</figcaption></figure><p>On the other hand, the assertion #3 is False because Paula does not have the edit-product role.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8LFvKRv92OpP8lyjA_JGMQ.png" /><figcaption>Assertion #3</figcaption></figure><h4>Step 2) Try it Out: Run the full demo</h4><p>Here is an overview of the user cases.</p><h4>Use case 1: Access to the Store for managing products as an Analyst (Paula)</h4><ol><li>Access to the <a href="http://store:9090/">Store web application</a> and proceed to login with Paula (paula / demo1234!) in Keycloak</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lSiX2HuGcwmDucwmykyIwg.png" /><figcaption>Store Web App</figcaption></figure><p>2.1 Keycloak will return the id_token and the access token to the application</p><p>3. The Store web application will show the product catalog</p><p>3.1 The Store web application will call the product API sending the access token in the Authorization header</p><p>3.2 The API will apply the following steps:</p><p>3.3. It will validate the token following the OAuth 2.0 standard and it will extract the claim sub to identify the user</p><p>3.4. Then it will call the OpenFGA API to check if the user has the view-product role with the relationship assignee</p><p>3.5. OpenFGA will return the response “allowed”</p><p>3.6. The API will return the product information and the store app will show the information to the user</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MEcwWsT_WBK7BkjQTMoAVA.png" /></figure><p>4. Try to publish a product by clicking the button “Publish” but you will see that Paula is not allowed</p><p>4.1. The app will call the product API sending the access token in the Authorization header</p><p>4.2. The API will apply the following steps:</p><p>4.3. It will validate the token following the OAuth 2.0 standard and it will extract the claim sub to identify the user</p><p>4.4. Then it will call the OpenFGA API to check if the user has the edit-product role with the relationship assignee</p><p>4.5. OpenFGA will return the response “denied” and the app will show the error message “Unauthorized Access”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LRqfMjvUGQOpvPsMniR8sQ.png" /></figure><h4>Use case 2: Access to the Store for managing products as an Admin (Richard)</h4><ol><li>Access to the <a href="http://store:9090/">Store web application</a> and proceed to login with Richard (richard / demo1234!) in Keycloak</li></ol><p>2. Keycloak will return the id_token and the access token to the application</p><p>3. The store web application will show the product catalog</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x5RImfYw0VXrmJ6fivRLQw.png" /></figure><p>4. Try to publish a product by clicking the button “Publish” but you will see that Richard is allowed</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qS6GxZShhtZk35cTNiwOQw.png" /></figure><h4>Use case 3: Access to the Store for managing products as an Regular User (Peter)</h4><ol><li>Access to the <a href="http://store:9090/">Store web application</a> and proceed to login with Peter (peter / demo1234!) in Keycloak</li></ol><p>2. Keycloak will return the id_token and the access token to the application</p><p>3. The store web application will try to the products show but the user is not allowed</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SAZj_rPddLXwpkE5kQP8QA.png" /><figcaption>Unauthorized Access for viewing product as Peter</figcaption></figure><p>All the use cases are available <a href="https://github.com/embesozzi/keycloak-openfga-workshop">here</a>.</p><h3>Conclusions</h3><p>I hope you’ve enjoyed the article. In my opinion, this approach solves several problems in the modern applications which have evolved and this makes fine-grained authorization a critical element in software. As I described in the article, the API is still protected by OAuth 2.0, since it requires an access token for accessing it. But the complex authorization rules are implemented into OpenFGA.</p><p>Another point to have in mind is that nowadays it is all about scalability, so decoupling the authorization part from Keycloak and delegating it to OpenFGA (which was designed JUST for handling authorization at scale) it’s a good path to follow. Another thing to bear in mind is that the direct integration between AM and OpenFGA simplifies the authorization architecture. With the use of the SDK in the extension, it provides the possibility to adapt the integration based on the authorization model.</p><p>Finally, this authorization architecture can evolve in many different ways, for instance, adding new components acting as PEPs (Proxy, API Gateway, etc) working in conjunction or not with OPA (Open Policy Agent), etc. Taking these points into consideration, I will continue talking about how to improve this for sure</p><p>Please stay connected to get the updates if you are interested in this topic !</p><p>That’s all for this post!</p><p>Thank you for reading. If you like it, then share it!</p><h3>Reference:</h3><ul><li>Workshop: <a href="https://github.com/embesozzi/keycloak-openfga-workshop">https://github.com/embesozzi/keycloak-openfga-workshop</a></li><li>Keycloak OpenFGA Event Publisher (new): <a href="https://github.com/embesozzi/keycloak-openfga-event-listener">https://github.com/embesozzi/keycloak-openfga-event-</a>publisher</li><li>Keycloak OpenFGA Event Kafka: <a href="https://github.com/embesozzi/keycloak-openfga-event-listener">https://github.com/embesozzi/keycloak-openfga-event-</a>kafka (this was used in the first version of the PoC if you want to integrate the AM and OpenFGA server through <a href="https://github.com/embesozzi/keycloak-openfga-workshop/tree/main/kafka-integration">Kafka</a>)</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d3376de00f9a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Keycloak Step-Up and Multi-factor Authentication (MFA) for Web Apps and API]]></title>
            <link>https://embesozzi.medium.com/keycloak-step-up-authentication-for-web-and-api-3ef4c9f25d42?source=rss-86e67d103504------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ef4c9f25d42</guid>
            <category><![CDATA[openid-connect]]></category>
            <category><![CDATA[keycloak]]></category>
            <category><![CDATA[multifactorauthentication]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[oauth2]]></category>
            <dc:creator><![CDATA[Martin Besozzi]]></dc:creator>
            <pubDate>Wed, 19 Jan 2022 01:22:11 GMT</pubDate>
            <atom:updated>2024-07-27T00:05:56.339Z</atom:updated>
            <content:encoded><![CDATA[<h3>In Short</h3><p>The focus of the article is to announce that finally Keycloak (Identity and Access Management) <strong>will support step-up authentication</strong>. With step-up authentication, Web Applications or APIs that allow access to different types of resources can require users to authenticate with a stronger authentication mechanism to access sensitive resources.</p><h4>Update: July 21, 2023 😀</h4><p>Now you have access to the workshop for <strong>Keycloak Workshop for Step Up with MFA Biometrics Authentication (Passkeys) and Passwordless login experience </strong>on <a href="https://github.com/embesozzi/keycloak-workshop-stepup-mfa-biometrics">Github</a>, which includes the use cases described in this article. Additionally, there is a new <a href="https://medium.com/@embesozzi/keycloak-workshop-for-step-up-with-mfa-biometrics-authentication-passkeys-b7020ea9ae1b">article</a> 🙌 with more information and cool new use cases, such as, how to implement Step-up Authentication based on OAuth 2.0 Step-up Authentication Challenge Protocol and Passkeys for 1 or 2-factor (MFA).</p><h4>Update: January 4, 2024</h4><p>I have updated the article to include the use of the A<strong>uthentication Methods Reference</strong> because it will be supported in 🙌 Keycloak version 24. Since this version has not been released yet (the PR was merge into the main branch), I have built Keycloak from source in order to test the functionality for the article.</p><h4>Update: January 26, 2024</h4><p>There is a new way to handle the authentication and step-up experience with native authentication in Keycloak. It’s an API-based approach that enhances the UX by delegating the control of the authentication steps to the application. If you are interested, here is my new <a href="https://medium.com/@embesozzi/deep-dive-into-enhancing-user-experience-with-native-authentication-and-passkeys-in-keycloak-86fb72c64278">article</a> that shows this approach in detail.</p><p>I won’t dive deep into the explanation about step-up authentication or the standard involved because there is a lot of information available. I will just described a high-level overview technical points:</p><ul><li>An Authentication Context Class (acr claim) specifies a set of business rules that authentications are being requested to be satisfied. ACR is referred to as the level of assurance (LoA) or Authenticator Assurance Level (AAL). Authentication Requests using the acr_values parameter request that the specified Authentication Context will be used.</li><li>Authentication Methods Reference (amr claim) is an JSON array of strings that are identifiers for authentication methods used in<br> the authentication. According to the <a href="https://www.rfc-editor.org/rfc/rfc8176.html">RFC 8176</a>, you can specify for instance the authentication method such as pwd (password), otp, user, etc to give more information to the application after the authentication process has concluded.</li><li>To fully support the step-up, a client should be able to force re-authentication even when the IdP considers that a user is authenticated to an acceptable level. In the OpenID Connect standard, this is done with the prompt=login optional parameter.</li></ul><p>At the moment I was writing the article the PR <a href="https://github.com/keycloak/keycloak/pull/7897">keycloak-847</a> was approved and merged into main repository. Now, it’s officially available.</p><h4>New features</h4><h4>Clients: ACR to Level of Authentication Mapping</h4><p><em>Clients &gt; Advance Settings &gt; ACR to Level of Authentication Mapping</em></p><p>You can define which Authentication Context Class Reference (ACR) value is mapped to which Level of Authentication (LoA). The acr claim will be included in the access token and ID token.</p><p>For instance:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h5LIQBjEEkc8IFbEXs7UyA.png" /><figcaption>ACR to LoA mapping</figcaption></figure><p>In this example the acr aal1 is related to one-factor authentication, therefore, the user authenticates with username and password. On the other hand, the acr aal2 is related to two-factor authentication, so it requires the authentication with password and TOTP or Passkeys.</p><p>I choose these values to simplify the demo, but for specifying MFA you can use the value<a href="http://schemas.openid.net/pape/policies/2007/06/multi-factor">http://schemas.openid.net/pape/policies/2007/06/multi-factor</a> (based on <a href="https://openid.net/specs/openid-provider-authentication-policy-extension-1_0-05.html">OpenID Provider Authentication Policy Extension</a>) or <a href="http://schemas.openid.net/policies/modrna/multi-factor">http://schemas.openid.net/policies/modrna/multi-factor</a> (based on <a href="https://openid.net/specs/openid-connect-modrna-authentication-1_0.html#rfc.section.4">OpenID Connect MODRNA Authentication Profile 1.0</a>).</p><h4>Flow: Condition - Level Of Authentication</h4><p><em>Realm &gt; Flows &gt; Condition - Level Of Authentication</em></p><p>Based on the browser login which is an authentication flow you can use the new flow “Condition - Level Of Authentication” in order to require or not the defined authentication step based on the value of parameters acr_values specified by the application. By doing so, the client could specify the authentication level of a user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RTyRx8plL8U3GHkith0crg.png" /><figcaption>Keycloak authentication flow MFA</figcaption></figure><p>I have also associated the authentication mechanism reference with the desired amr claim values to provide the application with more context about the login process. In this case: Password Form → amr: <strong>pwd</strong>, OTP Form → amr: <strong>otp</strong>, and WebAuthn → amr: <strong>user</strong>. Here is an example for the OTP form.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H9yofOBEPSfgazXAv6dk2w.png" /><figcaption>Keycloak AMR configuration for OTP step</figcaption></figure><h3>Example Step-Up Use Case</h3><p>In this scenario I’ve registered a demo realm and I’ve created an OAuth Client for the OIDC demo Bank Portal. I’ve also followed the step-up configuration described before.</p><p>In the following sequence diagram you will see that the Bank portal for the sign-in processs will require one factor authentication (username and password) and for managing the bank accounts two factor authentication (mfa).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QpjxArnrRzaIuG1KdT-dZg.png" /><figcaption>Sequence Diagram for Step-Up process</figcaption></figure><p><strong>STEP #1:</strong> In this case the web application wants to authenticate the user with username and password (one factor authentication). The application is configured to authenticate with OpenID Connect and it will implement the OAuth Flow Authorization Code.</p><p>To initiate the authentication process the web application must send the authentication request specifying the required acr_values, in this example, aal1.</p><pre>https:/idp/auth/realms/Demo/protocol/openid-connect/auth?<br>  response_type=code&amp;<br>  client_id=spa&amp;<br>  scope=openid%20profile&amp;<br>  state=Xvg9WF-dpnoLGWDocd35PWRf7pHmqpc&amp;<br>  redirect_uri=<a href="https://webapp/login/oauth2/code/keycloak&amp;nonce=Gwh7EDGaKUnOa1CYLJXwNTlufGLqKUkB1URdJBFbClg&amp;acr_values=pwd">https://webapp/callback&amp;</a><br>  nonce=Gwh7EDGaKUnOa1CYLJXwNTlufGLqKU&amp;<br>  <strong>acr_values=aal1</strong></pre><p>Keycloak based on the configuration that I’ve described before will follow these authentication steps:</p><ol><li>Prompt for username</li><li>Prompt for password (one factor authentication)</li><li>Skip second factor authentication step</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MWjVEh_Fi736up5DAtBNZQ.png" /><figcaption>Sign In with 1 factor (ACR value = aal1)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IGzV6_7pFy5UoLUACbhw4Q.png" /><figcaption>1 Factor - Prompt Username</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dBO6JF36s5hLijYnKEa2bg.png" /><figcaption>1 Factor - Prompt Password</figcaption></figure><p>Keycloak after the successful authentication will return the authorization code to the application and then the application will negotiate the tokens.</p><p>Here is an example with id_token (payload decoded):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p6VxQWWFFFREx3pjNvDjPw.png" /><figcaption>ID token information</figcaption></figure><p>Based on the acr claim it will know the level of assurance of the authenticated user and the authentication mechanism amr claim.</p><p><strong>STEP #2: </strong>If the application wants to do a step-up authentication for requiring two-factor authentication it must send the acr_values with the value aal2 - it also could specify the parameter prompt_login with the value true to force the authentication. Here’s an example:</p><pre>https:/idp/auth/realms/Demo/protocol/openid-connect/auth?<br>  response_type=code&amp;<br>  client_id=spa&amp;<br>  scope=openid%20profile&amp;<br>  state=Lll923-dpnoLGWDocd35PWRf7pHmqpc-DxQNdTEdy-U%3D&amp;<br>  redirect_uri=<a href="https://webapp/login/oauth2/code/keycloak&amp;nonce=Gwh7EDGaKUnOa1CYLJXwNTlufGLqKUkB1URdJBFbClg&amp;acr_values=mfa">https://webapp/callback</a><br>  nonce=Gwh7EDGaKUnOa1CYLJXwNTlufGLqKUkB1URdJBFbClg&amp;<br>  <strong>acr_values=aal2</strong>&amp;<br>  <strong>prompt_login=true</strong></pre><p>Keycloak will follow these authentication steps:</p><ul><li>Prompt for username</li><li>Prompt for password (first factor authentication)</li><li>Prompt for otp (second factor authentication)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HXqAdVDxuJ0nW3kdfmcgiw.png" /><figcaption>Sign In with 2 factor (ACR value = aal2)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IGzV6_7pFy5UoLUACbhw4Q.png" /><figcaption>1 Factor — Prompt Username</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dBO6JF36s5hLijYnKEa2bg.png" /><figcaption>1 Factor — Prompt Password</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0Tgp5_1rx7-1scFADpjOXw.png" /><figcaption>2 Factor — Prompt for OTP</figcaption></figure><p>Here is an example with id_token:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0HPYnPkrmkd_YCugEKi8og.png" /><figcaption>ID token information</figcaption></figure><p>Based on the acrclaim, it will indicate the level of assurance of the authenticated user; in this case, ‘aal2,’ and the amr claim that contains ‘otp’ indicating the use of the second factor.”</p><p>UPDATED: When I originally wrote this article, I used OTP as the second factor, but nowadays, you can use Passkeys that trigger Touch or Face ID. If you want to know more about it, check out the new <a href="https://medium.com/@embesozzi/keycloak-workshop-for-step-up-with-mfa-biometrics-authentication-passkeys-b7020ea9ae1b">article</a> 🙌.</p><p><strong>BONUS:</strong> Step-Up authentication for API</p><p>You can also implement step-up authentication to your API protected by OAuth. For instance, the API can verify that the user has logged in using MFA and, if not, require the user to step-up to access certain resources. Therefore, you can use the acr claim which is also available in the access token.</p><p>In this example, for second factor authentication the access token has the acr claim with the value aal2:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*TO63Ql31-nckF7ajxGEn2A.png" /></figure><p>The API will validate if the acr claim is equal to the value aal2 in the access token received in the Authorization Header with format: Bearer {access-token} based on <a href="https://datatracker.ietf.org/doc/html/rfc6750">RFC 6750</a>.</p><p>Here is an authorization rule in Rego language for <a href="https://www.openpolicyagent.org/">Open Policy Agen</a>t. OPA is an open-source policy engine that provides a simple API for delegating policy decisions to it. General-purpose policy engine that unifies policy enforcement across the stack. In this example the policy requires multi-factor authentication (claim is equal to aal2) for payment operations (POST /api/v1/payment).</p><pre>package http.authz<br>default allow = false</pre><pre>## Check if claim acr is equal to &#39;aal2&#39; for POST payments<br>allow {<br> input.method == &quot;POST&quot;<br> input.path[_] == &quot;payment&quot;<br> token.payload.acr == &quot;aal2&quot;<br>}</pre><pre>## Decode and extract JWT payload</pre><pre>token = {&quot;payload&quot;: payload }{<br> auth_header := input.headers.authorization<br> startswith(auth_header, &quot;Bearer &quot;)<br> bearer_token := substring(auth_header, count(&quot;Bearer &quot;), -1)<br> [_, payload, _] := io.jwt.decode(bearer_token)<br>}</pre><p>UPDATED: Nowadays, the <a href="https://datatracker.ietf.org/doc/draft-ietf-oauth-step-up-authn-challenge/">OAuth 2.0 Step-up Authentication Challenge Protocol</a> standard (RFC 9470) is available - thanks to 🖤 Vittorio. This enables the API to implement step-up authentication by understanding the required Authentication Context Level (acr). If the level is not sufficient, the API informs the client that it needs to trigger step-up authentication. If you want to know more, check out the new <a href="https://medium.com/@embesozzi/keycloak-workshop-for-step-up-with-mfa-biometrics-authentication-passkeys-b7020ea9ae1b">article</a> <strong>Step Up with MFA Biometrics Authentication (Passkeys) and Passwordless login experience.</strong></p><h3>Conclusion</h3><p>At first sight the implementation looks very promising and you can implement step-up for Web Apps and API without any problem. I’ve reviewed this feature in other IAM platforms and Keycloak is one of the first ones to implement the <a href="https://www.rfc-editor.org/rfc/rfc9068.html">RFC 9068</a> in order to have the acr claim present in the access token. It is the key for applying access control based on the authentication level of assurance in the API scenario.</p><p>Thanks to Keycloak’s support for the Authentication Methods Reference (amr claim) in complex use cases, it is helpful to indicate to the application the authentication method used. For complex login journeys, you can use the amr claim with the value ‘mfa,’ confirming to the application that the user went through a 2-step authentication process.</p><p>Finally, with the <a href="https://datatracker.ietf.org/doc/draft-ietf-oauth-step-up-authn-challenge/">OAuth 2.0 Step-up Authentication Challenge Protocol</a>, you can improve the security and user experience on the API side by using the acr and amr claims to check the desire level of authentication. If the level is not sufficient, you can trigger the step-up process following the step-up challenge standard RFC 9470.</p><p>That’s all for this post!</p><p>Thank you for reading. If you like it, then share it!</p><p>👉 Lastly, check the new <a href="https://medium.com/@embesozzi/keycloak-workshop-for-step-up-with-mfa-biometrics-authentication-passkeys-b7020ea9ae1b">article</a> and <a href="https://github.com/embesozzi/keycloak-workshop-stepup-mfa-biometrics">github workshop</a> about <strong>Step Up with MFA Biometrics Authentication (Passkeys) and Passwordless login experience.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ef4c9f25d42" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>