<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: DarkEdges</title>
    <description>The latest articles on DEV Community by DarkEdges (@darkedges).</description>
    <link>https://dev.to/darkedges</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1396307%2F1b5a1a60-77b1-40cd-89e3-0cfb704caf5a.jpeg</url>
      <title>DEV Community: DarkEdges</title>
      <link>https://dev.to/darkedges</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/darkedges"/>
    <language>en</language>
    <item>
      <title>Building a Federated Copilot: Part 6, Ionic React, Fingerprints and Persistent Sessions</title>
      <dc:creator>DarkEdges</dc:creator>
      <pubDate>Tue, 03 Nov 2026 20:28:00 +0000</pubDate>
      <link>https://dev.to/darkedges/building-a-federated-copilot-part-6-ionic-react-fingerprints-and-persistent-sessions-5bkl</link>
      <guid>https://dev.to/darkedges/building-a-federated-copilot-part-6-ionic-react-fingerprints-and-persistent-sessions-5bkl</guid>
      <description>&lt;p&gt;After the browser produced a verified document-backed answer, the next requirement was a phone application that could demonstrate the integration without repeated deployment windows and several logins.&lt;/p&gt;

&lt;p&gt;The agreed target was Ionic React on a Pixel 6 Pro running Android 17, delivered directly as an APK. The owner wanted a remembered 30-day enrollment, fingerprint unlock, a new chat on every entry and access to supported documents inside the existing approved SharePoint site.&lt;/p&gt;

&lt;p&gt;This article describes both the implemented design and its current verification boundary. The native device-test build passed owner-observed fingerprint and background-clearing checks. The live v5 APK is installed and distributed, and the backend is deployed. Live mobile sign-in is still under investigation: tapping Sign in has not yet been observed to redirect successfully to PF. There is no claim of completed mobile Copilot acceptance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Separate the mobile project from the server
&lt;/h2&gt;

&lt;p&gt;The Ionic application lives under &lt;code&gt;apps/mobile&lt;/code&gt; with its own package and Android build. It does not add its UI dependencies to the dependency-light simulation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apps/mobile/
  src/                 React UI, controller and fixed HTTPS transport
  tests/               Lifecycle, transport and proof tests
  android/             Capacitor application and native plugins
  scripts/             Local Android build helper
src/mobile/            Server-side enrollment and execution components
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are two explicit build modes. The default is a labelled offline device test. The &lt;code&gt;live&lt;/code&gt; mode uses the fixed agent API and never returns a local success message when real services fail.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Run from apps/mobile after installing its pinned dependencies.&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;npm&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nv"&gt;$&lt;/span&gt;&lt;span class="nn"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nv"&gt;VITE_MOBILE_MODE&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;'live'&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;npm&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;run&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;android:build&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The repository helper checks the configured JDK and SDK, builds the web application, synchronizes Capacitor and runs native assembly, unit tests and lint. It signs with a dedicated local demo key outside source control. That key is a distribution credential, not a PF, Graph or agent credential.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Make fingerprint unlock cryptographic
&lt;/h2&gt;

&lt;p&gt;A JavaScript flag such as &lt;code&gt;authenticated: true&lt;/code&gt; is insufficient evidence for resuming a delegated session. We implemented a small native boundary that creates an authentication-bound P-256 Android Keystore key and signs a challenge through a strong biometric &lt;code&gt;CryptoObject&lt;/code&gt; operation.&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;sequenceDiagram
    participant A as Ionic app
    participant N as Native biometric plugin
    participant K as Android Keystore
    participant B as Mobile backend
    A-&amp;gt;&amp;gt;B: Request nonce bound to enrolled device and request key
    B--&amp;gt;&amp;gt;A: Short-lived one-use challenge
    A-&amp;gt;&amp;gt;N: Sign challenge for mobile presence
    N-&amp;gt;&amp;gt;K: Initialize authentication-bound signature
    N-&amp;gt;&amp;gt;N: Show strong fingerprint prompt
    K--&amp;gt;&amp;gt;N: Signature only after allowed key use
    N--&amp;gt;&amp;gt;A: Signature and public metadata
    A-&amp;gt;&amp;gt;B: Complete challenge
    B-&amp;gt;&amp;gt;B: Verify key, purpose, nonce, expiry and current authority
    B--&amp;gt;&amp;gt;A: Short-lived foreground session&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Android's &lt;a href="https://developer.android.com/identity/sign-in/biometric-auth" rel="noopener noreferrer"&gt;biometric cryptography guide&lt;/a&gt; and &lt;a href="https://developer.android.com/privacy-and-security/keystore" rel="noopener noreferrer"&gt;Keystore documentation&lt;/a&gt; explain the platform primitives. Our enrollment and server authorization protocol is additional application logic.&lt;/p&gt;

&lt;p&gt;The native policy requires strong biometric authentication for key use, uses separate aliases and domains for local testing and live mobile presence, and checks reported hardware security level. It does not collect fingerprint images or templates.&lt;/p&gt;

&lt;p&gt;The selected app policy has no device-PIN substitute for biometric session unlock. Fresh sign-in is the recovery direction, but the current enrollment path still checks that strong biometrics are available. Do not advertise a complete biometric-unavailable recovery experience until that case is designed and tested.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Preserve the hardware-attestation boundary
&lt;/h2&gt;

&lt;p&gt;The phone can report that its key is backed by TEE or StrongBox and can produce a valid signature. Without verified remote attestation, the backend has not independently proved that every remote client enforces the same biometric policy.&lt;/p&gt;

&lt;p&gt;We therefore label server evidence as registered-device-key possession with hardware attestation &lt;strong&gt;UNVERIFIED&lt;/strong&gt;. The owner approved this explicit PoC assurance limit. A signature does not justify inventing a stronger assurance claim.&lt;/p&gt;

&lt;p&gt;The APK contains no PF confidential-client secret, agent signing key, Graph key, Direct Line secret or Vault bootstrap credential. Its durable local state is limited to device-bound references and the consent preference. The native key stays in Android Keystore.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Keep first login in the system browser
&lt;/h2&gt;

&lt;p&gt;We use backend-assisted PF login rather than embedding the provider page in the WebView. The backend owns the confidential client and provider tokens; the phone starts a device-bound transaction.&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;sequenceDiagram
    participant M as Mobile app
    participant B as Backend
    participant F as PF A
    participant W as System browser
    M-&amp;gt;&amp;gt;M: Create device key and native pending claim secret
    M-&amp;gt;&amp;gt;B: Device public key and hash of claim secret
    B-&amp;gt;&amp;gt;F: PAR with PKCE, state, nonce and private_key_jwt
    B--&amp;gt;&amp;gt;M: Fixed-provider authorization URL
    M-&amp;gt;&amp;gt;W: Open approved provider URL
    W-&amp;gt;&amp;gt;F: Human sign-in
    F--&amp;gt;&amp;gt;B: Code at fixed backend callback
    B-&amp;gt;&amp;gt;F: Redeem code with PKCE and signed client assertion
    B--&amp;gt;&amp;gt;W: One-use HTTPS App Link handoff
    W-&amp;gt;&amp;gt;M: Return to verified app
    M-&amp;gt;&amp;gt;B: Claim handoff with native transaction secret
    B--&amp;gt;&amp;gt;M: Enrollment challenge requiring device signature&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;The handoff is short-lived, one-use and bound to the initiating device and claim hash. It is not a provider access token in a deep link. Process loss or missing native custody requires a fresh sign-in.&lt;/p&gt;

&lt;p&gt;The return path is an HTTPS Android App Link. The association binds the exact hostname, package ID and APK signing certificate. A successful HTTPS GET of &lt;code&gt;assetlinks.json&lt;/code&gt; does not prove Android has verified the association on the installed phone. That is a separate device check documented in &lt;a href="https://developer.android.com/training/app-links/verify-applinks" rel="noopener noreferrer"&gt;Android App Link verification&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Separate enrollment, foreground proof and delegation
&lt;/h2&gt;

&lt;p&gt;The 30-day period is an absolute device enrollment ceiling. It does not make a PF access token valid for 30 days and does not move the original PF &lt;code&gt;auth_time&lt;/code&gt; forward.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Object&lt;/th&gt;
&lt;th&gt;Purpose and bound&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Device enrollment&lt;/td&gt;
&lt;td&gt;Original verified human, device public key and absolute 30-day expiry&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Resource consent&lt;/td&gt;
&lt;td&gt;Separate chat/document grants, revocable and bounded by enrollment&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Foreground session&lt;/td&gt;
&lt;td&gt;Up to 15 minutes, replaced on fresh unlock&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Request proof&lt;/td&gt;
&lt;td&gt;At most 60 seconds, one use, exact method/path/body&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Mobile authority assertion&lt;/td&gt;
&lt;td&gt;Profile-specific short-lived issuance under current evidence&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PF A and PF B tokens&lt;/td&gt;
&lt;td&gt;Narrower audience-specific child evidence&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Provider access/refresh session&lt;/td&gt;
&lt;td&gt;Server-held Generic OAuth session, separate from delegated authority&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A foreground session ID alone grants no access. The app creates an ephemeral request key and signs a JWT binding session, configured audience, exact route, body hash, validity and unique &lt;code&gt;jti&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The server consumes replay identifiers durably and rejects a proof for access status when it is reused for chat or approval. Extra identity, scope and resource fields are not accepted in the chat body.&lt;/p&gt;

&lt;p&gt;Current device, human, actor, organisation, grant and resource checks run again during execution. A successful fingerprint cannot override a revoked grant or suspended agent.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 6: Treat resumed interaction as its own evidence type
&lt;/h2&gt;

&lt;p&gt;We did not reuse an expired OIDC login or switch the operation to autonomous mode to bypass recent-login checks.&lt;/p&gt;

&lt;p&gt;The mobile authority preserves the original login issuer, subject, client audience and authentication time, and records current registered-device-key presence separately. It requires the current resource grant and an independently signed registered-agent assertion before issuing delegated evidence.&lt;/p&gt;

&lt;p&gt;The original object returned by the trusted device authority is held in an instance-private registry. JSON copies cannot be reconstructed into authority. A future cross-process handoff would need authenticated transport and replay protection, not a serialized object accepted on trust.&lt;/p&gt;

&lt;p&gt;Real Vault/PF container verification exercised the mobile chat and document chains with their own keys and clients. The current profile uses authority/PF A/PF B maximum lifetimes of 180, 120 and 60 seconds, while enforcing remaining parent validity. This is separate from the 60-minute provider user token used for Microsoft sign-in.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 7: Design foreground lifecycle as a state machine
&lt;/h2&gt;



&lt;pre data-lang="mermaid"&gt;&lt;code&gt;stateDiagram-v2
    [*] --&amp;gt; Locked
    Locked --&amp;gt; Starting: Sign in
    Starting --&amp;gt; Browser: Fixed-provider launch
    Browser --&amp;gt; Completing: Bound App Link return
    Completing --&amp;gt; Consent: Manual review selected
    Completing --&amp;gt; Chat: Current approval available
    Consent --&amp;gt; Chat: Explicit approval
    Locked --&amp;gt; Completing: Fingerprint resume
    Chat --&amp;gt; Locked: Background or lock
    Starting --&amp;gt; Error: Native or network failure
    Completing --&amp;gt; Error: Verification failure
    Chat --&amp;gt; Error: Authority or service failure
    Error --&amp;gt; Starting: New explicit sign-in&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Backgrounding clears the current messages, cancels owned work and discards foreground signing authority. A legitimate system-browser departure preserves only its pending native login transaction.&lt;/p&gt;

&lt;p&gt;Generation counters prevent late callbacks, duplicate App Link events and delayed network results from opening a chat after cancellation or crossing into a new session. A failed credential-bearing operation does not automatically replay.&lt;/p&gt;

&lt;p&gt;Every successful entry or unlock starts an empty chat. Multiple questions are supported while that foreground session is active. The app and backend do not write a durable transcript or document cache. Microsoft-hosted conversations and traces have their own retention and are not deleted merely because the app clears its screen.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 8: Separate default approval from identity
&lt;/h2&gt;

&lt;p&gt;The visible default-on checkbox approves only the configured chat and document capabilities for the registered agent and existing site. It does not approve new sites, scopes or arbitrary model actions.&lt;/p&gt;

&lt;p&gt;Turning it off requires manual resource approval. A revoked resource permission cannot be restored by a later automatic check under the same revoked binding. Unknown or unsaved preference state fails closed.&lt;/p&gt;

&lt;p&gt;The device enrollment consent and resource delegation IDs remain different records. A phone that proves possession of its key is not automatically entitled to read documents.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 9: Refresh provider credentials without creating a replay loop
&lt;/h2&gt;

&lt;p&gt;The dedicated mobile login client requires PAR, S256 PKCE and signed client authentication, with authorization code and rotating refresh grants. Provider credentials remain in CAS-protected Vault records.&lt;/p&gt;

&lt;p&gt;Before refresh, the old refresh credential is persisted as spent. An uncertain response requires fresh sign-in. Fresh access tokens are checked for issuer, audience, subject, signature and lifetime before release to the server-side Copilot adapter.&lt;/p&gt;

&lt;p&gt;The provider must have enough remaining validity for the foreground chat. The deployment profile requires 960 seconds before opening a 900-second conversation, keeping a margin instead of starting a session with a nearly expired token.&lt;/p&gt;

&lt;p&gt;Compatibility of this new private-key-authenticated provider client with the already published Copilot Generic OAuth configuration remains a live gate. Sharing issuer and audience is not proof of that compatibility.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 10: Prepare persistent hosting without unlimited authority
&lt;/h2&gt;

&lt;p&gt;The owner requested demos without 45-minute deployment windows or one-question limits. We introduced a separate persistent profile, preserving all spent historical allowances.&lt;/p&gt;

&lt;p&gt;The approved standing ledger permits 100 attempted questions and 20 conversations, with additional fixed request ceilings. Counters persist across failures and restarts. This is a bounded operational allowance, not a currency meter or guaranteed enforcement of the existing $50 budget.&lt;/p&gt;

&lt;p&gt;The private API binds only to loopback HTTPS. Exact Cloudflare routes expose the mobile API and App Link association; PF A gains only the reviewed PAR route. Workload certificate roles, durable usage, one-day audit retention and dependency supervision are separate from UI unlock.&lt;/p&gt;

&lt;p&gt;An owned Windows startup task is prepared to run under the existing account without a stored password or operator Vault credential. It is intentionally not installed until owner phone acceptance succeeds. Docker, unsealed Vault, the host, network, Microsoft entitlements and certificate expiry remain real availability dependencies.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 11: Record deployment findings accurately
&lt;/h2&gt;

&lt;p&gt;Actual deployment exposed several mismatches that the local contracts did not catch:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;PF rejected the new client because &lt;code&gt;offline_access&lt;/code&gt; was absent from its global catalog. We obtained approval for that exact static scope addition and preserved every other setting.&lt;/li&gt;
&lt;li&gt;PF serialized scopes in a different order. We verified exact set equality, retained pending history and reconciled the successful write without repeating it.&lt;/li&gt;
&lt;li&gt;The new token manager could not publish a key ID already published by the original manager. We retained the approved signing key and disabled duplicate publication in the new manager.&lt;/li&gt;
&lt;li&gt;The service manifest omitted an APK certificate field. We completed metadata from the already approved certificate and APK pin while preserving the original packet.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The private runtime became ready, the five mobile clients were enabled and public configuration and association endpoints returned HTTP 200. Those facts still do not establish phone sign-in.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 12: Install, distribute and diagnose on the actual phone
&lt;/h2&gt;

&lt;p&gt;The v5 candidate was installed in place using the same signing certificate. ADB inspection should target the owner's known device and must not automate fingerprint or password entry.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;adb&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;devices&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-l&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;adb&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-s&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;owner-device&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;install&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-r&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;verified-apk-path&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;adb&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-s&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;owner-device&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;shell&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;pm&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;verify-app-links&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;--re-verify&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;package-id&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;adb&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-s&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;owner-device&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;shell&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;pm&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;get-app-links&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;package-id&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the owner moved off-network, we added an exact, time-limited APK download route through the existing public hostname. The server serves one hash-pinned artifact, refuses other paths and query variants, and does not expose a build directory. We downloaded the public artifact and verified its hash before sharing the link.&lt;/p&gt;

&lt;p&gt;The current reported failure is that the app stays at its sign-in button. A bounded backend initiation check returned a valid authorization destination at PF A, so the next investigation is on the native client path. We initially suspected the offline page policy, then inspected the built artifact and confirmed live mode already replaced it correctly. That suspicion was withdrawn; no unsupported fix is claimed.&lt;/p&gt;

&lt;p&gt;This is why the next acceptance test requires the actual phone: observe the preparing state, native key operations, pending login, browser launch and verified return without logging URLs, handoff secrets or credentials.&lt;/p&gt;

&lt;h2&gt;
  
  
  Current outcome and production work
&lt;/h2&gt;

&lt;p&gt;At the activation preparation checkpoint, 896 backend production tests, 372 simulation tests, 41 mobile tests and 12 native tests passed. Later isolated tests cover the scope amendment and APK route. These are historical checkpoint counts, not a claim that every subsequent change reran every suite.&lt;/p&gt;

&lt;p&gt;The browser PoC has a verified document answer. Mobile core cryptography and lifecycle have local coverage, and the owner verified fingerprint behavior in the device-test build. Live mobile login, refresh, multi-turn document chat, Android association behavior and revoke/resume acceptance still need end-to-end verification.&lt;/p&gt;

&lt;p&gt;Production work includes hardware-attestation policy, Microsoft trace protection, stronger workload isolation, rotation, reliable host recovery, billing enforcement, supported document formats and sustained availability testing. The useful result of this series is a set of explicit trust boundaries and measurable integration milestones, including the ones that remain open.&lt;/p&gt;

</description>
      <category>android</category>
      <category>react</category>
      <category>security</category>
      <category>ai</category>
    </item>
    <item>
      <title>Building a Federated Copilot: Part 5, SharePoint Documents Without External Entra Users</title>
      <dc:creator>DarkEdges</dc:creator>
      <pubDate>Tue, 03 Nov 2026 20:27:56 +0000</pubDate>
      <link>https://dev.to/darkedges/building-a-federated-copilot-part-5-sharepoint-documents-without-external-entra-users-4ln6</link>
      <guid>https://dev.to/darkedges/building-a-federated-copilot-part-5-sharepoint-documents-without-external-entra-users-4ln6</guid>
      <description>&lt;p&gt;The external user can now authenticate with PF and invoke a delegated diagnostic through Copilot Studio. The next requirement is document access.&lt;/p&gt;

&lt;p&gt;We did not solve that by provisioning external Entra users or sending PF access tokens to Microsoft Graph. Instead, a dedicated Entra application reads an approved SharePoint site. Our own policy independently decides whether the external human and registered agent may use that application capability for the current operation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Establish a real site and entitlement
&lt;/h2&gt;

&lt;p&gt;The project needed an actual SharePoint-backed Microsoft 365 environment. A trial was obtained through the tenant's supported process, and the owner created a dedicated PoC site.&lt;/p&gt;

