> ## Documentation Index
> Fetch the complete documentation index at: https://www.truefoundry.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Govern Copilot Studio agents with OAuth2 OBO

> Govern Copilot Studio agents with OAuth2 On behalf of (OBO)

Use this checklist to connect Copilot Studio to the MCP server with OAuth2 on-behalf-of (OBO). Each user signs in, and the gateway sees each call as both the agent and the user. When you finish, your Copilot Studio agent appears in the TrueFoundry Agent Registry, and its egress and ingress calls go through the gateway with governance applied, including agent identity and RBAC.

Want user identity only, without agent identity? Use the [DCR checklist](https://www.truefoundry.com/docs/agent-platform/agent-governance/truefoundry-implementation/microsoft-copilot-studio/governance-checklist/dcr.md) instead.

Complete these steps for each imported agent.

## Steps at a glance

1. [Create app registrations](#app-registration)
2. [Configure the identity provider](#configure-idp)
3. [Enable agent identity](#enable-identity)
4. [Add the MCP server to the gateway](#add-mcp-to-gateway)
5. [Grant the agent MCP access](#grant-agent-access-to-mcp)
6. [Point the connector at the gateway](#update-mcp-to-gateway-url)
7. [Update connector authentication to use OAuth2 OBO](#update-auth-to-use-agent-identity)

## Create app registrations

This section creates two kinds of Entra apps for the gateway hop:

* **`truefoundry-app`**: create this once, per tenant or gateway. It is the shared audience for all agents' connector tokens.
* **`agent-client-<slug>`**: create one per Copilot Studio agent. It is the connector's OAuth client. Its app ID appears as the `azp` claim, which TrueFoundry uses to identify the agent.

**Prerequisites:** an Entra role that can create app registrations. Cloud Application Administrator covers creating apps and granting admin consent. For the CLI, you need `az login` and `uuidgen`.

> [!NOTE]
>
> Copilot Studio's own **Entra Agent ID** does not appear in connector tokens.

Each agent has its own connector and `agent-client`, but all agents share `truefoundry-app`:

```text theme={"dark"}
Copilot Studio agent A ── connector (agent-client-A) ──┐
                                                       ├── aud = truefoundry-app ──► TrueFoundry gateway
Copilot Studio agent B ── connector (agent-client-B) ──┘   azp = agent-client-*
```

### Create `truefoundry-app` (shared audience)

> [!NOTE]
>
> If the app already exists, skip this section.

Connector tokens are issued for this app, so their `aud` claim is `api://<TFY_APP>`. The gateway accepts those tokens.

> [tab] Portal
>
> 1. Go to [Entra admin center](https://entra.microsoft.com) → **App registrations → New registration**.
> 2. Name the app `truefoundry-app`, choose single tenant, leave the redirect empty, and select **Register**. Copy the Application (client) ID. This is `$TFY_APP`.
> 3. Go to **Expose an API**:
>    * Set the Application ID URI to `api://<TFY_APP>`.
>    * Add the scope `access_as_user` (Admins and users, Enabled). It is a delegated **User** scope, not an app role.
> 4. Under **Authorized client applications**, add `fe053c5f-3692-4f14-aef2-ee34fc081cae` (Azure API Connections) with `access_as_user`.
> 5. In the manifest, set `api.requestedAccessTokenVersion` to **`2`**. This makes tokens use the v2 format, which puts the agent's app ID in the `azp` claim. TrueFoundry needs `azp` to identify the agent. A v1 token doesn't include it, so agent resolution fails.
> 6. Create a client secret for TrueFoundry. It is used for the gateway and MCP Auth Data, not the connector.
> 7. No API permissions are needed here. `agent-client` requests the refresh token (`offline_access`).

> [tab] Azure CLI
>
> ```bash expandable theme={"dark"}
> TENANT_ID="<your-tenant-id>"
> az login --tenant "$TENANT_ID"
>
> TFY_APP=$(az ad app create \
>   --display-name truefoundry-app \
>   --sign-in-audience AzureADMyOrg \
>   --query appId -o tsv)
> az ad sp create --id "$TFY_APP"
>
> OBJ=$(az ad app show --id "$TFY_APP" --query id -o tsv)
> SCOPE_ID=$(uuidgen | tr '[:upper:]' '[:lower:]')
>
> # Scope + v2 tokens (first PATCH)
> az rest --method PATCH \
>   --headers "Content-Type=application/json" \
>   --url "https://graph.microsoft.com/v1.0/applications/$OBJ" \
>   --body "{
>     \"identifierUris\": [\"api://$TFY_APP\"],
>     \"api\": {
>       \"requestedAccessTokenVersion\": 2,
>       \"oauth2PermissionScopes\": [{
>         \"id\": \"$SCOPE_ID\",
>         \"value\": \"access_as_user\",
>         \"type\": \"User\",
>         \"isEnabled\": true,
>         \"adminConsentDisplayName\": \"Act as the signed-in user through the agent\",
>         \"adminConsentDescription\": \"Allows a connector to obtain a token for the agent tier on behalf of the signed-in user.\",
>         \"userConsentDisplayName\": \"Let the agent act on your behalf\",
>         \"userConsentDescription\": \"Allows the agent to access tools on your behalf.\"
>       }]
>     }
>   }"
>
> # Pre-authorize Azure API Connections (second PATCH, required)
> APIM_CONNECTIONS=fe053c5f-3692-4f14-aef2-ee34fc081cae
> az rest --method PATCH \
>   --headers "Content-Type=application/json" \
>   --url "https://graph.microsoft.com/v1.0/applications/$OBJ" \
>   --body "{
>     \"api\": {
>       \"preAuthorizedApplications\": [
>         { \"appId\": \"$APIM_CONNECTIONS\", \"delegatedPermissionIds\": [\"$SCOPE_ID\"] }
>       ]
>     }
>   }"
>
> az ad app credential reset --id "$TFY_APP" --append \
>   --display-name gateway --years 1 --query password -o tsv
>
> echo "TFY_APP=$TFY_APP  Resource URL=api://$TFY_APP"
> ```
>
> Run the scope and pre-authorization as **two** separate PATCH calls. Combining them returns an `InvalidValue` error.

> [!NOTE]
>
> Without Azure API Connections pre-authorized on `access_as_user`, users see an interactive sign-in on every connector call.

### Create `agent-client` (one per agent)

This is the connector's OAuth client. Its app ID appears as the **`azp`** claim in tokens and as the agent's **Subject value**. Don't configure **Expose an API** on this app.

> [tab] Portal
>
> 1. Select **New registration**, name it `agent-client-<slug>`, and choose single tenant.
> 2. Under **Authentication → Web**, add the redirect URI `https://global.consent.azure-apim.net/redirect`. If the connector's Security tab shows an extra redirect URI after you create the connector, add it here too.
> 3. Under **API permissions (Delegated)**, add `truefoundry-app` → `access_as_user` and Graph → `offline_access`. Then select **Grant admin consent**.
> 4. Create a client secret for the Power Apps connector. Do not use it in TrueFoundry.

> [tab] Azure CLI
>
> ```bash expandable theme={"dark"}
> # Requires $TFY_APP from above
> AGENT_SLUG="support-bot"
> AGENT_CLIENT=$(az ad app create \
>   --display-name "agent-client-${AGENT_SLUG}" \
>   --sign-in-audience AzureADMyOrg \
>   --query appId -o tsv)
> az ad sp create --id "$AGENT_CLIENT"
>
> SCOPE_ID=$(az ad app show --id "$TFY_APP" \
>   --query "api.oauth2PermissionScopes[?value=='access_as_user'].id | [0]" -o tsv)
> GRAPH=00000003-0000-0000-c000-000000000000
> OFFLINE=7427e0e9-2fba-42fe-b0c0-848c9e6a8182
>
> az ad app permission add --id "$AGENT_CLIENT" --api "$TFY_APP" \
>   --api-permissions "${SCOPE_ID}=Scope"
> az ad app permission add --id "$AGENT_CLIENT" --api "$GRAPH" \
>   --api-permissions "${OFFLINE}=Scope"
>
> az ad app update --id "$AGENT_CLIENT" \
>   --web-redirect-uris "https://global.consent.azure-apim.net/redirect"
>
> az ad app credential reset --id "$AGENT_CLIENT" --append \
>   --display-name power-platform-connector --years 1 --query password -o tsv
>
> az ad app permission admin-consent --id "$AGENT_CLIENT"
>
> echo "AGENT_CLIENT=$AGENT_CLIENT"
> ```

> [!NOTE]
>
> Optional: pre-authorize this `agent-client` on `truefoundry-app` under **Authorized client applications**. Admin consent is enough on its own. Pre-authorization only reduces extra consent prompts.

> [!WARNING]
>
> Without an `agent-client` for each agent, agent identity is not propagated, and the gateway cannot identify the agent making the call.

## Configure the identity provider

Tell the gateway which Entra tokens to accept and how to resolve the agent from `azp`.

1. In TrueFoundry, go to **Settings → Security & Access → Identity Providers**.
2. Open an existing Entra provider, or select **Add Identity Provider**.
3. Set the following fields:

| Field | Value |
| - | - |
| **Enabled** | On |
| **Provider name** | For example, `entra-connector-agents` (lowercase, 3–32 characters) |
| **Issuer URL** | `https://login.microsoftonline.com/<tenant_id>/v2.0` |
| **JWKS URI** | `https://login.microsoftonline.com/<tenant_id>/discovery/v2.0/keys` |
| **Allowed audiences** | `api://<TFY_APP>` **and** `<TFY_APP>` |

4. Under **Resolve Token To → agent**, set:

| Field | Value |
| - | - |
| **Resolve to agent** | Enabled |
| **Name claim** | `azp` |
| **Acting on behalf of (slug) claim** | `preferred_username` (typical for Entra delegated tokens) |

Do **not** put `agent-client` IDs in Allowed audiences. They belong in the agent's Subject value.

For field details, see [External JWT](https://www.truefoundry.com/docs/platform/identity-providers/external-jwt.md).

```yaml theme={"dark"}
type: identity-provider
name: entra-connector-agents
provider: azure-entra-id
config:
  type: jwt
  issuer: https://login.microsoftonline.com/<tenant_id>/v2.0
  jwks_uri: https://login.microsoftonline.com/<tenant_id>/discovery/v2.0/keys
  audiences:
    - api://<TFY_APP>
    - <TFY_APP>
resolve_token_to:
  agent:
    name_claim: azp
    acting_on_behalf_of_slug_claim: preferred_username
```

> [!WARNING]
>
> Without this step, tokens for this agent are not mapped to the agent.

## Enable agent identity

Map each agent's `agent-client` so that the inbound `azp` claim resolves to the agent in TrueFoundry.

1. In **Agent Registry**, open the agent.
2. Enable **Agent Identity**:

| Field | Value |
| - | - |
| **Identity type** | Identity provider-backed |
| **Identity Provider** | The Entra provider from [Configure the identity provider](#configure-idp) |
| **Subject value** | This agent's **`agent-client` Application (client) ID** (the `azp` value) |

3. Grant **Agent Access** to the users or teams the agent may act for. This is required when the acting-on-behalf-of slug claim is set. Assign an owner team as well.

> [!NOTE]
>
> The Subject value must be the **`agent-client` app ID**. It is not `truefoundry-app`, not the Copilot Studio `AgentIdentityId`, and not the connector's display name.

> [!WARNING]
>
> Without this step, calls from this agent may not be identified as that agent.

## Add the MCP server to the gateway

Complete these steps for each MCP server added to the agent.

### Register the upstream MCP server

Register the MCP HTTPS endpoint in the gateway. The connector calls the gateway URL for this server.

> [!NOTE]
>
> If the MCP server is already added to the gateway, skip this section. You still need its gateway URL for the connector step.

1. If the MCP server isn't registered yet, register it. Getting started: [MCP Server Getting Started](https://www.truefoundry.com/docs/ai-gateway/mcp/mcp-server-getting-started.md).
2. If the MCP server authentication isn't set yet, open **Auth Data** and select the method the upstream server expects: **API Key**, **OAuth2**, **AWS SigV4**, or **Token Passthrough**. See [Outbound Authentication](https://www.truefoundry.com/docs/ai-gateway/mcp/mcp-gateway-auth-security.md#outbound-authentication) to choose.
3. Save the MCP server.
4. Copy the gateway URL for the server from **How To Use** section. You need it in the connector step below.

### Create a Virtual MCP Server

> [!NOTE]
>
> You need a Virtual MCP Server only if the remote MCP server uses `grant_type: authorization_code`. Otherwise, skip this section.

1. Go to **MCP Gateway → Virtual MCP Servers → Create**.
2. Enter a **Name** and turn on [Best Effort Mode](https://www.truefoundry.com/docs/ai-gateway/mcp/virtual-mcp-server.md#best-effort-mode).
3. Add the upstream MCP server as a **source**, and select the tools the agent should see.
4. Save, then copy the URL from **How To Use** section. You use it in [Point the connector at the gateway](#update-mcp-to-gateway-url).

For details, see [Virtual MCP Server](https://www.truefoundry.com/docs/ai-gateway/mcp/virtual-mcp-server.md).

## Grant the agent MCP access

Registering the server does not authorize tool calls. Grant the agent access to the **MCP Server** (and **Virtual MCP Server**) that the connector calls.

1. In **Agent Registry**, find the agent.
2. Go to **⋯ → Manage Permissions**.
3. Select **Add Permission** → **MCP Servers**, select the role **MCP Server User**, select the MCP Server, and save.
4. *Optional:* If you created a Virtual MCP Server, repeat step 3 and select the Virtual MCP Server instead.

> [!WARNING]
>
> Without this grant, the gateway returns **403**.

## Point the connector at the gateway

Create a **new** custom connector for each agent. It points at this server's gateway URL and uses this agent's `agent-client`. Don't reuse or change another agent's connector. TrueFoundry identifies the agent from the token's `azp` claim, which comes from the connector's client ID, so a shared connector gives every agent the same identity.

When you build the connector:

* Use the gateway URL for this server. If you created a Virtual MCP Server, use its URL from **How To Use**.
* Split `https://<gateway-host>/<gateway-path>` into swagger `host` = `<gateway-host>` and path = `/<gateway-path>`, with **`basePath: /`**.
* Build the connector in **Power Apps**, not in the Copilot Studio MCP wizard.

> [!NOTE]
>
> Keep `basePath: /` and put the full path under `paths:`. If you put the path only in `basePath`, the import succeeds but the server isn't registered as an MCP operation, so the tool list stays empty.

### Create the new gateway connector

> [tab] Portal
>
> 1. Go to **Power Apps → Custom connectors → New → Import an OpenAPI file**.
> 2. Use this definition:
>
> ```yaml theme={"dark"}
> swagger: '2.0'
> info:
>   title: My MCP via Gateway
>   version: '1.0.0'
> host: <gateway-host>
> basePath: /
> schemes: [https]
> paths:
>   /<gateway-path-for-this-server>:
>     post:
>       summary: MCP server
>       operationId: InvokeMCP
>       x-ms-agentic-protocol: mcp-streamable-1.0
>       responses:
>         '200':
>           description: Success
> ```
>
> 3. Set the **Security** tab as described in [Update connector authentication to use OAuth2 OBO](#update-auth-to-use-agent-identity).
> 4. Select **Create**.
> 5. In Copilot Studio, open the agent and go to **Tools → Add a tool → MCP**. Search for the new connector, select it and create a connection.
> 6. Test the new connector. If the agent already had an older connector for this server, remove it from the agent. Then select **Publish** to apply the changes.
> 7. Delete the old connector in **Power Apps → Custom connectors** only if no other agent uses it.

> [tab] Azure CLI / Power Apps API
>
> Use the `paconn` CLI to create the connector from two files. The OAuth settings go in the second file.
>
> 1. Save the gateway swagger as `apiDefinition.swagger.json`. This is the Portal tab definition written as JSON, because `paconn` can't read YAML. Replace `<gateway-host>` and `<gateway-path-for-this-server>` with the values for this server.
>
> ```json apiDefinition.swagger.json theme={"dark"}
> {
>   "swagger": "2.0",
>   "info": {
>     "title": "My MCP via Gateway",
>     "version": "1.0.0"
>   },
>   "host": "<gateway-host>",
>   "basePath": "/",
>   "schemes": ["https"],
>   "paths": {
>     "/<gateway-path-for-this-server>": {
>       "post": {
>         "summary": "MCP server",
>         "operationId": "InvokeMCP",
>         "x-ms-agentic-protocol": "mcp-streamable-1.0",
>         "responses": {
>           "200": {
>             "description": "Success"
>           }
>         }
>       }
>     }
>   }
> }
> ```
>
> 2. Save `apiProperties.json` with the OAuth 2.0 settings from the table in [Update connector authentication to use OAuth2 OBO](#update-auth-to-use-agent-identity). Leave the client secret out of the file.
> 3. Create the connector in the agent's Power Platform environment, and pass the `agent-client` secret on the command line:
>
> ```bash theme={"dark"}
> export ENV_ID="<power-platform-environment-id>"
>
> paconn create -e "$ENV_ID" \
>   --api-def apiDefinition.swagger.json \
>   --api-prop apiProperties.json \
>   --secret "<agent-client-secret>"
> ```
>
> 4. If the output prints a `redirectUrl`, add it to `agent-client`, as in the Portal tab.
> 5. In Copilot Studio, add the new connector to the agent, then test it. Remove the old connector from the agent, if there was one, and delete it only if no other agent uses it.

> [!WARNING]
>
> Without this step, the agent's MCP calls don't go through the gateway, so they can't be governed.

## Update connector authentication to use OAuth2 OBO

Configure the connector so Power Platform issues a token with **`aud` = `truefoundry-app`** and **`azp` = `agent-client`**.

| Security tab field | Value |
| - | - |
| Authentication type | **OAuth 2.0** |
| Identity Provider | **Azure Active Directory** |
| Client ID / secret | This agent's **`agent-client`** |
| Authorization URL / Login URI | `https://login.microsoftonline.com` |
| Tenant ID | Your Entra directory ID |
| **Resource URL** | `api://<TFY_APP>` |
| **Enable on-behalf-of login** | **On** |
| **Scope** | `api://<TFY_APP>/access_as_user offline_access` |

Before you continue, confirm two things:

* Azure API Connections is pre-authorized on `truefoundry-app`.
* `agent-client` lists this connector's redirect URL.

> [tab] Portal
>
> 1. Go to **Power Apps → Custom connectors → Security**.
> 2. Fill in the table above, then select **Update connector**.
> 3. If the connector's **Redirect URL** is missing from `agent-client`, add it.
> 4. In Copilot Studio, reconnect (or recreate the connection) so tokens use the new client.
> 5. Check the sign-in prompt. A short consent card means on-behalf-of is on. A full sign-in page means it is still off.

> [tab] Azure CLI / Power Apps API
>
> Update the existing connector with the OAuth settings for **`agent-client`**:
>
> 1. In `apiProperties.json`, set the `oAuthSettings` fields for the `aad` provider under `connectionParameters.*`:
>
>    | API field | Value |
>    | - | - |
>    | `identityProvider` | `aad` |
>    | `clientId` | `agent-client` app ID |
>    | `customParameters.LoginUri` | `https://login.microsoftonline.com` |
>    | `customParameters.TenantId` | Entra tenant ID |
>    | `customParameters.ResourceUri` | `api://$TFY_APP` |
>    | `properties.AzureActiveDirectoryResourceId` | Same as `ResourceUri` |
>    | `customParameters.EnableOnbehalfOfLogin` | `"true"` |
>    | `properties.IsOnbehalfofLoginSupported` | `true` |
>    | `scopes` | `["api://$TFY_APP/access_as_user", "offline_access"]` |
>
> 2. In `apiDefinition.swagger.json`, increase `info.version` (for example, from `1.0.0` to `1.0.1`) because the secret is changing.
>
> 3. Run the update. Pass the `agent-client` secret on the command line, not in the file:
>
>    ```bash theme={"dark"}
>    export ENV_ID="<power-platform-environment-id>"
>    export CONNECTOR="<connector-id>"
>
>    paconn update -e "$ENV_ID" -c "$CONNECTOR" \
>      --api-prop apiProperties.json \
>      --api-def apiDefinition.swagger.json \
>      --secret "<agent-client-secret>"
>    ```
>
> 4. Copy the `redirectUrl` that the command prints, and add it to `agent-client`.
>
> 5. In Copilot Studio, re-authorize the connection.

> [!WARNING]
>
> Without this step, user and agent identity are not propagated, so the gateway cannot identify the user or agent making the call.

## FAQ

> [accordion] Can I share one agent-client across all agents?
>
> No. Use one `agent-client` per agent. A shared client gives every agent the same `azp`, so the gateway can't tell them apart.

> [accordion] What goes in Allowed audiences?
>
> Only `api://<TFY_APP>` and `<TFY_APP>`. Put each `agent-client` app ID on the agent as the **Subject value**, not in Allowed audiences.

> [accordion] What goes in Subject value?
>
> The `agent-client` Application (client) ID, which is the value in the token's `azp` claim. Don't use the Copilot Studio `AgentIdentityId`.

> [accordion] Which access token version should truefoundry-app use?
>
> **2.** This gives the issuer `login.microsoftonline.com/<tenant_id>/v2.0` and puts the agent identity in `azp`.

> [accordion] Why pre-authorize Azure API Connections?
>
> So that Copilot Studio can get tokens silently. Without it, users see a sign-in prompt on every call.

> [accordion] Should On-behalf-of login be on?
>
> Yes. With it on, users see a short consent card, and user claims flow to the gateway. With it off, users see a full sign-in page.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.