&lt;p&gt;Our examples use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://exampletenant.sharepoint.com/sites/FederatedCopilotPoC
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The real tenant and site identifiers are intentionally omitted. We also kept subscriptions, trial expiry and licensing separate from application authorization. A working Graph app cannot keep a tenant trial alive or purchase missing entitlements.&lt;/p&gt;

&lt;p&gt;We used a small synthetic text file so that data handling and model answers could be checked without introducing sensitive business documents during the first live test.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Grant the broker only one selected site
&lt;/h2&gt;

&lt;p&gt;We created a dedicated single-tenant application and service principal, requested the Microsoft Graph application permission &lt;code&gt;Sites.Selected&lt;/code&gt;, and assigned a read-only grant on the exact approved site.&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;flowchart LR
    H[PF human and registered agent] --&amp;gt; P[Current external policy]
    P --&amp;gt; B[Document broker]
    C[Dedicated app certificate] --&amp;gt; E[Entra token endpoint]
    E --&amp;gt; B
    B --&amp;gt; G[Microsoft Graph]
    G --&amp;gt; S[Explicitly selected site]
    G -. no grant .-&amp;gt; X[Other SharePoint sites]&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;The selected permission and the resource assignment are separate setup steps. See &lt;a href="https://learn.microsoft.com/en-us/graph/permissions-selected-overview" rel="noopener noreferrer"&gt;Microsoft's selected permissions overview&lt;/a&gt; for the underlying model. Our broker adds its own fixed-site and human/agent checks above that platform boundary.&lt;/p&gt;

&lt;p&gt;The intended assignment shape is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"roles"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"read"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"grantedToIdentities"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"application"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;dedicated-broker-application-id&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"displayName"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"copilot-m365-resource-broker"&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This illustrates the selected-site permission payload. It is not a substitute for administrator consent, tenant verification or current Graph API requirements.&lt;/p&gt;

&lt;p&gt;We did not add &lt;code&gt;Sites.Read.All&lt;/code&gt;, &lt;code&gt;Files.Read.All&lt;/code&gt; or tenant-wide full control to the runtime application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Separate administrative setup from runtime
&lt;/h2&gt;

&lt;p&gt;The administrator's setup client needed authority to inspect and assign site permissions. That is distinct from the broker's runtime access.&lt;/p&gt;

&lt;p&gt;We reviewed that administrative authorization separately, verified the signed-in tenant, checked whether the grant already existed, and created only the approved read assignment when absent. The setup consent could persist and required its own lifecycle review. It was never copied into the broker's token acquisition path.&lt;/p&gt;

&lt;p&gt;The repository's provisioning workflow prepares a plan before application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Prepares the setup plan. Review it before any apply operation.&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;--experimental-strip-types&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;scripts/sharepoint/setup.ts&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An apply operation requires the newly reviewed plan's own hash and the correct administrative identity. Historical hashes from another run must not be pasted into a new environment.&lt;/p&gt;

&lt;p&gt;We retained durable receipts to prevent duplicate applications, repeated grants or blind retries after a lost response.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Enroll a certificate and keep Graph tokens server-side
&lt;/h2&gt;

&lt;p&gt;The broker uses a dedicated certificate credential. The private key is held in a protected Vault KV record and read through a narrowly scoped, one-use credential reader. Only the public certificate is registered on the application.&lt;/p&gt;

&lt;p&gt;This is server-side certificate custody. It is not a non-exportable Transit signer: the authorized broker process receives the private key in memory. That distinction matters for a production threat model.&lt;/p&gt;

&lt;p&gt;The token request targets one approved tenant and the fixed Graph &lt;code&gt;.default&lt;/code&gt; scope:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;POST https://login.microsoftonline.com/&amp;lt;approved-tenant&amp;gt;/oauth2/v2.0/token
Content-Type: application/x-www-form-urlencoded

grant_type=client_credentials
client_id=&amp;lt;dedicated-broker-application-id&amp;gt;
scope=https%3A%2F%2Fgraph.microsoft.com%2F.default
client_assertion_type=urn%3Aietf%3Aparams%3Aoauth%3Aclient-assertion-type%3Ajwt-bearer
client_assertion=&amp;lt;fresh-certificate-signed-assertion&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The implementation uses a fresh short-lived assertion, a unique identifier and the approved certificate thumbprint. Its PS256 and &lt;code&gt;x5t#S256&lt;/code&gt; profile follows the &lt;a href="https://learn.microsoft.com/en-us/entra/identity-platform/certificate-credentials" rel="noopener noreferrer"&gt;Microsoft certificate credential format&lt;/a&gt;. Do not reuse the PF client's algorithm, assertion audience or key simply because both flows use signed JWTs.&lt;/p&gt;

&lt;p&gt;The returned Graph token is an internal app credential. It does not identify the external human. We do not send it to the phone, a prompt or a Copilot tool input.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Prove transport before claiming federation
&lt;/h2&gt;

&lt;p&gt;We first performed bounded app-level metadata and content checks against one uploaded file. That proved the certificate, selected-site permission and transport worked.&lt;/p&gt;

&lt;p&gt;It did not prove that an external human or agent was authorized. Those early probes had no PF document grant. We explicitly kept their acceptance category at app-level transport and integrity.&lt;/p&gt;

&lt;p&gt;This separation was useful when Graph returned metadata successfully but the reader stopped at a parent-site comparison. A successful HTTP status did not establish that every identity field matched our expectations.&lt;/p&gt;

&lt;p&gt;Read-only diagnostics showed the returned parent site reference used the site's collection GUID representation. The original check expected a composite site identifier. We added exact handling for the observed representation and retained mandatory host, collection, web, drive and item bindings.&lt;/p&gt;

&lt;p&gt;We also handled case normalization for GUID components without making arbitrary URL or host comparisons case-insensitive. A precise representation repair is safer than disabling a site check because one real response differs from a fixture.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 6: Constrain metadata, content and redirects
&lt;/h2&gt;

&lt;p&gt;For the initial file, the server pinned the site, drive, item, unique identifier, filename, size, MIME type and expected content hash. Metadata was checked before content access.&lt;/p&gt;

&lt;p&gt;The read path validates the version and uses a version-bound content request. If Graph returns a preauthenticated SharePoint download URL, the reader permits only a constrained HTTPS destination on the approved site host with the expected download path and unique file ID.&lt;/p&gt;

&lt;p&gt;It follows at most the reviewed redirect pattern, never forwards the Graph Authorization header to the download host and never exposes the signed download URL to the caller. Redirects are handled deliberately, not through an unrestricted &lt;code&gt;follow&lt;/code&gt; setting.&lt;/p&gt;

&lt;p&gt;This prevents a metadata response or compromised document from turning the broker into an arbitrary HTTP client. The same allowlist is applied before transmission and remains independent of model output.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 7: Add a separate document grant and PF chain
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;copilot.invoke&lt;/code&gt; capability is not document-read permission. We introduced dedicated document authority, PF processors and policies, client keys, audiences and resource consent for &lt;code&gt;m365.document.read&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;sequenceDiagram
    participant U as Verified human
    participant P as Grant authority
    participant V as Vault
    participant A as PF A
    participant B as PF B
    participant D as Document broker
    participant G as Graph and SharePoint
    U-&amp;gt;&amp;gt;P: Approve registered agent and exact resource
    P-&amp;gt;&amp;gt;V: Sign bounded document assertion
    V--&amp;gt;&amp;gt;P: Signed evidence
    P-&amp;gt;&amp;gt;A: Document exchange with independent actor proof
    A--&amp;gt;&amp;gt;P: Upstream document token
    P-&amp;gt;&amp;gt;B: Audience-specific second exchange
    B--&amp;gt;&amp;gt;D: Document broker proof
    D-&amp;gt;&amp;gt;P: Check current human, actor, grant and resource
    D-&amp;gt;&amp;gt;G: Bounded metadata and content requests
    D-&amp;gt;&amp;gt;P: Recheck authority before releasing text&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;The real container verification was initially isolated from Microsoft reads. It exercised actual Vault and both PF domains, replay denial, expiry and revocation, then cleaned up the owned grant and temporary client activation.&lt;/p&gt;

&lt;p&gt;PF clock skew and token lifetime granularity required care. We waited for actual token validity rather than weakening &lt;code&gt;nbf&lt;/code&gt; checks. The tested mobile profile later uses distinct minute-based lifetimes across authority, PF A and PF B; downstream validity remains bounded by verified parent evidence.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 8: Ground one actual Copilot answer
&lt;/h2&gt;

&lt;p&gt;The first complete document question combined two independent chains:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The document chain authorized the approved file read.&lt;/li&gt;
&lt;li&gt;A separate chat chain authorized the Copilot conversation.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The server read the 201-byte synthetic sample, checked its expected hash and supplied its bounded text as untrusted context. It created a new Direct Line conversation, used that conversation's fresh Generic OAuth card and sent one question.&lt;/p&gt;

&lt;p&gt;The observed answer identified the approved research color as &lt;strong&gt;teal&lt;/strong&gt;, the reference as &lt;strong&gt;FEDERATED-COPILOT-POC-001&lt;/strong&gt;, and the source as &lt;code&gt;federated-copilot-poc.txt&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Independent evidence confirmed both human and actor identity, distinct chat and document grants, current policy decisions, bounded Graph requests, the constrained content download and grant revocation before release. The system did not rely on the answer text alone as proof that authorization worked.&lt;/p&gt;

&lt;p&gt;This was server-supplied context. It was not a native Copilot SharePoint connector, unrestricted tenant search or autonomous document access.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 9: Reduce repeated browser logins carefully
&lt;/h2&gt;

&lt;p&gt;The first workflow required separate fresh login evidence for several purposes. That was useful for isolation but cumbersome to demonstrate.&lt;/p&gt;

&lt;p&gt;We prepared a narrower browser profile with brief PF session reuse, removed identity-only approval repetition and added a visible default-on resource approval choice. Opting out retained manual approval. We kept the separate chat and document grants, registered agent and revocation checks.&lt;/p&gt;

&lt;p&gt;Fewer prompts did not mean one universal token. The browser session, resource consents, provider login token and delegated execution credentials remained distinct objects with different lifetimes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 10: Expand to bounded text discovery
&lt;/h2&gt;

&lt;p&gt;The mobile work extends the server from a pinned sample to eligible documents within the already approved site. It enumerates that site's drives and folders under fixed limits rather than issuing unrestricted Graph search.&lt;/p&gt;

&lt;p&gt;The current profile permits at most 16 UTF-8 &lt;code&gt;.txt&lt;/code&gt; documents, 128 visited nodes, 64 discovery/read requests and 262,144 aggregate bytes. PDF, DOCX and scanned documents are unsupported. Unsupported files are counted and disclosed; they are not quietly described as readable.&lt;/p&gt;

&lt;p&gt;Each eligible file still requires site/drive/item validation, MIME and size checks, current authorization and version consistency. Changed content invalidates existing context and requires a new chat. There is no cross-chat document cache presented as current authority.&lt;/p&gt;

&lt;p&gt;The broader reader has local synthetic multi-document coverage. The live evidence described above remains one approved sample and one question. We have not promoted that result into live multi-document acceptance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why this boundary matters
&lt;/h2&gt;

&lt;p&gt;A broker app permission can outlive a person's current consent. A document can contain instructions that attempt to expand the task. A model can answer convincingly even when a test used mock content.&lt;/p&gt;

&lt;p&gt;Separating Entra app access, external human/agent policy, constrained retrieval and independently checked evidence makes those failure modes observable. Part 6 takes the same separation to a fingerprint-unlocked Android chat application.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>security</category>
      <category>microsoft</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Building a Federated Copilot: Part 4, Making Copilot Studio Accept the Right Token</title>
      <dc:creator>DarkEdges</dc:creator>
      <pubDate>Tue, 03 Nov 2026 20:27:19 +0000</pubDate>
      <link>https://dev.to/darkedges/building-a-federated-copilot-part-4-making-copilot-studio-accept-the-right-token-1aik</link>
      <guid>https://dev.to/darkedges/building-a-federated-copilot-part-4-making-copilot-studio-accept-the-right-token-1aik</guid>
      <description>&lt;p&gt;The most time-consuming part of the integration was not generating another JWT. It was proving that the particular credential sent to a Microsoft endpoint belonged at that endpoint.&lt;/p&gt;

&lt;p&gt;We had already verified real PF exchanges and policy. Copilot Studio still returned HTTP 400. Later, sign-in worked while a connector returned HTTP 401. Each result described a different boundary.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Establish the Microsoft environment
&lt;/h2&gt;

&lt;p&gt;The project began without a usable Copilot Studio environment. We prepared Power Platform tooling and an environment plan, then worked through the actual tenant's capacity, maker access, licensing and publishing requirements.&lt;/p&gt;

&lt;p&gt;An Azure subscription alone did not prove Dataverse capacity or a Copilot maker entitlement. The observed errors included a self-service signup requirement and &lt;code&gt;User license not found&lt;/code&gt; while creating or saving an agent.&lt;/p&gt;

&lt;p&gt;The practical sequence was to verify the signed-in tenant and account, inspect environment capacity, configure the approved billing or licensing arrangement, grant the maker access allowed by tenant policy, and publish a dedicated test agent.&lt;/p&gt;

&lt;p&gt;We created a small budget with notifications. That budget was an alert mechanism, not a spending cutoff. Product licensing and trial conditions change, so reproduce these checks against current &lt;a href="https://learn.microsoft.com/en-us/power-platform/admin/create-environment" rel="noopener noreferrer"&gt;Power Platform environment requirements&lt;/a&gt;, rather than treating a historical portal screenshot as a license guide.&lt;/p&gt;

&lt;p&gt;The maker account is an internal administrative identity. None of this creates Entra accounts for the external PF users.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Put only necessary PF endpoints on public HTTPS
&lt;/h2&gt;

&lt;p&gt;Microsoft's callback and the user's browser need reachable provider endpoints. We used an existing locally managed Cloudflare Tunnel on the Windows host.&lt;/p&gt;

&lt;p&gt;The public names in this article use examples:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Host&lt;/th&gt;
&lt;th&gt;Exposed purpose&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;pf-a.copilot.example.com&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Reviewed authorization, token, metadata, JWKS and required login assets&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;pf-b.copilot.example.com&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Only the reviewed public trust endpoints&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;relay.copilot.example.com&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Exact delegated diagnostic route&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;agent.copilot.example.com&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Human portal and later mobile API&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;DNS records, edge certificates and tunnel ingress are separate objects. Creating a DNS route did not populate a locally managed connector's configuration. A wildcard certificate did not authorize wildcard application routing.&lt;/p&gt;

&lt;p&gt;We kept deny-all fallbacks, preserved origin TLS verification and checked the connector process before restarting it. PF administration ports were not added to public ingress. The host and connector version remained explicit deployment dependencies.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Configure Generic OAuth and publish
&lt;/h2&gt;

&lt;p&gt;The agent uses manual authentication with Generic OAuth 2. Its callback for the original browser integration was:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://token.botframework.com/.auth/web/redirect
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The authorization template used fixed server configuration, a state value and the provider scope. An illustrative PF-specific query is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;?client_id={ClientId}&amp;amp;response_type=code&amp;amp;redirect_uri={RedirectUrl}&amp;amp;scope={Scopes}&amp;amp;state={State}&amp;amp;pfidpadapterid=consentHTMLForm&amp;amp;resource=urn%3Acopilot%3Alogin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The token endpoint was the PF A &lt;code&gt;/as/token.oauth2&lt;/code&gt; endpoint. The authorization-code body used the exact placeholders expected by the editor:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;code={Code}&amp;amp;grant_type=authorization_code&amp;amp;redirect_uri={RedirectUrl}&amp;amp;client_id={ClientId}&amp;amp;client_secret={ClientSecret}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are examples of the original dedicated Generic OAuth client configuration. They are not instructions to paste a real secret into an article or to replace the later mobile client's signed authentication with a shared secret.&lt;/p&gt;

&lt;p&gt;The configuration review also covered the less visible fields:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Field&lt;/th&gt;
&lt;th&gt;How we treated it&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Scope list delimiter&lt;/td&gt;
&lt;td&gt;Matched the configured editor value, comma in this lab&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Scopes&lt;/td&gt;
&lt;td&gt;Only &lt;code&gt;copilot.login&lt;/code&gt; for the provider sign-in purpose&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Token URL query&lt;/td&gt;
&lt;td&gt;No additional query parameters; form fields belong in the body&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Refresh URL&lt;/td&gt;
&lt;td&gt;The provider token endpoint when a separately enabled refresh flow is intended&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Refresh URL query&lt;/td&gt;
&lt;td&gt;No additional query parameters&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Refresh body&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;refresh_token={RefreshToken}&amp;amp;grant_type=refresh_token&amp;amp;client_id={ClientId}&amp;amp;client_secret={ClientSecret}&lt;/code&gt; for that client authentication configuration&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;OAuth metadata&lt;/td&gt;
&lt;td&gt;Use only verified provider metadata appropriate to the selected configuration; the original manually configured profile left this blank&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PKCE challenge method&lt;/td&gt;
&lt;td&gt;S256, with provider enforcement checked separately&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The original shared Generic OAuth client was authorization-code-only. Filling in a refresh template does not enable its refresh grant or prove renewal. The new mobile client uses a separate signed-authentication refresh path and still needs live acceptance. We did not copy the mobile &lt;code&gt;offline_access&lt;/code&gt; scope into the original agent's scope field by assumption.&lt;/p&gt;

&lt;p&gt;We checked saved values after editing. One observed problem was a malformed saved token URL. A field that looked right before saving was not evidence of the stored configuration.&lt;/p&gt;

&lt;p&gt;Save and publish are separate operations; &lt;a href="https://learn.microsoft.com/en-us/microsoft-copilot-studio/configuration-end-user-authentication" rel="noopener noreferrer"&gt;Microsoft documents publication as necessary for authentication changes to take effect&lt;/a&gt;. We also used a fixed Boolean topic reporting &lt;code&gt;User.IsLoggedIn&lt;/code&gt;; a greeting or a model-generated claim of federation was not a verification result.&lt;/p&gt;

&lt;p&gt;The Native App connection string shown by the Microsoft 365 Agents SDK view was not automatically the Direct Line endpoint expected by our adapter. We treated the transport contracts separately instead of substituting URLs with similar names.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Separate four credential types
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Credential&lt;/th&gt;
&lt;th&gt;Role&lt;/th&gt;
&lt;th&gt;Does it authorize a document or tool?&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Direct Line channel secret or conversation token&lt;/td&gt;
&lt;td&gt;Channel transport&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PF A provider user access token&lt;/td&gt;
&lt;td&gt;Generic OAuth sign-in&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PF B broker token&lt;/td&gt;
&lt;td&gt;Delegated broker operation&lt;/td&gt;
&lt;td&gt;Only under its exact audience and current policy&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PF B tool or document token&lt;/td&gt;
&lt;td&gt;Purpose-specific delegated execution&lt;/td&gt;
&lt;td&gt;Only for its configured resource and grant&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;One confirmed bug crossed these boundaries. An earlier runner posted a PF B delegated tool token to the Generic OAuth secure URL. That token passed its own local checks, but the agent was configured for the PF A provider user token.&lt;/p&gt;

&lt;p&gt;The repair introduced a separate provider verifier and an authoritative binding from that verified provider identity to the already verified broker human. It did not invent missing actor or grant claims in the user token.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Use the fresh OAuth card exactly
&lt;/h2&gt;



&lt;pre data-lang="mermaid"&gt;&lt;code&gt;sequenceDiagram
    participant B as Trusted backend client
    participant DL as Direct Line
    participant C as Copilot Studio
    participant PF as PF A provider
    participant SP as Secure token-post endpoint
    B-&amp;gt;&amp;gt;PF: Obtain and verify provider user access token
    B-&amp;gt;&amp;gt;DL: Create a new conversation
    DL-&amp;gt;&amp;gt;C: Begin published authentication flow
    C--&amp;gt;&amp;gt;B: OAuth card with tokenPostResource.sasUrl
    B-&amp;gt;&amp;gt;B: Validate card, destination and current authority
    B-&amp;gt;&amp;gt;SP: POST exact card URL with token JSON
    SP--&amp;gt;&amp;gt;B: Sign-in result
    B-&amp;gt;&amp;gt;DL: Continue only after verified sign-in&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;The backend extracts &lt;code&gt;content.tokenPostResource.sasUrl&lt;/code&gt; from an attachment with content type &lt;code&gt;application/vnd.microsoft.card.oauth&lt;/code&gt;. It uses that exact URL from the new conversation and sends the configured provider token in the documented JSON property. This is the flow described in &lt;a href="https://learn.microsoft.com/en-us/microsoft-copilot-studio/configure-sso-3p" rel="noopener noreferrer"&gt;Microsoft's Generic OAuth SSO documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;A deliberately non-runnable request shape is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;POST &amp;lt;fresh-card-secure-url&amp;gt;
Content-Type: application/json

{"token":"&amp;lt;verified-PF-A-provider-user-access-token&amp;gt;"}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We do not reconstruct the URL, reuse a previous conversation's card or add the Direct Line Authorization header to this POST. Destination rules are pinned; an activity cannot instruct the server to send a credential to an arbitrary host.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 6: Diagnose HTTP 400 without guessing
&lt;/h2&gt;

&lt;p&gt;We observed responses classified as expired, including the literal response &lt;code&gt;Token is expired&lt;/code&gt;. Some posted PF tokens were locally within &lt;code&gt;nbf&lt;/code&gt; and &lt;code&gt;exp&lt;/code&gt;, and the card-to-POST delay was short.&lt;/p&gt;

&lt;p&gt;That evidence does not identify which Microsoft-side object was considered expired. The secure URL, OAuth state, connection binding and token validation are distinct possibilities. We corrected the proven token-type mismatch without declaring that it explained every historical 400.&lt;/p&gt;

&lt;p&gt;The investigation recorded token provenance, verified timing comparisons, fresh-card use, method, content type, property names and sanitized request IDs. When exact captures were explicitly requested, they were retained privately in Vault, not pasted into support messages or committed as fixtures.&lt;/p&gt;

&lt;p&gt;A later approved test with a 60-minute PF A provider token returned HTTP 200 and the published signed-in diagnostic succeeded. We extended that dedicated provider lifetime, not the broker and tool authorization lifetimes. The result demonstrates a working lab configuration; it does not prove a universal Microsoft minimum lifetime or explain the earlier failures.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 7: Prove the connector's headers before using a real token
&lt;/h2&gt;

&lt;p&gt;Sign-in success still did not prove delegated tool execution. The custom connector initially returned &lt;code&gt;ConnectorAuthorizationError&lt;/code&gt; with HTTP 401.&lt;/p&gt;

&lt;p&gt;We inspected fixed origin diagnostics containing only header-presence and outcome categories. A synthetic unbound provider value could safely distinguish missing transport from a later authorization denial.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Observation&lt;/th&gt;
&lt;th&gt;Supported interpretation&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;401, required provider header absent&lt;/td&gt;
&lt;td&gt;Request did not reach provider validation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;403, provider and caller present with synthetic value&lt;/td&gt;
&lt;td&gt;Header forwarding worked, authority correctly denied&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;502&lt;/td&gt;
&lt;td&gt;Transport or upstream path failed; not an identity verdict&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Fixed successful diagnostic plus policy evidence&lt;/td&gt;
&lt;td&gt;Actual delegated operation verified&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;An explicit forwarding policy did not repair the missing header in our observed connector path. Changing the managed parameter to &lt;code&gt;PfUserAccessToken&lt;/code&gt;, updating the system-variable mapping and selecting that exact transport at the relay did.&lt;/p&gt;

&lt;p&gt;This was a measured workaround, not a claim that all hyphenated headers fail in Power Platform. The managed profile rejects mixed or alternate header formats; it does not merge them or weaken token validation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 8: Bind the provider token to delegated execution
&lt;/h2&gt;



&lt;pre data-lang="mermaid"&gt;&lt;code&gt;flowchart TD
    U[Verified provider token] --&amp;gt; B[Private exact-token binding]
    A[Verified agent and broker authority] --&amp;gt; B
    C[Separately authenticated connector caller] --&amp;gt; R[Relay]
    B --&amp;gt; R
    R --&amp;gt; P[Current grant and policy checks]
    P --&amp;gt; T[Private delegated tool]
    T --&amp;gt; V[Check result and authority before release]&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;The provider token alone still grants no tool permission. The relay requires a separate caller credential and a short-lived, one-use exact-token binding created from independently verified human and agent evidence. The private tool checks purpose-specific PF proof and current policy.&lt;/p&gt;

&lt;p&gt;The eventual live interactive diagnostic succeeded through the published connector, the real PF chain and the private tool. Independent audit confirmed human, actor, organisation, grant, mode, resource and audience continuity, exactly one successful origin operation and owned cleanup.&lt;/p&gt;

&lt;h2&gt;
  
  
  The credential-trace limitation remains
&lt;/h2&gt;

&lt;p&gt;The PoC passed &lt;code&gt;System.User.AccessToken&lt;/code&gt; through a tool input. We could not establish credential protection across Microsoft tool execution traces. The owner's explicit synthetic-data PoC exception allowed the experiment, but success did not resolve that protection gap.&lt;/p&gt;

&lt;p&gt;Review &lt;a href="https://learn.microsoft.com/en-us/microsoft-copilot-studio/voice-sensitive-data" rel="noopener noreferrer"&gt;Microsoft's sensitive-data limitations&lt;/a&gt; for the relevant action and channel. We do not treat test-pane redaction or the absence of an observed leak as a guarantee. A production user-authenticated connector would change the trust model and requires its own design review.&lt;/p&gt;

&lt;p&gt;Part 5 adds document access through a selected-site Entra application while keeping external human and agent authorization separate.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>security</category>
      <category>oauth</category>
      <category>microsoft</category>
    </item>
    <item>
      <title>Building a Federated Copilot: Part 3, Consent, Revocation and Vault</title>
      <dc:creator>DarkEdges</dc:creator>
      <pubDate>Tue, 03 Nov 2026 20:27:15 +0000</pubDate>
      <link>https://dev.to/darkedges/building-a-federated-copilot-part-3-consent-revocation-and-vault-3j39</link>
      <guid>https://dev.to/darkedges/building-a-federated-copilot-part-3-consent-revocation-and-vault-3j39</guid>
      <description>&lt;p&gt;Real token exchange answers whether two identity domains can exchange signed evidence. It does not answer who owns a grant, how revocation survives a restart or which process may use a signing key.&lt;/p&gt;

&lt;p&gt;This part adds those missing controls: persistent policy, a human consent flow, an authenticated assertion authority and scoped Vault custody.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Make the registry authoritative
&lt;/h2&gt;

&lt;p&gt;We built a transactional store around organisations, external humans, registered agents, grants, approval evidence, consumed assertion identifiers and audit records.&lt;/p&gt;

&lt;p&gt;An external principal is an immutable issuer, subject and organisation binding. An agent has its own independently registered issuer and subject. Registry records can be suspended; a request cannot repair or reactivate them.&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;erDiagram
    ORGANISATION ||--o{ HUMAN : contains
    ORGANISATION ||--o{ AGENT : registers
    HUMAN ||--o{ GRANT : owns
    AGENT ||--o{ GRANT : acts_under
    GRANT ||--|| APPROVAL_EVIDENCE : requires
    GRANT ||--o{ AUDIT_EVENT : records
    WORKLOAD ||--o{ USED_ASSERTION : authenticates&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;The diagram is a conceptual relationship map. The implementation also tracks consent references, versions and profile-specific state needed for recovery and replay rejection.&lt;/p&gt;

&lt;p&gt;SQLite is suitable for this single-host PoC because transactions can make a policy decision and its audit event commit together. The store uses prepared statements, foreign keys, bounded locking, WAL and full synchronous commits. It is not a claim of multi-region availability or safe operation on a network filesystem.&lt;/p&gt;

&lt;p&gt;Registry and grant decisions have no permit cache. A service outage or unavailable database denies the operation rather than reusing yesterday's permission.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Authenticate the policy request itself
&lt;/h2&gt;

&lt;p&gt;A gateway's access to the policy API does not let it submit arbitrary identity claims and ask for a Boolean answer. The policy service independently verifies the signed PF token evidence.&lt;/p&gt;

&lt;p&gt;The caller also signs its HTTP request. In this implementation the request JWT binds:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The registered workload ID as issuer and subject.&lt;/li&gt;
&lt;li&gt;The exact configured endpoint audience.&lt;/li&gt;
&lt;li&gt;The method and SHA-256 hash of the exact body bytes.&lt;/li&gt;
&lt;li&gt;A short validity interval and unique, persistently consumed &lt;code&gt;jti&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;A fixed signing type, algorithm and key ID.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This protects a different boundary from the delegated access token. The workload signature authenticates who is asking for a decision. The PF token and current database establish whose delegated operation is being evaluated.&lt;/p&gt;

&lt;p&gt;Decision callers cannot register principals or create grants. Consent callers cannot silently become registry administrators. Roles are also organisation-scoped.&lt;/p&gt;

&lt;p&gt;The resulting separation is visible in the API design:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operation&lt;/th&gt;
&lt;th&gt;Caller role&lt;/th&gt;
&lt;th&gt;Key restriction&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Evaluate one capability&lt;/td&gt;
&lt;td&gt;Decision workload&lt;/td&gt;
&lt;td&gt;Verify token evidence and current grant&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Preview human consent&lt;/td&gt;
&lt;td&gt;Consent workload&lt;/td&gt;
&lt;td&gt;Independently verify current OIDC login&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Approve or revoke owned consent&lt;/td&gt;
&lt;td&gt;Consent workload&lt;/td&gt;
&lt;td&gt;Bind the verified owner and reviewed terms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Register principals&lt;/td&gt;
&lt;td&gt;Registry administrator&lt;/td&gt;
&lt;td&gt;No public application access&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Administrative grant management&lt;/td&gt;
&lt;td&gt;Grant administrator&lt;/td&gt;
&lt;td&gt;Explicitly separate administrative authority&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Step 3: Add real human login
&lt;/h2&gt;

&lt;p&gt;The browser portal uses PF A Authorization Code flow with required PAR and S256 PKCE. The client authenticates with a signed JWT. State, nonce and PKCE verifier are server-held and tied to the initiating browser transaction.&lt;/p&gt;

&lt;p&gt;For the prepared local lab:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;npm&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;run&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;pf:configure&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;npm&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;run&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;consent:serve&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These commands reconcile local PF configuration and start a local consent portal. They should not be run over a later active profile without reviewing their lifecycle assumptions.&lt;/p&gt;

&lt;p&gt;The initial browser flow has two separate decisions. PF authenticates the human and authorizes the identity request. The application then asks whether the registered agent may perform a specific resource operation for a stated period.&lt;/p&gt;

&lt;p&gt;We verify signature, exact issuer and client audience, nonce, recent &lt;code&gt;auth_time&lt;/code&gt;, token validity and &lt;code&gt;at_hash&lt;/code&gt; when present. We do not use an email string from the page to locate or provision an Entra account.&lt;/p&gt;

&lt;p&gt;Cookies are secure, HTTP-only, host-only and SameSite=Lax. State-changing forms require the expected origin and session-bound CSRF. Extra form fields that attempt to supply human, actor, scope or resource authority are refused.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Bind consent to the review the human saw
&lt;/h2&gt;



&lt;pre data-lang="mermaid"&gt;&lt;code&gt;sequenceDiagram
    participant U as Human browser
    participant C as Consent portal
    participant F as PF A
    participant P as Policy authority
    participant DB as Durable store
    C-&amp;gt;&amp;gt;F: PAR and authorization code flow with PKCE
    F--&amp;gt;&amp;gt;C: Code bound to callback and transaction
    C-&amp;gt;&amp;gt;F: Redeem code using signed client authentication
    C-&amp;gt;&amp;gt;P: Verified login evidence for consent preview
    P--&amp;gt;&amp;gt;C: Registered agent, resource, modes and review digest
    U-&amp;gt;&amp;gt;C: Approve reviewed terms
    C-&amp;gt;&amp;gt;P: Login evidence and exact review digest
    P-&amp;gt;&amp;gt;DB: Commit grant, approval evidence and audit
    DB--&amp;gt;&amp;gt;P: New grant ID
    P--&amp;gt;&amp;gt;C: Approved permission reference&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;A review digest ties the decision to the login, human, agent, resource and allowed options. Approval does not silently expand if server policy changes between rendering and submission.&lt;/p&gt;

&lt;p&gt;The initial browser implementation allowed explicit durations and a separate background-execution opt-in. The later mobile profile has a different, disclosed default-on approval preference for fixed capabilities. Those are separate consent designs, not a retroactive change to historical grants.&lt;/p&gt;

&lt;p&gt;Approval evidence records digests and provenance rather than raw ID tokens. A consumed login cannot mint another unrelated grant. Revocation is permanent for the grant ID.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Issue fresh assertions under current authority
&lt;/h2&gt;

&lt;p&gt;The registered agent authenticates to the assertion authority and supplies its independent actor proof. The authority resolves the human from the grant, checks current organisation and principal state, validates the requested mode and operation, then signs a short-lived assertion.&lt;/p&gt;

&lt;p&gt;The authority checks again before releasing the result. A grant revoked during signing must not produce usable released evidence.&lt;/p&gt;

&lt;p&gt;The gateway no longer opens the policy database or imports the authority's private key merely to request an assertion. The signing dependency has an interface, so local development and Vault-backed execution remain explicit choices rather than fallback paths.&lt;/p&gt;

&lt;p&gt;Autonomous assertion issuance does not replay a stored browser login token. It relies on a grant that permits autonomous work, current independent agent authentication and fresh issuance. This local capability must still be distinguished from unverified autonomous Copilot provider SSO.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 6: Introduce Vault by key purpose
&lt;/h2&gt;

&lt;p&gt;We used actual local Vault services to exercise non-exportable signing, scoped credential reads, denial cases, outages and rotation.&lt;/p&gt;

&lt;p&gt;Vault Transit owns dedicated assertion signing keys. The workload can ask to sign at an allowed path but cannot export the key. This is the relevant property of &lt;a href="https://developer.hashicorp.com/vault/docs/secrets/transit" rel="noopener noreferrer"&gt;Vault Transit&lt;/a&gt;, rather than treating the entire secret manager as one unlimited key store.&lt;/p&gt;

&lt;p&gt;Other credentials in this PoC have different custody. PF client private keys and the Graph broker certificate key are stored in protected KV records and retrieved by authorized server processes. They are exportable to those processes. They must not be described as non-exportable Transit keys.&lt;/p&gt;

&lt;p&gt;The mobile deployment eventually separated five certificate-authenticated roles:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Role&lt;/th&gt;
&lt;th&gt;Access&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Runtime reader&lt;/td&gt;
&lt;td&gt;One use, short-lived read of the exact mobile runtime record&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Provider store&lt;/td&gt;
&lt;td&gt;Read and CAS-update only mobile provider session records&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Agent signer&lt;/td&gt;
&lt;td&gt;Sign with the dedicated agent Transit key&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Authority signer&lt;/td&gt;
&lt;td&gt;Sign with the dedicated authority Transit key&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Graph reader&lt;/td&gt;
&lt;td&gt;One use, short-lived read of the existing broker credential record&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The cert login mechanism is documented in &lt;a href="https://developer.hashicorp.com/vault/docs/auth/cert" rel="noopener noreferrer"&gt;Vault TLS certificate authentication&lt;/a&gt;. Our exact policies, lease ceilings and record boundaries are project-specific.&lt;/p&gt;

&lt;p&gt;A narrow policy example illustrates the intent:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Illustrative policy for one reader, not an operator policy.&lt;/span&gt;
&lt;span class="nx"&gt;path&lt;/span&gt; &lt;span class="s2"&gt;"mobile-runtime/data/credentials"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;capabilities&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"read"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A reader should fail to list unrelated secrets, write its own policy, read the Graph key through the wrong role or sign with another purpose's key. Those denials are part of verification.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 7: Handle leases and secret versions deliberately
&lt;/h2&gt;

&lt;p&gt;Reusable workload leases are short-lived and reauthenticated before expiry. A certificate login returning unexpected policies, excessive lifetime or an invalid use count is rejected. A failed renewal clears usable in-memory authority and stops the service.&lt;/p&gt;

&lt;p&gt;Unattended runtime startup does not use a root token, bootstrap credential or automatic unseal operation. Host availability and Vault seal recovery remain operational responsibilities.&lt;/p&gt;

&lt;p&gt;For mutable provider records we use compare-and-set. Before transmitting a rotating refresh token, the store records it as spent. If the response is lost, the application requires a new sign-in instead of using the same refresh token again.&lt;/p&gt;

&lt;p&gt;For enrollment and IAM changes we retain a durable progression:&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;stateDiagram-v2
    [*] --&amp;gt; Prepared
    Prepared --&amp;gt; Approved
    Approved --&amp;gt; PendingWrite
    PendingWrite --&amp;gt; Confirmed: Read-back matches
    PendingWrite --&amp;gt; Uncertain: Failure or lost response
    Uncertain --&amp;gt; Reconciled: Inspect owned state
    Reconciled --&amp;gt; Confirmed: Actual result verified
    Confirmed --&amp;gt; [*]&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;The state machine intentionally has no "clear the file and try again" transition.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 8: Minimize audit without losing revocation history
&lt;/h2&gt;

&lt;p&gt;Operational audit records contain fixed outcomes and pseudonymous references, not tokens, questions or document excerpts. The selected local retention is one day, with a small bounded journal.&lt;/p&gt;

&lt;p&gt;Replay state, revoked grant records and usage counters have different purposes. Deleting audit events must not reactivate a grant, erase a consumed assertion prematurely or reset the demo allowance.&lt;/p&gt;

&lt;p&gt;The Windows custody directory is restricted to the owner and SYSTEM. We also encountered a practical ACL error: trying to read or apply security information unnecessarily requested a privilege the process did not have. The repair constructed the required discretionary ACL directly rather than attempting a broader privileged operation.&lt;/p&gt;

&lt;p&gt;This remains a shared-host PoC. ACLs, Vault roles and application checks do not establish isolation from a fully privileged administrator.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is verified at this boundary
&lt;/h2&gt;

&lt;p&gt;The local system has real consent, persistent revocation, independently authenticated policy requests and Vault-backed signing. Tests cover wrong callers, actor substitution, replay, expiry, suspension, signing failure and revocation during asynchronous work.&lt;/p&gt;

&lt;p&gt;The next challenge is Microsoft-specific: a valid delegated PF token is not necessarily the credential Copilot Studio expects for sign-in. Part 4 follows that integration and the failures that exposed the difference.&lt;/p&gt;

</description>
      <category>security</category>
      <category>oauth</category>
      <category>vault</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Building a Federated Copilot: Part 2, Real PingFederate Token Exchange</title>
      <dc:creator>DarkEdges</dc:creator>
      <pubDate>Tue, 03 Nov 2026 20:26:38 +0000</pubDate>
      <link>https://dev.to/darkedges/building-a-federated-copilot-part-2-real-pingfederate-token-exchange-2hdj</link>
      <guid>https://dev.to/darkedges/building-a-federated-copilot-part-2-real-pingfederate-token-exchange-2hdj</guid>
      <description>&lt;p&gt;Part 1 defined the identity contract. This part puts actual PingFederate servers behind it.&lt;/p&gt;

&lt;p&gt;The objective was narrow: implement the Gateway 2 exchange adapter, trust only approved issuers and JWKS, authenticate the confidential client with a signed JWT, and preserve the original human and actor. The local simulation had to continue working.&lt;/p&gt;

&lt;p&gt;The container lab used PingFederate 13.1.0 on an existing Windows Docker host. That version describes the tested lab, not a recommendation to ignore later patches or your organisation's supported release policy.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Create an explicit adapter boundary
&lt;/h2&gt;

&lt;p&gt;The real implementation lives behind typed contracts in &lt;code&gt;src/adapters/token-exchange.ts&lt;/code&gt;. The JOSE implementation, configuration loader and mode selection are separate modules.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Abbreviated interface, not the repository's full exported type.&lt;/span&gt;
&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;ExchangeAdapter&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;exchange&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;upstreamBearer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;VerifiedExchangeResult&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Mode selection is explicit. A production configuration cannot silently fall back to mock behavior when JOSE is missing, JWKS is unreachable or the token endpoint fails.&lt;/p&gt;

&lt;p&gt;Install the optional real-adapter dependencies and run their tests separately:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;npm&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;ci&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;--include&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;optional&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nx"&gt;npm&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;run&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;test:production&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The baseline &lt;code&gt;npm test&lt;/code&gt; path remains separate. The real adapter does not import development private keys, fixture grants or the mock JWT helper.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Prepare two independent PF containers
&lt;/h2&gt;

&lt;p&gt;We reused the preparation approach from an existing local PingFederate PAR proof of concept. We did not modify its containers or reuse its runtime state as our own deployment.&lt;/p&gt;

&lt;p&gt;The project-specific flow was:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;npm&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;run&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;pf:prepare&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;npm&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;run&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;pf:up&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;npm&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;run&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;pf:test&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;npm&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;run&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;pf:status&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are lab provisioning commands. Review their fixed object IDs, licensing inputs, TLS files and configuration before running them in another environment.&lt;/p&gt;

&lt;p&gt;The preparation step places private inputs in ignored local storage. It creates independent admin credentials and preserves the named volumes alongside their associated keys. It does not print passwords or produce shareable credential fixtures.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Component&lt;/th&gt;
&lt;th&gt;Runtime&lt;/th&gt;
&lt;th&gt;Administration&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;PF A&lt;/td&gt;
&lt;td&gt;&lt;code&gt;https://localhost:9033&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;https://localhost:9996&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PF B&lt;/td&gt;
&lt;td&gt;&lt;code&gt;https://localhost:9034&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;https://localhost:9997&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;All host mappings bind to &lt;code&gt;127.0.0.1&lt;/code&gt;. Outbound requests verify the local CA. A self-signed lab certificate is not a reason to set TLS verification to false.&lt;/p&gt;

&lt;p&gt;Each domain has its own signing objects, exchange processors, policy mappings and confidential client. A successful exchange in one domain must not collapse the second domain's validation boundary.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Configure trust as deployment data
&lt;/h2&gt;

&lt;p&gt;An upstream trust entry specifies the issuer, JWKS URI, exact audience, allowed algorithm, allowed key IDs, actor namespace, organisation and maximum lifetime.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"issuer"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://pf-a.example.com"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"jwksUri"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://pf-a.example.com/pf/JWKS"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"audience"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"api://gateway-2"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"algorithms"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"RS256"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"keyIds"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"pf-a-current"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"pf-a-next"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"organisations"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"partner-a"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"actorIssuers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"https://partner-a.example/agents"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"maxLifetimeSeconds"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;180&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is an illustrative entry, not a complete environment configuration. The downstream profile is independent and targets the broker audience.&lt;/p&gt;

&lt;p&gt;We reject token-controlled &lt;code&gt;jku&lt;/code&gt;, embedded JWKs and alternate certificate URLs. A header can identify an approved key by &lt;code&gt;kid&lt;/code&gt;; it cannot choose where the verifier fetches trust.&lt;/p&gt;

&lt;p&gt;The validator checks signature, issuer, single exact audience, algorithm, key ID, validity, replay identity and the required delegation claims. Decoding a JWT is never treated as validation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Keep three audiences separate
&lt;/h2&gt;

&lt;p&gt;The live container tests exposed a distinction that is easy to lose in a mock:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Audience&lt;/th&gt;
&lt;th&gt;Purpose&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;api://gateway-2&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Who may consume the upstream access token&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Configured PF B authorization-server audience&lt;/td&gt;
&lt;td&gt;Who may consume the client-authentication assertion&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;api://copilot-broker&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Who may consume the exchanged access token&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;For our tested PF configuration, client authentication used the server base URL as the assertion audience. It did not use the broker audience. This is a configured interoperability choice, not a general instruction to change every OAuth client's audience.&lt;/p&gt;

&lt;p&gt;The client assertion uses the registered client ID as issuer and subject, a short expiry, a fresh &lt;code&gt;jti&lt;/code&gt;, and the client's pinned signing key:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Illustrative construction. Obtain privateKey from approved custody.&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;assertion&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;SignJWT&lt;/span&gt;&lt;span class="p"&gt;({})&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setProtectedHeader&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;alg&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;RS256&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;kid&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;clientKeyId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;typ&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;client-authentication+jwt&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setIssuer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;clientId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setSubject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;clientId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setAudience&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;configuredAssertionAudience&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setIssuedAt&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setExpirationTime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;60s&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setJti&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;crypto&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;randomUUID&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sign&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;privateKey&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The explicit &lt;code&gt;typ&lt;/code&gt; mattered in this lab: the tested PF configuration rejected a generic &lt;code&gt;JWT&lt;/code&gt; value for this authentication use. That observation belongs beside the version and configuration, not in a universal OAuth rule.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Send the exchange request once
&lt;/h2&gt;

&lt;p&gt;The request uses the token-exchange grant and signed client authentication:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;grant_type=urn:ietf:params:oauth:grant-type:token-exchange
subject_token=&amp;lt;verified-upstream-token&amp;gt;
subject_token_type=urn:ietf:params:oauth:token-type:access_token
requested_token_type=urn:ietf:params:oauth:token-type:access_token
client_id=&amp;lt;registered-gateway-client&amp;gt;
client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer
client_assertion=&amp;lt;fresh-signed-client-assertion&amp;gt;
resource=&amp;lt;administrator-configured-target&amp;gt;
scope=copilot.invoke
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a request shape. It intentionally contains no reusable values.&lt;/p&gt;

&lt;p&gt;Our PF access-token-manager selection required &lt;code&gt;resource&lt;/code&gt;. Sending an &lt;code&gt;audience&lt;/code&gt; parameter did not select the intended manager in that profile. We made the target parameter configurable and trusted configuration, while retaining strict validation of the resulting JWT audience.&lt;/p&gt;

&lt;p&gt;We do not retry a token POST after an uncertain response. A lost response could mean issuance succeeded. Network GETs for JWKS have narrowly bounded retry behavior; credential-bearing issuance is a different operation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 6: Validate the result independently
&lt;/h2&gt;



&lt;pre data-lang="mermaid"&gt;&lt;code&gt;sequenceDiagram
    participant G1 as Gateway 1
    participant G2 as Gateway 2
    participant A as Approved PF A JWKS
    participant P as Independent policy service
    participant B as PF B token endpoint
    participant J as Approved PF B JWKS
    G1-&amp;gt;&amp;gt;G2: Authenticated sender and PF A token
    G2-&amp;gt;&amp;gt;A: Resolve approved signing key
    G2-&amp;gt;&amp;gt;G2: Verify upstream token and identity contract
    G2-&amp;gt;&amp;gt;P: Check current grant and exact operation
    G2-&amp;gt;&amp;gt;B: Exchange with private_key_jwt
    B--&amp;gt;&amp;gt;G2: New access token
    G2-&amp;gt;&amp;gt;J: Resolve approved downstream signing key
    G2-&amp;gt;&amp;gt;G2: Verify audience, identity and bounded validity
    G2-&amp;gt;&amp;gt;P: Recheck current authority before release
    G2--&amp;gt;&amp;gt;G1: Release verified result&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;An HTTP 200 response does not bypass output validation. We check that the exchanged token carries the same human, original actor and actor issuer, organisation, grant and mode. It must have the intended scope and audience and must not extend authority beyond the applicable parent evidence.&lt;/p&gt;

&lt;p&gt;Both policy checks matter. A grant might be revoked while PF is processing issuance. The post-issuance check prevents a newly issued token from escaping under authority that disappeared during the call.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 7: Exercise the negative matrix against real PF
&lt;/h2&gt;

&lt;p&gt;The tests cover wrong issuer, audience, algorithm and key ID; missing or substituted actor; scope expansion; unknown resource; expired input; changed organisation; client assertion replay; and revocation before or during issuance.&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;flowchart TD
    T[Incoming signed token] --&amp;gt; V{Cryptographic profile valid?}
    V --&amp;gt;|No| D[Deny]
    V --&amp;gt;|Yes| P{Current grant permits operation?}
    P --&amp;gt;|No| D
    P --&amp;gt;|Yes| X[Exchange through PF B]
    X --&amp;gt; O{Output preserves identity and bounds?}
    O --&amp;gt;|No| D
    O --&amp;gt;|Yes| R{Authority still active?}
    R --&amp;gt;|No| D
    R --&amp;gt;|Yes| A[Release]&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;We also test redirect refusal, TLS failures, bounded timeouts and key rotation overlap. Stable error codes cross the adapter boundary; raw token responses, form bodies and private keys do not enter logs.&lt;/p&gt;

&lt;p&gt;For configuration work, dependent objects are staged with clients disabled. We record intent before mutation, read back actual state and refuse to turn an uncertain write into an automatic second creation.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the container result proves
&lt;/h2&gt;

&lt;p&gt;The real PF A and PF B chain works in the local lab for the tested interactive and grant-backed autonomous profiles. It preserves the human and actor and enforces current policy.&lt;/p&gt;

&lt;p&gt;It does not prove production hosting, Microsoft authentication or document access. Those are separate integrations.&lt;/p&gt;

&lt;p&gt;Part 3 gives the grants and signing keys durable ownership through the policy service and Vault. For protocol background, see &lt;a href="https://datatracker.ietf.org/doc/html/rfc8693" rel="noopener noreferrer"&gt;RFC 8693&lt;/a&gt; and the &lt;a href="https://docs.pingidentity.com/pingfederate/13.1/developers_reference_guide/pf_token_endpoint.html" rel="noopener noreferrer"&gt;PingFederate token endpoint documentation&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>security</category>
      <category>oauth</category>
      <category>docker</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Building a Federated Copilot: Part 1, Identity Before Integration</title>
      <dc:creator>DarkEdges</dc:creator>
      <pubDate>Tue, 03 Nov 2026 20:26:34 +0000</pubDate>
      <link>https://dev.to/darkedges/building-a-federated-copilot-part-1-identity-before-integration-50en</link>
      <guid>https://dev.to/darkedges/building-a-federated-copilot-part-1-identity-before-integration-50en</guid>
      <description>&lt;p&gt;An external AI agent should be able to help a partner user work with an internal Copilot Studio agent. The partner authenticates with PingFederate, does not have an Entra account and should not acquire one as an accidental side effect of using the application.&lt;/p&gt;

&lt;p&gt;That requirement turns a chatbot integration into an identity engineering project. We need to know which human approved the work, which registered agent performs it, what that agent may do, and whether the permission is still active when a result leaves the system.&lt;/p&gt;

&lt;p&gt;This six-part series follows the implementation from a local simulation through real PingFederate containers, Vault custody, Copilot Studio authentication, selected-site SharePoint access and an Ionic React Android application. It includes mistakes and unresolved work because those boundaries determine what the system can honestly claim.&lt;/p&gt;

&lt;p&gt;All domains, tenant details and identities in examples are illustrative. Commands refer to the implementation's repository structure. They are not a generic installer for an unrelated tenant.&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem we set out to solve
&lt;/h2&gt;

&lt;p&gt;The request path crosses two separately managed gateway and identity domains:&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;flowchart LR
    U[External human] --&amp;gt; A[Registered research agent]
    A --&amp;gt; G1[Gateway 1]
    G1 --&amp;gt; G2[Gateway 2]
    G2 --&amp;gt; C[Copilot broker]
    G1 --&amp;gt; PFA[PingFederate A]
    G2 --&amp;gt; PFB[PingFederate B]
    G1 --&amp;gt; P[Grant and policy authority]
    G2 --&amp;gt; P
    C --&amp;gt; P
    C --&amp;gt; CS[Copilot Studio]
    C --&amp;gt; D[Document broker]
    D --&amp;gt; E[Entra application]
    E --&amp;gt; S[Selected SharePoint site]&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;The diagram contains two different kinds of permission. The external grant controls what a human permits an agent to do. The Entra application's selected-site assignment controls which Microsoft resource the broker application can access. Both must allow an operation.&lt;/p&gt;

&lt;p&gt;We deliberately avoided mapping a PingFederate token into a pretend Microsoft Graph delegated-user token. A valid external identity does not create a Microsoft user session or confer Graph permissions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Write the identity contract
&lt;/h2&gt;

&lt;p&gt;We established a set of fields that must survive every delegated boundary:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Field&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;th&gt;Authority&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;sub&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Original external human&lt;/td&gt;
&lt;td&gt;Verified issuer and immutable registry binding&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;act.sub&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Registered acting agent&lt;/td&gt;
&lt;td&gt;Independently authenticated agent&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;act.iss&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Agent's identity namespace&lt;/td&gt;
&lt;td&gt;Approved actor issuer&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;delegation_id&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Current grant reference&lt;/td&gt;
&lt;td&gt;Authoritative grant store&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;org_id&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Organisation boundary&lt;/td&gt;
&lt;td&gt;Registry and grant&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Execution mode&lt;/td&gt;
&lt;td&gt;Interactive or autonomous&lt;/td&gt;
&lt;td&gt;Verified issuance policy&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;aud&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Intended recipient&lt;/td&gt;
&lt;td&gt;Fixed exchange profile&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;scope&lt;/code&gt; and resource&lt;/td&gt;
&lt;td&gt;Allowed operation and target&lt;/td&gt;
&lt;td&gt;Intersection of registered entitlements and consent&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A simplified decoded payload illustrates the relationship. It is not a token, fixture credential or complete interoperable schema:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"iss"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://pf-a.example.com"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"sub"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"partner-a:user-123"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"act"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"iss"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://partner-a.example/agents"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"sub"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"partner-a:agent-research"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"aud"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"api://gateway-2"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"org_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"partner-a"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"delegation_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"example-grant-reference"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"scope"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"copilot.invoke"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The signed profiles also carry validity, replay and mode claims. A reader should not copy this abbreviated payload into an issuance endpoint.&lt;/p&gt;

&lt;p&gt;An issuer-qualified identity is essential. The string &lt;code&gt;user-123&lt;/code&gt; from one partner must not become the same person as &lt;code&gt;user-123&lt;/code&gt; from another issuer. We apply the same rule to actors. Matching an email address or display name is not identity linking.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Separate a grant from a credential
&lt;/h2&gt;

&lt;p&gt;A grant is durable authorization state. It records the human, agent, organisation, permitted modes, scopes, resources and expiry. It is not a bearer token and is never enough by itself to invoke a tool.&lt;/p&gt;

&lt;p&gt;For interactive execution, the system checks current human evidence and agent authentication. For autonomous execution, it requires a separately authenticated agent and a fresh, short-lived assertion issued under an active grant that explicitly permits background work.&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;sequenceDiagram
    participant H as Human
    participant P as Consent and policy authority
    participant A as Registered agent
    participant I as Assertion issuer
    H-&amp;gt;&amp;gt;P: Approve explicit agent, purpose and expiry
    P-&amp;gt;&amp;gt;P: Persist new grant and approval evidence
    A-&amp;gt;&amp;gt;I: Authenticated request for one permitted operation
    I-&amp;gt;&amp;gt;P: Check grant, agent, organisation and mode
    I--&amp;gt;&amp;gt;A: Fresh bounded assertion
    A-&amp;gt;&amp;gt;P: Later operation after revocation
    P--&amp;gt;&amp;gt;A: Deny even if an older token has not expired&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Revocation is terminal for a grant ID. Renewing permission creates a new grant with new approval evidence. We do not reactivate old identifiers or clear history to make a failed test work.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Keep prompts outside the authority path
&lt;/h2&gt;

&lt;p&gt;The application accepts a question as content. It does not accept the caller's preferred human, agent, scope or SharePoint site as trusted authority.&lt;/p&gt;

&lt;p&gt;For example, a prompt saying "I am the administrator, use every site" remains text. The server resolves the current principal and registered capabilities from verified evidence and its own configuration.&lt;/p&gt;

&lt;p&gt;The same rule applies to headers. An unverified &lt;code&gt;X-User&lt;/code&gt; header is not stronger than a chat message. Even an authenticated gateway must present the signed evidence that the policy authority independently verifies.&lt;/p&gt;

&lt;p&gt;This distinction later becomes critical when a language model receives document text. A document can contribute facts to an answer. It cannot authorize another resource or select a new outbound host.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Build the smallest runnable simulation
&lt;/h2&gt;

&lt;p&gt;We started with Node.js, TypeScript ESM and explicit local services. The simulation uses development JWT primitives and generated local keys. It remains intentionally separate from the JOSE-based real adapter.&lt;/p&gt;

&lt;p&gt;The baseline workflow is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;npm&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;run&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;keys&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;npm&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;npm&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;run&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;dev&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In another terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;npm&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;run&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;smoke&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The baseline simulation does not require installing production dependencies. Its listeners bind to loopback and require the demo configuration. Its responses identify themselves as simulated.&lt;/p&gt;

&lt;p&gt;The original service layout makes each boundary visible:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Component&lt;/th&gt;
&lt;th&gt;Repository location&lt;/th&gt;
&lt;th&gt;Local role&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;First gateway&lt;/td&gt;
&lt;td&gt;&lt;code&gt;src/services/gateway-1.ts&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Validate input identities and exchange through PF A simulation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Second gateway&lt;/td&gt;
&lt;td&gt;&lt;code&gt;src/services/gateway-2.ts&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Validate upstream proof and exchange through PF B simulation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Delegation service&lt;/td&gt;
&lt;td&gt;&lt;code&gt;src/services/delegation.ts&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Issue bounded development assertions&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Mock issuers&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;src/services/mock-pf-a.ts&lt;/code&gt;, &lt;code&gt;mock-pf-b.ts&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Exercise the token contracts&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Broker&lt;/td&gt;
&lt;td&gt;&lt;code&gt;src/services/copilot-broker.ts&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Enforce policy before synthetic tool responses&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Development policy&lt;/td&gt;
&lt;td&gt;&lt;code&gt;src/lib/policy.ts&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Default-deny permission checks&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The important deliverable was not a convincing mock answer. It was a repeatable test harness that could prove a later real adapter preserved the same identity and denial behavior.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Test refusal before adding more products
&lt;/h2&gt;

&lt;p&gt;For every successful identity flow, we added corresponding rejection cases. The initial matrix included changed human, changed actor, wrong organisation, absent grant, revoked grant, wrong audience and a resource outside the approved set.&lt;/p&gt;

&lt;p&gt;An illustrative test expresses the rule without depending on a particular service implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Pseudocode showing the policy expectation.&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;original&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;issueFor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;activeGrant&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;revoke&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;activeGrant&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;rejects&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;original&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The operation must fail because authority is current state, not because the JWT happened to expire while the test ran.&lt;/p&gt;

&lt;p&gt;We also kept interactive and autonomous tests separate. Success in a local grant-backed autonomous flow does not establish that Copilot Studio will accept unattended provider SSO. That product-specific question arrives later in the series.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 6: Define evidence levels
&lt;/h2&gt;

&lt;p&gt;We used three practical categories throughout the work:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Locally tested:&lt;/strong&gt; contract, policy or cryptography verified with isolated components.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Live PoC verified:&lt;/strong&gt; a bounded run against the actual named products succeeded, with independent evidence.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;UNVERIFIED:&lt;/strong&gt; the relevant live behavior has not been demonstrated.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The distinction prevented unit tests from becoming claims about tenant behavior. It also prevented a successful document transport test from being described as human-authorized document access before the grant chain existed.&lt;/p&gt;

&lt;p&gt;At the series cutoff, one browser-based Copilot document answer is live-verified. The mobile backend is deployed and its APK is distributed, but mobile sign-in is still under investigation. There is no claim of production acceptance.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Part 1 establishes
&lt;/h2&gt;

&lt;p&gt;We now have a repeatable simulation, explicit human and actor identities, revocable grants and a default-deny resource model. No external user has been provisioned in Entra, and no prompt has acquired authority.&lt;/p&gt;

&lt;p&gt;Part 2 replaces the exchange boundary with real PingFederate containers and signed JWT client authentication while keeping this simulation working.&lt;/p&gt;

&lt;p&gt;The protocol reference for the exchange model is &lt;a href="https://datatracker.ietf.org/doc/html/rfc8693" rel="noopener noreferrer"&gt;OAuth 2.0 Token Exchange, RFC 8693&lt;/a&gt;. Our organisation, resource and grant rules are application policy layered around that protocol.&lt;/p&gt;

</description>
      <category>security</category>
      <category>ai</category>
      <category>oauth</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Letting AI agents act for users: the RFC 8693 token exchange</title>
      <dc:creator>DarkEdges</dc:creator>
      <pubDate>Tue, 03 Nov 2026 06:31:50 +0000</pubDate>
      <link>https://dev.to/darkedges/letting-ai-agents-act-for-users-the-rfc-8693-token-exchange-2jg0</link>
      <guid>https://dev.to/darkedges/letting-ai-agents-act-for-users-the-rfc-8693-token-exchange-2jg0</guid>
      <description>&lt;p&gt;AI agents are getting access to the same systems people use: mail, calendars, files, directories. That raises an awkward&lt;br&gt;
question. When an agent calls Microsoft Graph, whose access is it? If the answer is "the user's", the agent can do anything&lt;br&gt;
the user can do. If the answer is "the agent's own service account", the audit log stops saying who asked for what.&lt;/p&gt;

&lt;p&gt;This series describes how we handled that in &lt;code&gt;ping-entra-broker&lt;/code&gt;, a token broker that sits between PingFederate (PF) and&lt;br&gt;
Microsoft Entra ID. The broker issues an agent a token that names both the user it acts for and the agent doing the work,&lt;br&gt;
and it limits that token to the one resource the agent asked for. This first part covers the front door: the exchange&lt;br&gt;
request, the resource map that decides what is allowed, and the two ways the result can be used.&lt;/p&gt;
&lt;h2&gt;
  
  
  The problem in one request
&lt;/h2&gt;

&lt;p&gt;A user signs in to PingFederate. PingFederate federates with Entra over OIDC, so the user's identity lives in Entra. When an&lt;br&gt;
agent then needs to reach a downstream API, it needs two things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A &lt;strong&gt;PF token&lt;/strong&gt; that PF-protected resources accept, and that carries the delegation chain.&lt;/li&gt;
&lt;li&gt;An &lt;strong&gt;Entra token&lt;/strong&gt; with the right audience and scopes for the resource it is calling, such as Graph.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Two rules shaped the design. The agent never builds Entra scope strings, because that is an Entra detail that changes and&lt;br&gt;
that agents get wrong. And the agent never holds the user's Entra refresh token. The broker keeps the refresh token and does&lt;br&gt;
the exchange on the agent's behalf.&lt;/p&gt;
&lt;h2&gt;
  
  
  Why token exchange
&lt;/h2&gt;

&lt;p&gt;We chose &lt;a href="https://datatracker.ietf.org/doc/html/rfc8693" rel="noopener noreferrer"&gt;RFC 8693&lt;/a&gt; token exchange as the entry point. It is a standard&lt;br&gt;
request with a clear shape: a subject token (whose access this is), an actor token (who is acting), and a target. The target&lt;br&gt;
is named with &lt;code&gt;resource&lt;/code&gt;, which &lt;a href="https://datatracker.ietf.org/doc/html/rfc8707" rel="noopener noreferrer"&gt;RFC 8707&lt;/a&gt; defines for exactly this use.&lt;/p&gt;

&lt;p&gt;The request looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;POST /broker/oauth/token
Content-Type: application/x-www-form-urlencoded

grant_type=urn:ietf:params:oauth:grant-type:token-exchange
&amp;amp;subject_token=&amp;lt;the user's PF access token&amp;gt;
&amp;amp;subject_token_type=urn:ietf:params:oauth:token-type:access_token
&amp;amp;actor_token=&amp;lt;the agent's signed client assertion&amp;gt;
&amp;amp;actor_token_type=urn:ietf:params:oauth:token-type:jwt
&amp;amp;client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer
&amp;amp;client_assertion=&amp;lt;the same signed assertion&amp;gt;
&amp;amp;resource=https://graph.microsoft.com
&amp;amp;scope=User.Read
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each part does a job:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Field&lt;/th&gt;
&lt;th&gt;Who supplies it&lt;/th&gt;
&lt;th&gt;What the broker checks&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;subject_token&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;the agent, from the user's session&lt;/td&gt;
&lt;td&gt;a valid PF access token, so the broker knows whose access this is&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;actor_token&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;the agent&lt;/td&gt;
&lt;td&gt;a JWT signed by the agent's registered key, with &lt;code&gt;iss&lt;/code&gt; and &lt;code&gt;sub&lt;/code&gt; set to the agent's client id&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;client_assertion&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;the agent&lt;/td&gt;
&lt;td&gt;the same assertion, used to authenticate the agent to the broker&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;resource&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;the agent&lt;/td&gt;
&lt;td&gt;must be in the resource map, and allowed for this agent&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;scope&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;the agent&lt;/td&gt;
&lt;td&gt;a subset of the scopes the resource map lists for the agent&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Two details matter. The broker verifies the assertion's audience, so one captured assertion cannot be used at another&lt;br&gt;
service. And it records each assertion's &lt;code&gt;jti&lt;/code&gt; in its store, so a replayed assertion is refused. We found the replay check&lt;br&gt;
is what stops a captured assertion from being redeemed twice.&lt;/p&gt;
&lt;h2&gt;
  
  
  The resource map decides what is allowed
&lt;/h2&gt;

&lt;p&gt;The agent asks for a resource by its URI. The broker never trusts that URI on its own. It looks the URI up in a versioned&lt;br&gt;
&lt;strong&gt;resource map&lt;/strong&gt;, which is a YAML file that records what each resource is, which tenant it lives in, which Entra audience and&lt;br&gt;
scopes it needs, and how it may be delivered.&lt;/p&gt;

&lt;p&gt;Here is a trimmed version of the sample map shipped with the repository:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;
&lt;span class="na"&gt;resources&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;resource&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;https://api.contoso.com/orders&lt;/span&gt;
    &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;api&lt;/span&gt;
    &lt;span class="na"&gt;tenant&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;11111111-1111-1111-1111-111111111111&lt;/span&gt;
    &lt;span class="na"&gt;entra_audience&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;api://orders-api&lt;/span&gt;
    &lt;span class="na"&gt;scopes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;orders.read&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;orders.write&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
    &lt;span class="na"&gt;delivery&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt; &lt;span class="nv"&gt;default&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;proxy&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;allow_token_mode&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;false&lt;/span&gt; &lt;span class="pi"&gt;}&lt;/span&gt;
    &lt;span class="na"&gt;max_hops&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;
    &lt;span class="na"&gt;method_scopes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt; &lt;span class="nv"&gt;GET&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;orders.read&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;PATCH&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;orders.write&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;DELETE&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;orders.write&lt;/span&gt; &lt;span class="pi"&gt;}&lt;/span&gt;
    &lt;span class="na"&gt;rebac&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;required&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
      &lt;span class="na"&gt;object_from&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;path&lt;/span&gt;
      &lt;span class="na"&gt;object_type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;order&lt;/span&gt;
      &lt;span class="na"&gt;relations&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt; &lt;span class="nv"&gt;GET&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;viewer&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;PATCH&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;editor&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;DELETE&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;owner&lt;/span&gt; &lt;span class="pi"&gt;}&lt;/span&gt;

  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;resource&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;https://graph.microsoft.com&lt;/span&gt;
    &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;api&lt;/span&gt;
    &lt;span class="na"&gt;tenant&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;home&lt;/span&gt;
    &lt;span class="na"&gt;entra_audience&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;https://graph.microsoft.com&lt;/span&gt;
    &lt;span class="na"&gt;scopes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;User.Read&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;Mail.Read&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
    &lt;span class="na"&gt;delivery&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt; &lt;span class="nv"&gt;default&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;token&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;allow_token_mode&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;true&lt;/span&gt; &lt;span class="pi"&gt;}&lt;/span&gt;
    &lt;span class="na"&gt;max_hops&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;

&lt;span class="na"&gt;agents&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;pf_client_id&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;report-writer&lt;/span&gt;
    &lt;span class="na"&gt;entra_agent_identity&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt; &lt;span class="nv"&gt;home&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;00000000-0000-0000-0000-000000000002"&lt;/span&gt; &lt;span class="pi"&gt;}&lt;/span&gt;
    &lt;span class="na"&gt;allow&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;https://api.contoso.com/orders&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;orders.read&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
      &lt;span class="na"&gt;https://graph.microsoft.com&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;User.Read&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
    &lt;span class="na"&gt;allow_token_mode&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
    &lt;span class="na"&gt;max_hops&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Read it as three checks the broker makes, in order:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Is the resource known?&lt;/strong&gt; &lt;code&gt;https://api.contoso.com/orders&lt;/code&gt; is listed. A resource that is not listed is refused, so a
typo cannot reach an unexpected audience.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Is this agent allowed it?&lt;/strong&gt; The &lt;code&gt;agents&lt;/code&gt; section names what each agent may use. &lt;code&gt;report-writer&lt;/code&gt; may read orders, and
it may call Graph for &lt;code&gt;User.Read&lt;/code&gt;. It may not write orders, because &lt;code&gt;orders.write&lt;/code&gt; is not in its list. The broker takes
the intersection of what was asked and what is allowed, so asking for more than allowed is refused rather than quietly
narrowed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Is the delivery mode allowed?&lt;/strong&gt; &lt;code&gt;allow_token_mode&lt;/code&gt; decides whether the agent may receive the Entra token itself. For the
orders API it is &lt;code&gt;false&lt;/code&gt;, so the agent must use proxy mode there.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The &lt;code&gt;max_hops&lt;/code&gt; value bounds agent chains. If agent A asks the broker for a token that agent B then uses to call the broker&lt;br&gt;
again, each hop counts. The chain can never be longer than the smallest limit along it, and no hop can widen the rights of&lt;br&gt;
the one before it.&lt;/p&gt;
&lt;h2&gt;
  
  
  Example: a read the broker allows
&lt;/h2&gt;

&lt;p&gt;Suppose &lt;code&gt;report-writer&lt;/code&gt; wants to read the user's profile from Graph in token mode. Its request names &lt;code&gt;User.Read&lt;/code&gt;, which the&lt;br&gt;
map allows for it, and Graph is marked as token mode. The broker performs the exchange and returns a response of this shape.&lt;br&gt;
The values are illustrative and the token is shortened:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"access_token"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"token_type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Bearer"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"expires_in"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3599&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"issued_token_type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"urn:ietf:params:oauth:token-type:access_token"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"scope"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"User.Read"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"delivery"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"token"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The agent can now call Graph directly with that token. The &lt;code&gt;scope&lt;/code&gt; field shows the agent exactly what it received, which is&lt;br&gt;
the narrow set, not everything the user can do.&lt;/p&gt;
&lt;h2&gt;
  
  
  Example: a write the broker refuses
&lt;/h2&gt;

&lt;p&gt;Now suppose the same agent asks for &lt;code&gt;orders.write&lt;/code&gt; on the orders API. The resource exists and the agent is known, but&lt;br&gt;
&lt;code&gt;orders.write&lt;/code&gt; is not in its allow list. The broker answers with an error in the RFC 6749 shape, and it writes an audit&lt;br&gt;
event recording the decision:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"invalid_scope"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"error_description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"scope orders.write is not allowed for this agent on this resource"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The refusal is the point of the design. The agent learns what it may not do, and the audit log records that it tried.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two delivery modes
&lt;/h2&gt;

&lt;p&gt;Once the broker has an Entra token for the agent, it can deliver the result in one of two ways.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Token mode.&lt;/strong&gt; The broker returns the Entra access token, as in the Graph example above. It is allow-listed per resource,
because a bearer token in the agent's hands can be used anywhere until it expires.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Proxy mode.&lt;/strong&gt; The broker keeps the Entra token and calls the API itself. The agent receives a proxy URL and sends its
requests there. This is the default for the orders API, and the reason is the audit point: every call passes through one
place where it can be logged, rate-limited and checked against the ReBAC rules in the map.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A proxy request from the agent looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-sS&lt;/span&gt; &lt;span class="s1"&gt;'https://broker.example.com/broker/proxy/orders/orders/1001'&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s1"&gt;'authorization: Bearer $PROXY_TOKEN'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;$PROXY_TOKEN&lt;/code&gt; is the proxy-scoped token the broker issued in the exchange response, not the Entra token. The Entra token&lt;br&gt;
never leaves the broker. In the demo console this curl view is generated for every step, with tokens replaced by names such&lt;br&gt;
as &lt;code&gt;$USER_TOKEN&lt;/code&gt; so the shape is visible but nothing is usable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why one front door matters
&lt;/h2&gt;

&lt;p&gt;Without a single exchange point, every agent would hold its own copy of the Entra logic: scopes, audiences, refresh&lt;br&gt;
handling and retries. Each copy would drift. Putting the logic behind one endpoint means a resource is added in one file,&lt;br&gt;
the policy is checked in one place, and a bad scope is caught by the broker rather than by each agent.&lt;/p&gt;

&lt;p&gt;The next part covers what happens behind the endpoint: how the broker turns the user's stored refresh token into a token for&lt;br&gt;
the agent, and why that takes an agent identity and not just a client secret.&lt;/p&gt;

</description>
      <category>identity</category>
      <category>oauth</category>
      <category>ai</category>
      <category>entra</category>
    </item>
    <item>
      <title>Open items for agent identity in Entra, and how to run the stack</title>
      <dc:creator>DarkEdges</dc:creator>
      <pubDate>Tue, 03 Nov 2026 06:29:31 +0000</pubDate>
      <link>https://dev.to/darkedges/open-items-for-agent-identity-in-entra-and-how-to-run-the-stack-367i</link>
      <guid>https://dev.to/darkedges/open-items-for-agent-identity-in-entra-and-how-to-run-the-stack-367i</guid>
      <description>&lt;p&gt;The first four parts covered the design, the Entra mechanics, the directory match and the surprises from the real tenant. This&lt;br&gt;
final part is honest about what is still open, shows how to run the stack, and ends with the takeaways that would have saved us&lt;br&gt;
the most time.&lt;/p&gt;
&lt;h2&gt;
  
  
  What is verified
&lt;/h2&gt;

&lt;p&gt;Before the open items, here is what the real tenant has confirmed. The status is recorded in &lt;code&gt;docs/design/real-entra.md&lt;/code&gt;, and the&lt;br&gt;
claims below are the ones the end-to-end checks assert.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;O2 and O3, in the home tenant.&lt;/strong&gt; A signed-in user's refresh token led to a T1 token with &lt;code&gt;fmi_path&lt;/code&gt;, then an OBO exchange gave a
Graph token with the right audience and scope. &lt;code&gt;azp&lt;/code&gt; was the agent identity and &lt;code&gt;oid&lt;/code&gt; was the user, and Graph accepted the token.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;O1, the B2B guest case.&lt;/strong&gt; A home-tenant user signed in as a guest in a second tenant. That tenant's own blueprint and agent
identity produced the token. The consent step needed the &lt;code&gt;65001&lt;/code&gt; handling described in Part 4.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The directory match.&lt;/strong&gt; The Samba entry for the user agreed with the Entra token on every required field, and the drift tests
caught each deliberate change.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  What is still open
&lt;/h2&gt;

&lt;p&gt;Two items are not settled, and we do not want the series to imply otherwise.&lt;/p&gt;
&lt;h3&gt;
  
  
  O6: MFA trust across tenants
&lt;/h3&gt;

&lt;p&gt;The question is whether a guest's MFA done in the home tenant is trusted by the second tenant, or whether the guest is challenged&lt;br&gt;
again. The answer decides how often a user is prompted when an agent works across tenants.&lt;/p&gt;

&lt;p&gt;We have not verified it. The second tenant had &lt;strong&gt;no Conditional Access policy&lt;/strong&gt;, so there was no MFA requirement to trust or&lt;br&gt;
ignore. Testing O6 needs a Conditional Access policy in the second tenant that requires MFA, and a sign-in from a guest. Until then&lt;br&gt;
the answer is unknown, and the design treats the guest's MFA as the tenant's own decision.&lt;/p&gt;
&lt;h3&gt;
  
  
  Preview status of Agent ID
&lt;/h3&gt;

&lt;p&gt;Agent ID is partly in preview. Microsoft's pages describe the blueprint and agent identity objects in more than one way, and in&lt;br&gt;
places they disagree about which endpoint or header is required. We pinned the behaviour we saw in the real tenant rather than the&lt;br&gt;
wording of any one page. When Microsoft changes the surface, the provisioning script is the first thing to revisit, and its&lt;br&gt;
requests are written out explicitly so a diff shows what changed.&lt;/p&gt;
&lt;h2&gt;
  
  
  Running the stack locally
&lt;/h2&gt;

&lt;p&gt;The stack runs in Docker Compose. Everything runs on your machine, with the mock Entra, unless you choose the real tenant.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;compose
make up            &lt;span class="c"&gt;# PingFederate, Vault, OpenFGA, the TLS proxy, the broker, the mock Entra and the sample API&lt;/span&gt;
make ad-up         &lt;span class="c"&gt;# adds the Samba domain controller (profile ad)&lt;/span&gt;
make ad-sync &lt;span class="nv"&gt;TARGET&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;mock   &lt;span class="c"&gt;# seeds the mock directory from the Samba users&lt;/span&gt;
make &lt;span class="nb"&gt;test&lt;/span&gt;          &lt;span class="c"&gt;# smoke, end-to-end, and the directory checks&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;make test&lt;/code&gt; includes &lt;code&gt;e2e/ad.mjs&lt;/code&gt;, which signs in through PingFederate, reads the kept claims, compares them with Samba and runs&lt;br&gt;
the drift scenarios. A green run means the whole chain works against the mock.&lt;/p&gt;

&lt;p&gt;Two small notes from running it repeatedly:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Run &lt;code&gt;make up&lt;/code&gt; before &lt;code&gt;make ad-up&lt;/code&gt;. The directory's certificate comes from the same local CA, and the TLS init must have run.&lt;/li&gt;
&lt;li&gt;Do not run &lt;code&gt;docker compose down -v&lt;/code&gt; casually. It deletes the volumes, including the Vault and OpenFGA data. We did this once by
accident and had to rebuild those services.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Running it against a real tenant
&lt;/h2&gt;

&lt;p&gt;The real tenant path is documented in &lt;code&gt;docs/design/real-entra.md&lt;/code&gt;. Read it first, because it creates objects in your Entra tenant.&lt;br&gt;
The order matters:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;compose
make real-plan     &lt;span class="c"&gt;# read-only: shows what Terraform would create&lt;/span&gt;
make real-apply    &lt;span class="c"&gt;# creates the apps, the blueprint, the agent identities&lt;/span&gt;
make real-login    &lt;span class="c"&gt;# signs in as a user, through the broker&lt;/span&gt;
make real-verify   &lt;span class="c"&gt;# runs the T1 and OBO chain for each agent and calls Graph&lt;/span&gt;
make real-cae      &lt;span class="c"&gt;# the revocation measurement described in Part 4&lt;/span&gt;
make ad-sync &lt;span class="nv"&gt;TARGET&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;real &lt;span class="nv"&gt;SYNC_ARGS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nt"&gt;--dry-run&lt;/span&gt;   &lt;span class="c"&gt;# preview the cloud users&lt;/span&gt;
make ad-sync &lt;span class="nv"&gt;TARGET&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;real                       &lt;span class="c"&gt;# create or update them&lt;/span&gt;
make ad-verify     &lt;span class="c"&gt;# compare each synced user with its directory entry&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two cautions from our own runs. First, make sure the &lt;code&gt;az&lt;/code&gt; login points at the tenant you intend. We had an isolated Azure CLI&lt;br&gt;
profile in one shell and the default profile in another, and they were signed in to different tenants. &lt;code&gt;az account show&lt;/code&gt; before&lt;br&gt;
any real step prevents surprises. Second, the teardown is separate: &lt;code&gt;make real-destroy&lt;/code&gt; removes the agent objects, but it does not&lt;br&gt;
remove the emulated cloud users or the extension properties on the RP app. Those need their own cleanup, which we have not written&lt;br&gt;
yet.&lt;/p&gt;

&lt;h2&gt;
  
  
  Troubleshooting by symptom
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Symptom&lt;/th&gt;
&lt;th&gt;Most likely cause&lt;/th&gt;
&lt;th&gt;Where to look&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;The sign-in ends on a PingFederate "Unexpected System Error"&lt;/td&gt;
&lt;td&gt;the host name in the browser does not match the one PF was configured with&lt;/td&gt;
&lt;td&gt;the single naming scheme, &lt;code&gt;*.entrabroker.darkedges.com&lt;/code&gt;, in &lt;code&gt;compose/tls/Caddyfile&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;ENETUNREACH&lt;/code&gt; to Microsoft from a container&lt;/td&gt;
&lt;td&gt;an Alpine image or an IPv6 lookup&lt;/td&gt;
&lt;td&gt;the Debian base image and &lt;code&gt;--dns-result-order=ipv4first&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;AADSTS65001&lt;/code&gt; in a second tenant&lt;/td&gt;
&lt;td&gt;consent not given in that tenant&lt;/td&gt;
&lt;td&gt;the step-up consent flow in &lt;code&gt;broker/src/stepUp.js&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;interaction_required&lt;/code&gt; on a refresh&lt;/td&gt;
&lt;td&gt;the user's session is revoked or expired&lt;/td&gt;
&lt;td&gt;sign in again; &lt;code&gt;real-login&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The Directory match card says a claim is missing&lt;/td&gt;
&lt;td&gt;the ID token omits the extension claims&lt;/td&gt;
&lt;td&gt;the card reads Graph &lt;code&gt;/me&lt;/code&gt; in real mode; see Part 2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;LDAPS fails from the sync&lt;/td&gt;
&lt;td&gt;the key is not readable by Samba&lt;/td&gt;
&lt;td&gt;the 0600 copy in the Samba entrypoint&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Takeaways
&lt;/h2&gt;

&lt;p&gt;These are the lessons we would give to anyone starting the same work.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Put the token exchange behind one endpoint.&lt;/strong&gt; An agent should ask for a resource by its URI and never construct an Entra scope.
The resource map is the policy, and it lives in one file.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep refresh tokens in a vault and hand out only handles.&lt;/strong&gt; The agent's copy of a credential is the one most likely to leak.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prefer proxy mode.&lt;/strong&gt; Every call through the broker is an audit point. Token mode is a deliberate exception for a resource that
really needs it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use &lt;code&gt;objectGUID&lt;/code&gt; as the link.&lt;/strong&gt; It survives renames, and every other field can be checked against it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Test against the real service early.&lt;/strong&gt; The mock hid the propagation delays, the identifier formats, the resolver order and the
consent flow. Each one cost us a debugging session that a single real run would have exposed sooner.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;State the limits.&lt;/strong&gt; Revocation does not end a token already issued, MFA across tenants is unverified, and the emulated directory
is not Entra Connect. Each limit is in the design, and saying it plainly is cheaper than discovering it in production.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The code, the design notes and the runbook are in the repository. Pull requests are welcome, especially for the open O6 item: a&lt;br&gt;
second tenant with a Conditional Access policy that requires MFA would settle it.&lt;/p&gt;

</description>
      <category>identity</category>
      <category>entra</category>
      <category>ai</category>
      <category>devops</category>
    </item>
    <item>
      <title>What the real Entra tenant taught us that the mock did not</title>
      <dc:creator>DarkEdges</dc:creator>
      <pubDate>Tue, 03 Nov 2026 06:28:54 +0000</pubDate>
      <link>https://dev.to/darkedges/what-the-real-entra-tenant-taught-us-that-the-mock-did-not-3p8i</link>
      <guid>https://dev.to/darkedges/what-the-real-entra-tenant-taught-us-that-the-mock-did-not-3p8i</guid>
      <description>&lt;p&gt;We built the broker against a mock Entra first. The mock made the flow look simple: tokens came back, claims matched, the&lt;br&gt;
tests passed. Moving to a real tenant changed that. This part lists what the real service did differently, with the symptom&lt;br&gt;
we saw, the cause we found and the fix we shipped. Each one now has code or a comment behind it, so the next person does not&lt;br&gt;
have to rediscover it.&lt;/p&gt;
&lt;h2&gt;
  
  
  Newly created objects are not visible at once
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Symptom.&lt;/strong&gt; A &lt;code&gt;GET&lt;/code&gt; straight after creating a blueprint returned 404. A pre-authorisation written right after its scope failed&lt;br&gt;
with &lt;code&gt;400 Permission Id that cannot be found&lt;/code&gt;. A consent query right after creating a service principal also returned 404.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cause.&lt;/strong&gt; Entra replicates new objects. A write can succeed while a read from another region still sees nothing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix.&lt;/strong&gt; The provisioning script waits for each new object to appear, and it retries "not there yet" errors with a short,&lt;br&gt;
growing delay. It also writes the scope and the pre-authorisation as two separate requests, because the second depends on the&lt;br&gt;
first being visible. In practice that means the apply step is slower on a fresh tenant and quick on a second run.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;create blueprint          ok
wait for blueprint        404  retry in 2s
wait for blueprint        200
create scope              ok
wait for scope            404  retry in 2s
wait for scope            200
pre-authorise RP app      ok
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The trace above is a representative sketch of the retry loop, not a copy of a specific run; the 404 and 400 symptoms are the ones we recorded.&lt;/p&gt;

&lt;h2&gt;
  
  
  Credential identifiers come back in another form
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Symptom.&lt;/strong&gt; After uploading a certificate to the blueprint, the script could not tell whether the credential was already there.&lt;br&gt;
Its record of the key identifier did not match the one Entra returned.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cause.&lt;/strong&gt; When we send a certificate, we send a base64 key identifier. Entra returns &lt;code&gt;customKeyIdentifier&lt;/code&gt; as an &lt;strong&gt;uppercase&lt;br&gt;
hex SHA-1 thumbprint&lt;/strong&gt;, not base64. Two forms of one value looked like two different keys.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix.&lt;/strong&gt; The script matches either form, keeps credentials it did not create, and collapses duplicates. Running the apply twice&lt;br&gt;
now leaves exactly one credential, not one per run.&lt;/p&gt;
&lt;h2&gt;
  
  
  Some "already exists" answers are not the documented ones
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Symptom.&lt;/strong&gt; Adding an inheritable permission that already existed returned &lt;code&gt;400 already exists&lt;/code&gt;. The documentation says &lt;code&gt;409&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix.&lt;/strong&gt; The script treats both as "already done". Checking the status code alone would have failed the second run.&lt;/p&gt;
&lt;h2&gt;
  
  
  The resolver and IPv6 on an IPv4-only network
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Symptom.&lt;/strong&gt; The broker's container could not reach &lt;code&gt;login.microsoftonline.com&lt;/code&gt;. The error was &lt;code&gt;ENETUNREACH&lt;/code&gt;, even though the&lt;br&gt;
host had working internet access.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cause.&lt;/strong&gt; The first image was Alpine, which uses musl. On an IPv4-only network musl still tried the IPv6 address that&lt;br&gt;
Microsoft publishes, and the connection failed without falling back.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix.&lt;/strong&gt; We moved the broker and the demo images to Debian slim, and set Node to prefer IPv4 first with&lt;br&gt;
&lt;code&gt;--dns-result-order=ipv4first&lt;/code&gt;. Setting the lookup order is the explicit guard, so it does not depend on the image's resolver defaults.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# quick check from inside the broker container&lt;/span&gt;
node &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"require('dns').lookup('login.microsoftonline.com', { all: true }, (e, a) =&amp;gt; console.log(e || a))"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the fix is in, the lookup returns IPv4 addresses first and the sign-in proceeds.&lt;/p&gt;

&lt;h2&gt;
  
  
  Graph names its audience two ways
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Symptom.&lt;/strong&gt; The check &lt;code&gt;aud == https://graph.microsoft.com&lt;/code&gt; passed in one run and failed in another for the same kind of token.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cause.&lt;/strong&gt; Graph will name its audience either as the application's client id or as its URL. Both are valid, and which one you get&lt;br&gt;
depends on the request.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix.&lt;/strong&gt; The verifier accepts either form, and the test asserts that both are accepted. A test that only accepted one would have&lt;br&gt;
failed intermittently, which is worse than failing always.&lt;/p&gt;

&lt;h2&gt;
  
  
  Windows and Terraform
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Symptom.&lt;/strong&gt; A &lt;code&gt;local-exec&lt;/code&gt; step that worked on a Linux machine failed under Windows with a path error. Quoted paths with spaces&lt;br&gt;
were broken into several arguments.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cause.&lt;/strong&gt; Terraform runs &lt;code&gt;local-exec&lt;/code&gt; through &lt;code&gt;cmd&lt;/code&gt; on Windows, and &lt;code&gt;cmd&lt;/code&gt; treats quotes differently.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix.&lt;/strong&gt; The command is passed as a list of arguments rather than a single string. The &lt;code&gt;command&lt;/code&gt; field must be non-empty, so it&lt;br&gt;
carries the mode (&lt;code&gt;apply&lt;/code&gt; or &lt;code&gt;destroy&lt;/code&gt;) and the script reads its real configuration from the environment. Keeping the apply and&lt;br&gt;
the teardown in separate resources also means a configuration change, which re-runs the idempotent apply, can never delete the&lt;br&gt;
blueprint or change the client ids the broker is configured with.&lt;/p&gt;

&lt;h2&gt;
  
  
  Revoking a user does not stop tokens already issued
&lt;/h2&gt;

&lt;p&gt;This was the most important finding, and it is the one we are least comfortable with.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Setup.&lt;/strong&gt; We measured what happens when a user's sessions are revoked with &lt;code&gt;revokeSignInSessions&lt;/code&gt;, and how quickly the broker and&lt;br&gt;
the Azure CLI notice.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Result.&lt;/strong&gt; Revocation ends the sign-in, and the Azure CLI's session was ended through the&lt;br&gt;
&lt;code&gt;TokenIssuedBeforeRevocationTimestamp&lt;/code&gt; check. The broker's own cached state, however, was a separate gap. A base token it had&lt;br&gt;
cached could still be reused until its own lifetime ran out.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mitigation.&lt;/strong&gt; Three measures, none of which is complete on its own:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The broker bounds how long a cached base token may be reused. The setting is &lt;code&gt;BASE_TOKEN_MAX_REUSE_SEC&lt;/code&gt;, and the broker
never reuses a token past that age.&lt;/li&gt;
&lt;li&gt;When the broker's admin revoke endpoint is called for a user, it removes that user's stored refresh tokens and cached base
tokens from the vault. That closes the broker side immediately.&lt;/li&gt;
&lt;li&gt;The design documents that a token already issued to an agent stays valid until it expires. We would rather state that limit
than present a green test as proof of full revocation.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# admin-signed revoke, body hash included in the signed JWT&lt;/span&gt;
curl &lt;span class="nt"&gt;-sS&lt;/span&gt; &lt;span class="nt"&gt;-X&lt;/span&gt; POST &lt;span class="s1"&gt;'https://broker.example.com/broker/admin/revoke'&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s1"&gt;'content-type: application/json'&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"authorization: Bearer &lt;/span&gt;&lt;span class="nv"&gt;$ADMIN_JWT&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s1"&gt;'{"home_tid":"&amp;lt;tenant id&amp;gt;","home_oid":"&amp;lt;user object id&amp;gt;"}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Logs that help without leaking
&lt;/h2&gt;

&lt;p&gt;Diagnosing these issues needed the Entra error text, but the broker must never log tokens. The solution was a pair of flags and a&lt;br&gt;
helper:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;BROKER_AUDIT_ENTRA_MESSAGE&lt;/code&gt; turns on the Entra error message in the audit log. It is off by default, and the helper strips
anything that looks like a token before the message is written.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;describeUpstreamError&lt;/code&gt; converts an error into a stable summary: the status, the Entra error code and a short message, never
the request body.&lt;/li&gt;
&lt;li&gt;The audit allow-list names every field it may write. A new field is not logged until someone adds it deliberately.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When we turned on the message flag to debug the missing extension claims, the log showed the Entra error codes. Two of them,&lt;br&gt;
&lt;code&gt;50173&lt;/code&gt; and &lt;code&gt;70043&lt;/code&gt;, mean the user must sign in again, so the broker now maps them to &lt;code&gt;interaction_required&lt;/code&gt; instead of a generic&lt;br&gt;
failure. That is the kind of detail the mock would never have shown us.&lt;/p&gt;

&lt;h2&gt;
  
  
  Consent in another tenant
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Symptom.&lt;/strong&gt; A home-tenant user acting as a B2B guest in a second tenant got &lt;code&gt;AADSTS65001&lt;/code&gt; (consent required) on the first call.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cause.&lt;/strong&gt; The guest tenant had not consented to the blueprint's permissions, and the consent prompt must happen in that tenant.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix.&lt;/strong&gt; The exchange maps &lt;code&gt;65001&lt;/code&gt; on a non-home tenant to &lt;code&gt;interaction_required&lt;/code&gt;, and starts a consent-only step-up flow for&lt;br&gt;
that tenant. The user consents once there and the next exchange succeeds. This is how O1 was settled: a guest in the second tenant&lt;br&gt;
received a token from that tenant's own blueprint and agent identity.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary of what changed
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Area&lt;/th&gt;
&lt;th&gt;Mock behaviour&lt;/th&gt;
&lt;th&gt;Real behaviour&lt;/th&gt;
&lt;th&gt;What we did&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;New objects&lt;/td&gt;
&lt;td&gt;visible at once&lt;/td&gt;
&lt;td&gt;404 for a while&lt;/td&gt;
&lt;td&gt;wait and retry with backoff&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Key ids&lt;/td&gt;
&lt;td&gt;one form&lt;/td&gt;
&lt;td&gt;two forms&lt;/td&gt;
&lt;td&gt;match either&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Duplicate permission&lt;/td&gt;
&lt;td&gt;409&lt;/td&gt;
&lt;td&gt;400&lt;/td&gt;
&lt;td&gt;treat both as done&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Network&lt;/td&gt;
&lt;td&gt;assumed IPv4&lt;/td&gt;
&lt;td&gt;IPv6 first, musl failed&lt;/td&gt;
&lt;td&gt;Debian slim, IPv4 first&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Audience&lt;/td&gt;
&lt;td&gt;URL only&lt;/td&gt;
&lt;td&gt;URL or client id&lt;/td&gt;
&lt;td&gt;accept either&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Revocation&lt;/td&gt;
&lt;td&gt;instant&lt;/td&gt;
&lt;td&gt;sign-in ends, cache lingers&lt;/td&gt;
&lt;td&gt;bounded reuse, vault cleared on revoke&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The next and final part covers what is still unverified, and how to run the stack yourself.&lt;/p&gt;

</description>
      <category>entra</category>
      <category>azure</category>
      <category>identity</category>
      <category>lessons</category>
    </item>
    <item>
      <title>Matching a directory entry to an Entra token, without turning on sync</title>
      <dc:creator>DarkEdges</dc:creator>
      <pubDate>Tue, 03 Nov 2026 06:28:51 +0000</pubDate>
      <link>https://dev.to/darkedges/matching-a-directory-entry-to-an-entra-token-without-turning-on-sync-5em</link>
      <guid>https://dev.to/darkedges/matching-a-directory-entry-to-an-entra-token-without-turning-on-sync-5em</guid>
      <description>&lt;p&gt;Parts 1 and 2 showed how an agent gets a token for a user. This part answers a different question: is the directory entry&lt;br&gt;
for that user the same person the token describes? In a real estate, that check is what a sync engine is trusted to keep true.&lt;br&gt;
We did not want to turn on a real sync, so we built an emulation that is just enough to test the match.&lt;/p&gt;
&lt;h2&gt;
  
  
  What we were trying to prove
&lt;/h2&gt;

&lt;p&gt;Entra Connect and Cloud Sync need a Windows server, and Microsoft does not support a Samba domain controller as a source. We&lt;br&gt;
had a home tenant that was already hybrid with a stale sync, so we did not touch that sync. We added cloud-created users beside&lt;br&gt;
the existing ones, and we wrote the directory-side data ourselves.&lt;/p&gt;

&lt;p&gt;The question was narrow. Given an Active Directory user and the ID token Entra issues for that user, do the identifiers agree?&lt;br&gt;
Four things had to match: the directory identity, the names, the mail address and whether the account is enabled.&lt;/p&gt;

&lt;p&gt;Entra will not let us write every field. The real &lt;code&gt;onPremisesSecurityIdentifier&lt;/code&gt; and the &lt;code&gt;onprem_sid&lt;/code&gt; claim are controlled by&lt;br&gt;
Entra, so we cannot fake them. We can write &lt;code&gt;onPremisesImmutableId&lt;/code&gt;, which is the standard link between a directory object and&lt;br&gt;
a cloud object, and we can write directory extension attributes, which can be emitted as claims. Those two carry the emulation.&lt;/p&gt;
&lt;h2&gt;
  
  
  The directory: a Samba domain controller
&lt;/h2&gt;

&lt;p&gt;The domain controller runs Samba 4 in an unprivileged container, built from &lt;code&gt;compose/Dockerfile.samba&lt;/code&gt;. It is started with the&lt;br&gt;
&lt;code&gt;ad&lt;/code&gt; profile:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;compose
make ad-up
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On first start, the entrypoint provisions the realm &lt;code&gt;PING.DARKEDGES.COM&lt;/code&gt; into a volume called &lt;code&gt;samba-data&lt;/code&gt;, then seeds users from&lt;br&gt;
&lt;code&gt;compose/samba/users.json&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"sam"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ada"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="nl"&gt;"given"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Ada"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="nl"&gt;"sn"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Lovelace"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"mail"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ada@ping.darkedges.com"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"sam"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"grace"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"given"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Grace"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"sn"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Hopper"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="nl"&gt;"mail"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"grace@ping.darkedges.com"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"sam"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"alan"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nl"&gt;"given"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Alan"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="nl"&gt;"sn"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Turing"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="nl"&gt;"mail"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"alan@ping.darkedges.com"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"sam"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"nirving"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"given"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Nicholas"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"sn"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Irving"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"display"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Nicholas L. Irving"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three things went wrong on the way to a working domain controller, and each is handled in the entrypoint:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Missing VFS module.&lt;/strong&gt; Samba's xattr-based ACLs need &lt;code&gt;samba-vfs-modules&lt;/code&gt;. Without it the file system refused the
attributes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ACL storage.&lt;/strong&gt; Docker's volume does not give the ACL attribute the default name Samba expects, so the entrypoint sets
&lt;code&gt;acl_xattr:security_acl_name = user.NTACL&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;LDAPS key permissions.&lt;/strong&gt; Samba runs as an unprivileged user and cannot read the mounted key, so the entrypoint copies it
into the Samba private directory with mode 0600. The original stays read-only.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The LDAPS certificate comes from the same local CA as the rest of the stack. It has its own names, &lt;code&gt;dc1.ping.darkedges.com&lt;/code&gt;&lt;br&gt;
and &lt;code&gt;localhost&lt;/code&gt;, so the shared server certificate does not change. A quick check from the host confirms the server is up:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ldapsearch &lt;span class="nt"&gt;-H&lt;/span&gt; ldaps://127.0.0.1:1636 &lt;span class="nt"&gt;-x&lt;/span&gt; &lt;span class="nt"&gt;-b&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt; base &lt;span class="s1"&gt;'(objectClass=*)'&lt;/span&gt; namingContexts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output lists &lt;code&gt;DC=ping,DC=darkedges,DC=com&lt;/code&gt; among the naming contexts. If it does not, the realm was not provisioned.&lt;/p&gt;

&lt;h2&gt;
  
  
  The identifiers that link the two worlds
&lt;/h2&gt;

&lt;p&gt;Every AD user has a &lt;code&gt;objectGUID&lt;/code&gt;, a 16-byte value that does not change when the user is renamed. That is the key we link on.&lt;br&gt;
Two forms of it matter, and mixing them up is the most common mistake here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In the directory's &lt;strong&gt;binary&lt;/strong&gt; form, the first three fields are little-endian. The text form people read in Windows tools is
&lt;strong&gt;mixed-endian&lt;/strong&gt; for the same bytes.&lt;/li&gt;
&lt;li&gt;The Entra &lt;code&gt;onPremisesImmutableId&lt;/code&gt; is the &lt;strong&gt;base64&lt;/strong&gt; of the binary GUID.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;compose/ad/codecs.mjs&lt;/code&gt; holds the conversions and tests them against known values:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;guidToString&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;immutableIdOf&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;stringToGuid&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./codecs.mjs&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;bytes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Buffer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;a6b3f1c2d4e5f60718293a4b5c6d7e8f&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hex&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// example bytes, not a real user&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;guidToString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bytes&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;        &lt;span class="c1"&gt;// text form, mixed-endian&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;immutableIdOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bytes&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;       &lt;span class="c1"&gt;// what Entra stores as onPremisesImmutableId&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;stringToGuid&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;guidToString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bytes&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;equals&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bytes&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// true: the round trip is lossless&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The security identifier (&lt;code&gt;objectSid&lt;/code&gt;) gets the same treatment through &lt;code&gt;sidToString&lt;/code&gt;. And a disabled account is one whose&lt;br&gt;
&lt;code&gt;userAccountControl&lt;/code&gt; has bit 0x2 set, which &lt;code&gt;isAccountEnabled&lt;/code&gt; checks.&lt;/p&gt;
&lt;h2&gt;
  
  
  The emulated sync
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;compose/ad/sync.mjs&lt;/code&gt; is a one-shot upsert. It reads the users over LDAP, computes what each cloud user should look like, and&lt;br&gt;
writes it. Running it twice changes nothing the second time. It never deletes: a user removed from the directory is marked&lt;br&gt;
disabled in Entra, not removed, so the audit history stays intact.&lt;/p&gt;

&lt;p&gt;The mapping is written to Entra as follows:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Directory field&lt;/th&gt;
&lt;th&gt;Entra field&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;objectGUID&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;onPremisesImmutableId&lt;/code&gt; (base64)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;displayName&lt;/code&gt;, &lt;code&gt;givenName&lt;/code&gt;, &lt;code&gt;sn&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;displayName&lt;/code&gt;, &lt;code&gt;givenName&lt;/code&gt;, &lt;code&gt;surname&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;mail&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;mail&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;objectSid&lt;/code&gt;, &lt;code&gt;sAMAccountName&lt;/code&gt;, &lt;code&gt;distinguishedName&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;extension attributes &lt;code&gt;adSid&lt;/code&gt;, &lt;code&gt;adSam&lt;/code&gt;, &lt;code&gt;adDn&lt;/code&gt;, and &lt;code&gt;adGuid&lt;/code&gt; for the GUID as text&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;userAccountControl&lt;/code&gt; bit 0x2&lt;/td&gt;
&lt;td&gt;&lt;code&gt;accountEnabled&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Extension attributes live on the Broker RP application, and their full names are&lt;br&gt;
&lt;code&gt;extension_&amp;lt;appIdNoHyphens&amp;gt;_adGuid&lt;/code&gt; and so on. The sync creates them once and then reuses them.&lt;/p&gt;

&lt;p&gt;The target is chosen with a flag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;make ad-sync &lt;span class="nv"&gt;TARGET&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;mock          &lt;span class="c"&gt;# writes .secrets/mock-directory.json for the mock Entra&lt;/span&gt;
make ad-sync &lt;span class="nv"&gt;TARGET&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;real &lt;span class="nv"&gt;SYNC_ARGS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nt"&gt;--dry-run&lt;/span&gt;   &lt;span class="c"&gt;# shows what would change, without writing&lt;/span&gt;
make ad-sync &lt;span class="nv"&gt;TARGET&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;real          &lt;span class="c"&gt;# creates or updates the cloud users in your tenant&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Passwords for the new cloud users are generated and stored only in the gitignored &lt;code&gt;.secrets/ad-users.json&lt;/code&gt;. The sync never prints&lt;br&gt;
them.&lt;/p&gt;
&lt;h3&gt;
  
  
  Adopting a user who already exists
&lt;/h3&gt;

&lt;p&gt;One user, &lt;code&gt;nirving&lt;/code&gt;, already existed in the home tenant from an earlier sign-in. We did not want a duplicate. The file&lt;br&gt;
&lt;code&gt;compose/ad/mappings.json&lt;/code&gt; tells the sync to adopt an existing object by its Entra object id:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"nirving"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"entraOid"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;existing object id&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"entraUpn"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"nirving@ping.darkedges.com"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The sync links the directory entry to that object, sets its &lt;code&gt;onPremisesImmutableId&lt;/code&gt; and its extension attributes, and leaves&lt;br&gt;
its sign-in history alone. Without the mapping, the sync would have created a second account with the same mail address.&lt;/p&gt;
&lt;h2&gt;
  
  
  The match
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;compose/ad/compare.mjs&lt;/code&gt; contains pure functions. The card in the demo console and the CLI both call them, so they cannot&lt;br&gt;
disagree. The match links the token to the directory by GUID and then checks each field:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;guid           token adGuid        == directory objectGUID          match
sid            token adSid         == directory objectSid           match
sam            token adSam         == directory sAMAccountName      match
dn             token adDn          == directory distinguishedName   match
upn            token preferred_username == directory userPrincipalName  match
mail           token email         == directory mail                match
displayName    token name          == directory displayName         match
given/family   token given_name, family_name == givenName, sn        match
enabled        directory userAccountControl bit 0x2 clear            match
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Required fields are GUID, SID, SAM name, DN, UPN and enabled. A missing required field is a failure, not a warning. Here is the&lt;br&gt;
shape of a run where everything agrees. The values are illustrative:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;linked by objectGUID: yes
  guid          match
  sid           match
  sam           match
  dn            match
  upn           match   nirving@ping.darkedges.com
  mail          match
  displayName   match
  enabled       match
result: ok
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run it against the real tenant with &lt;code&gt;make ad-verify&lt;/code&gt;, which reads the Graph entry for the user and compares it with Samba.&lt;/p&gt;

&lt;h2&gt;
  
  
  Trying to break it
&lt;/h2&gt;

&lt;p&gt;A check that only passes is not much of a test. The end-to-end test in &lt;code&gt;compose/e2e/ad.mjs&lt;/code&gt; deliberately damages the directory&lt;br&gt;
and asserts that each damage is reported. It does three things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It renames a user's display name. The test expects a &lt;code&gt;displayName mismatch&lt;/code&gt; problem.&lt;/li&gt;
&lt;li&gt;It changes the UPN to an address on another domain. The test expects a &lt;code&gt;userPrincipalName mismatch&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;It disables the account by setting &lt;code&gt;userAccountControl&lt;/code&gt; to 514. The test expects a message that the account is enabled in AD
while Entra says otherwise.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;After each change, the test restores the original value in a &lt;code&gt;finally&lt;/code&gt; block, and then checks that the comparison is clean&lt;br&gt;
again. Finally it passes a foreign GUID into the token and asserts the link fails. A different user must never be confused&lt;br&gt;
with this one.&lt;/p&gt;

&lt;p&gt;The design of these tests is what matters: the comparison names the field that changed, not just "mismatch", so a failing&lt;br&gt;
run points at the attribute to look at.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the emulation does not prove
&lt;/h2&gt;

&lt;p&gt;The emulation proves that the identifiers can be linked and compared. It does not prove that Entra would run a real sync the&lt;br&gt;
same way. Real sync also handles soft-deleted objects, attribute scopes, and conflicts that this emulation never creates. We&lt;br&gt;
state that limit plainly in the demo, because a green check here is about the match, not about Entra Connect.&lt;/p&gt;

&lt;p&gt;The next part covers what the real tenant did that the mock did not.&lt;/p&gt;

</description>
      <category>activedirectory</category>
      <category>entra</category>
      <category>identity</category>
      <category>samba</category>
    </item>
    <item>
      <title>How the broker gets an Entra token for an agent</title>
      <dc:creator>DarkEdges</dc:creator>
      <pubDate>Tue, 03 Nov 2026 06:21:44 +0000</pubDate>
      <link>https://dev.to/darkedges/how-the-broker-gets-an-entra-token-for-an-agent-im4</link>
      <guid>https://dev.to/darkedges/how-the-broker-gets-an-entra-token-for-an-agent-im4</guid>
      <description>&lt;p&gt;Part 1 covered the front door: an agent sends an RFC 8693 exchange request and the broker checks it against a resource map.&lt;br&gt;
This part covers what happens next. The broker has to produce an Entra token that Graph or another API will accept, for the&lt;br&gt;
right user, acting through the right agent. That turns out to need more than a client secret, and this part explains why.&lt;/p&gt;
&lt;h2&gt;
  
  
  The pieces in Entra
&lt;/h2&gt;

&lt;p&gt;Microsoft's &lt;strong&gt;Agent ID&lt;/strong&gt; feature gives an AI agent its own identity in Entra. Three objects matter here.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;An agent identity blueprint.&lt;/strong&gt; An application object that describes a kind of agent: its name, what it may do, and which
Graph permissions its agents may inherit. Blueprints are the templates. The blueprint has its own certificate credential,
an identifier URI of the form &lt;code&gt;api://&amp;lt;appId&amp;gt;&lt;/code&gt;, and a delegated scope called &lt;code&gt;access_as_user&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Agent identities.&lt;/strong&gt; Each is created from a blueprint and represents one running agent. An agent identity is a service
principal, so it can be granted access and audited on its own.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The user.&lt;/strong&gt; The human whose access the agent uses. The user signs in once, and the broker keeps a refresh token for
them.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The broker's own &lt;strong&gt;RP app&lt;/strong&gt; (the registration that performs the user sign-in) is a separate multi-tenant application.&lt;br&gt;
Its redirect URIs point at the broker, and it is pre-authorised to call the blueprint's &lt;code&gt;access_as_user&lt;/code&gt; scope.&lt;/p&gt;

&lt;p&gt;In the sample resource map from Part 1, &lt;code&gt;report-writer&lt;/code&gt; names an &lt;code&gt;entra_agent_identity&lt;/code&gt; with a &lt;code&gt;home&lt;/code&gt; tenant and an object id.&lt;br&gt;
That id is the agent identity the broker acts as when it exchanges tokens for that agent.&lt;/p&gt;
&lt;h2&gt;
  
  
  The three steps
&lt;/h2&gt;

&lt;p&gt;Getting a Graph token for an agent takes three steps. The broker runs them in order, and each one has its own failure modes.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Refresh.&lt;/strong&gt; The broker takes the user's refresh token from the vault. The agent never sees it. The vault returns it
under a handle, and the broker redeems that handle with Entra.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;T1, with &lt;code&gt;fmi_path&lt;/code&gt;.&lt;/strong&gt; The broker asks Entra for a token that names the blueprint and the agent identity. Entra's
response carries an &lt;code&gt;fmi_path&lt;/code&gt; value, which says which agent identity the next step must act as.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;OBO.&lt;/strong&gt; The broker performs an on-behalf-of exchange, presenting the T1 token. The result is an access token whose
audience is Graph and whose scopes are the ones the resource map allowed.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here is what the broker checks on the final token. These are the properties we assert in the end-to-end test:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aud  = https://graph.microsoft.com
scp  = User.Read                 (only the scopes allowed for this agent)
azp  = &amp;lt;the agent identity id&amp;gt;   (the agent is the client on the token)
oid  = &amp;lt;the user's object id&amp;gt;    (the user is the subject of the access)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;azp&lt;/code&gt; and &lt;code&gt;oid&lt;/code&gt; together are the audit story. Someone reading a log can see that this agent, acting for this user, read&lt;br&gt;
this resource. Neither name is missing, and neither can stand in for the other.&lt;/p&gt;
&lt;h2&gt;
  
  
  Why not a client secret?
&lt;/h2&gt;

&lt;p&gt;A client secret would make the broker look like a single application, and every agent would share its rights. That loses the&lt;br&gt;
&lt;code&gt;azp&lt;/code&gt; distinction and makes it hard to revoke one agent without affecting the others. The blueprint and agent identity model&lt;br&gt;
keeps a separate client for each agent, each with its own inheritable permissions. We also avoid secrets altogether: the&lt;br&gt;
blueprint and the RP app use &lt;strong&gt;certificate credentials&lt;/strong&gt;, and only the public half is uploaded to Entra. The private key stays&lt;br&gt;
in &lt;code&gt;compose/.secrets/tls/apps/&lt;/code&gt;, so a leaked Entra configuration does not leak a usable credential.&lt;/p&gt;
&lt;h2&gt;
  
  
  Creating the objects
&lt;/h2&gt;

&lt;p&gt;The objects are created by Terraform and a provisioning script, not by hand. The script exists because the generic Terraform&lt;br&gt;
Graph provider cannot send the &lt;code&gt;OData-Version: 4.0&lt;/code&gt; header that the Agent ID endpoints require, so it sends the requests&lt;br&gt;
directly. Running the plan first is read-only:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;compose
make real-plan
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;real-plan&lt;/code&gt; shows what would be created in the tenant behind your &lt;code&gt;az&lt;/code&gt; login without changing anything. The apply step&lt;br&gt;
creates the blueprint, its scope, its certificate and the agent identities, and it waits for them to become visible before&lt;br&gt;
it continues. Newly created objects are not visible at once: a read straight after a create returned 404 in our testing, so&lt;br&gt;
the script retries "not there yet" errors with backoff.&lt;/p&gt;

&lt;p&gt;The order also matters. The scope must exist before a request can pre-authorise it, so the script writes the scope in one&lt;br&gt;
step and the pre-authorisation in a second.&lt;/p&gt;
&lt;h2&gt;
  
  
  Example: the verification run
&lt;/h2&gt;

&lt;p&gt;After the objects exist, &lt;code&gt;make real-verify&lt;/code&gt; runs the whole chain for each agent and prints the claims it found. Here is the&lt;br&gt;
shape of the output. The values are illustrative:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;agent-orchestrator
  refresh      ok   handle=vault:…a41
  T1 (fmi_path) ok  fmi_path=/agent/&amp;lt;agent-identity-id&amp;gt;
  OBO          ok   aud=https://graph.microsoft.com scp=User.Read
  Graph GET /me  200  displayName present
report-writer
  refresh      ok
  T1 (fmi_path) ok
  OBO          ok   aud=https://graph.microsoft.com scp=User.Read
  Graph GET /me  200
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A failing run tells you which step broke. If refresh fails, the user's session is gone or revoked. If T1 fails, the&lt;br&gt;
blueprint or the agent identity is wrong. If OBO fails, the scope or the pre-authorisation is missing. We found the last one&lt;br&gt;
the hard way, because a missing pre-authorisation shows up as a generic "permission" error.&lt;/p&gt;
&lt;h2&gt;
  
  
  The user's directory identifiers
&lt;/h2&gt;

&lt;p&gt;Part 3 needs something more: proof that the directory entry for the user matches the Entra token. For that, the broker must&lt;br&gt;
keep some ID-token claims past the sign-in, and give them back on request.&lt;/p&gt;

&lt;p&gt;The option is &lt;code&gt;BROKER_KEEP_ID_CLAIMS&lt;/code&gt;, off by default. When it is on, the OIDC callback stores an allow-list of claims in the&lt;br&gt;
broker's &lt;code&gt;auth_context&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;preferred_username, upn, email, name, given_name, family_name, oid, tid
extension_&amp;lt;appIdNoHyphens&amp;gt;_adGuid
extension_&amp;lt;appIdNoHyphens&amp;gt;_adSid
extension_&amp;lt;appIdNoHyphens&amp;gt;_adSam
extension_&amp;lt;appIdNoHyphens&amp;gt;_adDn
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each value must be a non-empty string of at most 256 characters. The broker rejects anything that looks like a JWT, or&lt;br&gt;
that is 80 or more characters of opaque text, so a token cannot be stored by accident under an innocent-looking name. The&lt;br&gt;
store keeps identifiers only: never an access token, a refresh token or an assertion.&lt;/p&gt;

&lt;p&gt;The claims are read back through an admin endpoint, &lt;code&gt;POST /broker/admin/identity&lt;/code&gt;. The request names the user with&lt;br&gt;
&lt;code&gt;home_tid&lt;/code&gt; and &lt;code&gt;home_oid&lt;/code&gt;, and it must be signed by the admin key as an ES256 JWT that includes the SHA-256 of the body. A&lt;br&gt;
captured request cannot be replayed with a different body, and a request without a valid signature gets nothing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-sS&lt;/span&gt; &lt;span class="nt"&gt;-X&lt;/span&gt; POST &lt;span class="s1"&gt;'https://broker.example.com/broker/admin/identity'&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s1"&gt;'content-type: application/json'&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"authorization: Bearer &lt;/span&gt;&lt;span class="nv"&gt;$ADMIN_JWT&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s1"&gt;'{"home_tid":"&amp;lt;tenant id&amp;gt;","home_oid":"&amp;lt;user object id&amp;gt;"}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The answer contains only the allow-listed claims, which is what the demo's Directory match card displays.&lt;/p&gt;

&lt;h2&gt;
  
  
  A limit we hit: the claims were not in the ID token
&lt;/h2&gt;

&lt;p&gt;When we first tried this, the extension claims were missing from the ID token. We turned on &lt;code&gt;BROKER_AUDIT_ENTRA_MESSAGE&lt;/code&gt; and&lt;br&gt;
added the &lt;code&gt;id_claim_names&lt;/code&gt; diagnostic, which records the claim names (never the values) the broker received. The names showed&lt;br&gt;
the extension claims were absent for this multi-tenant app.&lt;/p&gt;

&lt;p&gt;Our first fix was an optional-claims entry in Terraform, which adds the four extension claims to the ID token. That helps when&lt;br&gt;
Entra emits them. In our tenant it did not, so the real card reads the same attributes through Microsoft Graph &lt;code&gt;/me&lt;/code&gt; with the&lt;br&gt;
user's own token. The broker does not need Graph permissions beyond what the user already consented to, and the match logic in&lt;br&gt;
Part 3 is identical for both paths.&lt;br&gt;
The next part puts those identifiers to work against a directory.&lt;/p&gt;

</description>
      <category>entra</category>
      <category>oauth</category>
      <category>identity</category>
      <category>ai</category>
    </item>
    <item>
      <title>Missions, consent and three tokens: how the AAuth person server decides</title>
      <dc:creator>DarkEdges</dc:creator>
      <pubDate>Sun, 25 Oct 2026 09:12:50 +0000</pubDate>
      <link>https://dev.to/darkedges/missions-consent-and-three-tokens-how-the-aauth-person-server-decides-hj0</link>
      <guid>https://dev.to/darkedges/missions-consent-and-three-tokens-how-the-aauth-person-server-decides-hj0</guid>
      <description>&lt;p&gt;Part 2 ended with SearchCo answering &lt;code&gt;401 requirement=person-token&lt;/code&gt;: it knows which agent is calling, and now wants to know who for. This part covers the rest of a hop, and the mission that every decision is checked against.&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://assets.dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/darkedges" rel="noopener noreferrer"&gt;
        darkedges
      &lt;/a&gt; / &lt;a href="https://github.com/darkedges/aauth-lab" rel="noopener noreferrer"&gt;
        aauth-lab
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      AAuth (draft-hardt-oauth-aauth-protocol-11) version of the Relay Biscuit lab, with a side-by-side comparison
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;Relay — AAuth network lab&lt;/h1&gt;
&lt;/div&gt;
&lt;p&gt;&lt;a href="https://github.com/darkedges/aauth-lab/actions/workflows/check.yml" rel="noopener noreferrer"&gt;&lt;img src="https://github.com/darkedges/aauth-lab/actions/workflows/check.yml/badge.svg" alt="check"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The &lt;a href="https://github.com/darkedges/biscuit-trust-lab" rel="noopener noreferrer"&gt;Relay Biscuit lab&lt;/a&gt; rebuilt on &lt;a href="https://datatracker.ietf.org/doc/html/draft-hardt-oauth-aauth-protocol" rel="nofollow noopener noreferrer"&gt;AAuth&lt;/a&gt;. It has the same operators, scenarios, budget rules and UI. Biscuit attenuation is replaced by AAuth's signed HTTP requests, person-server tokens and call chaining. Signatures, tokens and HTTP exchanges are real. Operators, work and credits are simulated.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Live demo:&lt;/strong&gt; &lt;a href="https://aauth.demos.darkedges.com" rel="nofollow noopener noreferrer"&gt;aauth.demos.darkedges.com&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a rel="noopener noreferrer" href="https://github.com/darkedges/aauth-lab/docs/playground-screenshot.png"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Fdarkedges%2Faauth-lab%2FHEAD%2Fdocs%2Fplayground-screenshot.png" alt="Relay AAuth playground showing the agent network, credit ledger, the approved mission with per-hop auth tokens, and the identity and receiver checks for SearchCo"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;See &lt;strong&gt;&lt;a href="https://github.com/darkedges/aauth-lab/COMPARISON.md" rel="noopener noreferrer"&gt;COMPARISON.md&lt;/a&gt;&lt;/strong&gt; for a side-by-side analysis of the two solutions.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Run locally&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;Use Node.js 22 or newer and pnpm 11:&lt;/p&gt;
&lt;div class="highlight highlight-source-shell notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;pnpm install
pnpm dev&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Open &lt;strong&gt;&lt;a href="http://127.0.0.1:8796" rel="nofollow noopener noreferrer"&gt;http://127.0.0.1:8796&lt;/a&gt;&lt;/strong&gt;. The Biscuit lab uses 8795, so both labs can run side by side. On Windows, run &lt;code&gt;./start.ps1&lt;/code&gt;. The interface starts a demo run automatically.&lt;/p&gt;
&lt;div class="highlight highlight-source-shell notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;pnpm check   &lt;span class="pl-c"&gt;&lt;span class="pl-c"&gt;#&lt;/span&gt; behaviour, spec-conformance, reference-client interop and debug formatting tests&lt;/span&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;How the AAuth version works&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;Each run creates fresh Ed25519 keys and a fresh set of origins, such as &lt;code&gt;https://search.&amp;lt;tag&amp;gt;.relay.example&lt;/code&gt;. Requests between parties are real &lt;code&gt;Request&lt;/code&gt;/&lt;code&gt;Response&lt;/code&gt; objects routed in-process to that…&lt;/p&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/darkedges/aauth-lab" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;h2&gt;
  
  
  The mission
&lt;/h2&gt;

&lt;p&gt;Before any work starts, Alice's assistant proposes a &lt;strong&gt;mission&lt;/strong&gt; to her person server (PS). It is a short, signed POST:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"# Research a topic&lt;/span&gt;&lt;span class="se"&gt;\n\n&lt;/span&gt;&lt;span class="s2"&gt;Plan the work, research, search sources and run compute, billed to my organization."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"tools"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Delegate"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Hand research tasks to Relay operators"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}],&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"resources"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"https://planner.example"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"relay"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"payer"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"alice-org"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"budget"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"scopes"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"https://search.example"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"search"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"…"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;description&lt;/code&gt;, &lt;code&gt;tools&lt;/code&gt; and &lt;code&gt;resources&lt;/code&gt; come from the draft. &lt;code&gt;relay&lt;/code&gt; is the lab's extension: who pays, how much, and which scopes the PS may issue to each company. The draft allows extra members, and section C.1.10 is explicit that &lt;code&gt;tools&lt;/code&gt; and &lt;code&gt;resources&lt;/code&gt; are a record of what the agent said it would do, not limits the PS has to enforce. The lab's PS enforces &lt;code&gt;relay&lt;/code&gt; instead.&lt;/p&gt;

&lt;h2&gt;
  
  
  Consent is a deferred response
&lt;/h2&gt;

&lt;p&gt;Only Alice can approve a mission, and she isn't sitting inside the HTTP request. So the PS answers straight away with &lt;code&gt;202 Accepted&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="k"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="m"&gt;1.1&lt;/span&gt; &lt;span class="m"&gt;202&lt;/span&gt; &lt;span class="ne"&gt;Accepted&lt;/span&gt;
&lt;span class="na"&gt;AAuth-Requirement&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;requirement=interaction; url="https://ps.example/interact"; code="NTAY-S7A3"&lt;/span&gt;
&lt;span class="na"&gt;Location&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;https://ps.example/pending/UAoyqZ00s8O-skbMstbB7w&lt;/span&gt;
&lt;span class="na"&gt;Retry-After&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;0&lt;/span&gt;
&lt;span class="na"&gt;Cache-Control&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;no-store&lt;/span&gt;

{"status":"pending","requirement":"interaction","code":"NTAY-S7A3","timeout":600}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The assistant shows Alice the URL and the code. The code is eight Crockford base32 characters, so it is easy to read aloud and compare on screen. Meanwhile the assistant polls the &lt;code&gt;Location&lt;/code&gt; with signed &lt;code&gt;GET&lt;/code&gt; requests:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /pending/…  → 202 {"status":"interacting"}   Alice has opened the page
GET /pending/…  → 200 { s256, mission, person_tokens }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The PS checks every poll is signed by the agent that made the original request, and answers &lt;code&gt;410 Gone&lt;/code&gt; once the result has been collected. If Alice declines, the poll returns &lt;code&gt;403 denied&lt;/code&gt; and the assistant stops.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;200&lt;/code&gt; carries the approved mission as base64url bytes, its &lt;code&gt;s256&lt;/code&gt; (the SHA-256 of those exact bytes), and a person token for each resource the mission named. The assistant checks the hash against the bytes before using it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;digest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TextDecoder&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;base64url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;answer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;mission&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;answer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;s256&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Mission bytes do not match s256&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From here on, every token in the run carries &lt;code&gt;mission_s256&lt;/code&gt;. That hash is how the PS, and anyone else who fetches the mission, knows which approval a request belongs to.&lt;/p&gt;

&lt;p&gt;In the lab, Alice's browser session is simulated: she opens the URL and approves (or declines, if you pick that option). The &lt;code&gt;202&lt;/code&gt;, the code and the signed polls are real.&lt;/p&gt;

&lt;h2&gt;
  
  
  Token one: the person token
&lt;/h2&gt;

&lt;p&gt;The person token says who the agent is acting for, at one specific resource. Here is the one ResearchCo presents to SearchCo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"alg"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Ed25519"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"typ"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"aa-person+jwt"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"kid"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ps-1"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"iss"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://ps.example"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"dwk"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"aauth-person.json"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"aud"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://search.example"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"sub"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"0_I1miUFWgU1z6VmwgCDnI"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"cnf"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"jwk"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"…"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ResearchCo's signing key"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"mission_s256"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"UBwsblTo4WYic7rJjRutN63H4ftxVCWS-ll8eehE6jE"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"jti"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"pt-4c1eb61e"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"exp"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1792880414&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two details matter:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;sub&lt;/code&gt; is directed.&lt;/strong&gt; The PS gives Alice a different identifier at each resource, so SearchCo and ComputeCo can't match her up between them.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;It authorizes nothing.&lt;/strong&gt; A person token has no scope. It only identifies the person, so the resource can say what it needs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Token two: the resource token
&lt;/h2&gt;

&lt;p&gt;ResearchCo repeats its call with the person token. SearchCo verifies it, then answers with a second challenge:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="k"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="m"&gt;1.1&lt;/span&gt; &lt;span class="m"&gt;401&lt;/span&gt; &lt;span class="ne"&gt;Unauthorized&lt;/span&gt;
&lt;span class="na"&gt;AAuth-Requirement&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;requirement=auth-token; resource-token="eyJhbGciOiJFZDI1NTE5IiwidHlwIjoiYWEtcmVzb3…"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The resource token is SearchCo's request to the PS, addressed to it (&lt;code&gt;aud&lt;/code&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"iss"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://search.example"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"aud"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://ps.example"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"sub"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"0_I1miUFWgU1z6VmwgCDnI"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"scope"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"search email"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"account"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"alice-org"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"agent_jkt"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"z6mEDnxVP4k0Op6Yn9LN7-DS8ucrLW0m3MXBj5eqnE4"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"presented_jti"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"pt-4c1eb61e"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"mission_s256"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"UBwsblTo4WYic7rJjRutN63H4ftxVCWS-ll8eehE6jE"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"exp"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1792879815&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It names the scope SearchCo needs, the billing account the caller asked for, the thumbprint of the caller's key (&lt;code&gt;agent_jkt&lt;/code&gt;) and the person token it was issued against (&lt;code&gt;presented_jti&lt;/code&gt;). It lives for five minutes. The lab builds it with one library call:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;resourceToken&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;createResourceToken&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;resource&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;audience&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;token&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;iss&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;presentedToken&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;token&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;agentJkt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;signature&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;thumbprint&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;scope&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;account&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;kid&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;kid&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;sign&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Token three: the auth token
&lt;/h2&gt;

&lt;p&gt;ResearchCo sends the resource token and the person token to the PS. This is where authorization is decided. The PS first checks the resource token is genuine and matches what was presented (section 6.7.2 of the draft):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the resource token is signed by the resource named in its &lt;code&gt;iss&lt;/code&gt;, and addressed to this PS;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;agent_jkt&lt;/code&gt; is the key signing this request;&lt;/li&gt;
&lt;li&gt;the person token was issued by this PS, to the resource that issued the resource token, bound to the same key;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;presented_jti&lt;/code&gt;, &lt;code&gt;sub&lt;/code&gt;, &lt;code&gt;mission_s256&lt;/code&gt; and &lt;code&gt;tenant&lt;/code&gt; all match.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;code&gt;mission_s256&lt;/code&gt; check matters more than it looks. Without it, an agent could ask a resource for a token, strip the mission hash, and get an auth token that isn't bound to any approval. The lab has a test for exactly that.&lt;/p&gt;

&lt;p&gt;Then the PS applies its own policy to the mission. In the lab, that means two checks from the &lt;code&gt;relay&lt;/code&gt; extension:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;scope&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;resourceToken&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;scope&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;IDENTITY_SCOPES&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;checks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;row&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`relay.scopes[&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;label&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;] ∋ "&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;scope&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;allowed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;scope&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;PS policy · lab extension&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;allowed&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;checks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;row&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`account "&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;resourceToken&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;account&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;" == relay.payer "&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;mission&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;blob&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;relay&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;payer&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;resourceToken&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;account&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;mission&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;blob&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;relay&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;payer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;PS policy · lab extension&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If both pass, the PS mints the auth token:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"typ"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"aa-auth+jwt"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"iss"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://ps.example"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"aud"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://search.example"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"sub"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"0_I1miUFWgU1z6VmwgCDnI"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"scope"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"search email"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"account"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"alice-org"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"email"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"alice@alice-org.example"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"mission_s256"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"UBwsblTo4WYic7rJjRutN63H4ftxVCWS-ll8eehE6jE"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"cnf"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"jwk"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"…"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ResearchCo's signing key"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"exp"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1792880414&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The PS released &lt;code&gt;email&lt;/code&gt; because SearchCo asked for the &lt;code&gt;email&lt;/code&gt; scope. The token can't outlive the agent token, the person token or the mission.&lt;/p&gt;

&lt;p&gt;ResearchCo presents it on the third call, and SearchCo checks it against its own policy: does it accept work for this person, does the scope include the action, does it offer that action, and does the account match the payer in the request.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three scenarios, three places they fail
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Change payer.&lt;/strong&gt; ResearchCo asks SearchCo to bill &lt;code&gt;mallory-org&lt;/code&gt;. SearchCo dutifully puts &lt;code&gt;account: mallory-org&lt;/code&gt; in the resource token, and the PS refuses:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"denied"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"detail"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"Mission evaluation failed: account &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;mallory-org&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt; == relay.payer &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;alice-org&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"mission_checks"&lt;/span&gt;&lt;span class="p"&gt;:[&lt;/span&gt;&lt;span class="err"&gt;…&lt;/span&gt;&lt;span class="p"&gt;]}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;SearchCo never receives an auth token, so it can't be talked into billing anyone.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Forbidden operation.&lt;/strong&gt; ResearchCo asks for &lt;code&gt;delete&lt;/code&gt;. SearchCo really does offer delete, but the mission only allows &lt;code&gt;search&lt;/code&gt; there, so the PS refuses with &lt;code&gt;relay.scopes[SearchCo] ∋ "delete"&lt;/code&gt; failing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Untrusted issuer.&lt;/strong&gt; ResearchCo skips the PS and presents an auth token signed by a rogue key, claiming to come from Alice's PS. SearchCo fetches the PS's real keys, the signature fails, and the call is rejected. This is the one scenario the receiver catches rather than the PS.&lt;/p&gt;

&lt;p&gt;All errors use the draft's format: &lt;code&gt;application/problem+json&lt;/code&gt; with an AAuth &lt;code&gt;error&lt;/code&gt; code, and &lt;code&gt;denied&lt;/code&gt; for policy refusals.&lt;/p&gt;

&lt;h2&gt;
  
  
  Next
&lt;/h2&gt;

&lt;p&gt;So far every hop looks like the Assistant calling PlannerCo. Part 4 covers what changes when PlannerCo passes work on to ResearchCo, and ResearchCo to SearchCo: call chaining with &lt;code&gt;upstream_token&lt;/code&gt;.&lt;/p&gt;

</description>
      <category>security</category>
      <category>authorization</category>
      <category>oauth</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
