Edit

Configure On-Behalf-Of (OBO) user-delegated authentication

Data API builder 2.0 supports On-Behalf-Of (OBO) authentication, sometimes referred to as pass-through authentication, for Microsoft SQL databases using Microsoft Entra ID. When enabled, DAB exchanges the incoming user token for a downstream SQL token so the database authenticates as the actual calling user.

With standard authentication, DAB validates the caller's token but connects to the database using its own credentials (managed identity or connection string). With OBO, DAB performs a token exchange so the database sees the real user identity.

Note

The Data API builder functionality described in this section is available in version 2.0 and later. For more information, see What's new in version 2.0.

When to use OBO

OBO is the right choice when the SQL database must know who the actual caller is:

Scenario Use OBO?
Row-level security policies that depend on user identity Yes
Compliance auditing that requires per-user database access logs Yes
MCP scenarios where transparent user identification matters Yes
Simple API access where DAB connects with its own credentials No
Non-MSSQL databases No

Important

Today, OBO is supported only for Microsoft SQL databases with Entra ID.

Prerequisites

  • Data API builder CLI version 2.0 or later
  • dab-config.json with data-source.database-type set to mssql
  • An Entra ID app registration with the appropriate API permissions to request tokens for the database
  • An upstream identity provider that issues JWTs accepted by DAB (Entra ID or a custom provider you configure)
  • An MSSQL database configured to accept Microsoft Entra ID tokens

Connection string requirement

Important

When OBO is enabled, the connection string must not include an Authentication= keyword (such as Authentication=Active Directory Managed Identity). The Microsoft.Data.SqlClient library throws an exception if AccessToken is set on a connection that already has Authentication= in its connection string. Use a bare connection string containing only server, database, and encryption settings:

Server=tcp:<server>.database.windows.net,1433;Database=<db>;Encrypt=true;TrustServerCertificate=true

DAB 2.0 with OBO acquires an MSI token automatically for health checks and internal operations, and injects the per-user OBO token for authenticated requests.

Step 1: Choose an OBO application credential

Use a client secret or workload identity federation to authenticate the DAB API application during the token exchange. Federation replaces the application client secret, not the user's token. SQL still authenticates the calling user.

Variable Value Required for
DAB_OBO_CLIENT_ID Application (client) ID of the DAB API app registration Both options
DAB_OBO_TENANT_ID Microsoft Entra tenant ID Both options
DAB_OBO_CLIENT_SECRET Client secret for the DAB API app registration Client secret (leave unset if using workload identity federation)
DAB_OBO_MANAGED_IDENTITY_CLIENT_ID Client ID of the user-assigned managed identity Workload identity federation (leave unset if using client secret option)

Important

On builds that support federation, set exactly one credential variable: DAB_OBO_CLIENT_SECRET or DAB_OBO_MANAGED_IDENTITY_CLIENT_ID. If you set both or neither, DAB fails configuration validation when OBO is enabled. Restart DAB after changing these settings.

Use a client secret

Existing client-secret configurations remain supported. Set the API app's client ID, tenant ID, and client secret. Remove the managed identity credential setting if it exists.

export DAB_OBO_CLIENT_ID="<api-app-client-id>"
export DAB_OBO_TENANT_ID="<tenant-id>"
export DAB_OBO_CLIENT_SECRET="<api-app-client-secret>"
unset DAB_OBO_MANAGED_IDENTITY_CLIENT_ID

Use workload identity federation (secretless)

Note

Secretless OBO is available in DAB release 2.2.0-rc or later.

Use a user-assigned managed identity on Azure public cloud. The managed identity and DAB API app registration must belong to the same Microsoft Entra tenant.

  1. Attach the user-assigned managed identity to the Azure resource hosting DAB.

  2. Open the DAB API app registration in the Microsoft Entra admin center.

  3. Select Certificates & secrets > Federated credentials > Add credential.

  4. Choose the Managed identity scenario and select the identity attached to the DAB host.

  5. Configure the trust with these values, then add the credential:

    Field Value
    Issuer https://login.microsoftonline.com/<tenant-id>/v2.0
    Subject Object (principal) ID of the user-assigned managed identity
    Audience api://AzureADTokenExchange

For details, see Configure an application to trust a managed identity.

Keep DAB_OBO_CLIENT_ID and DAB_OBO_TENANT_ID. Set DAB_OBO_MANAGED_IDENTITY_CLIENT_ID to the managed identity's Client ID, not its Object (principal) ID. Remove DAB_OBO_CLIENT_SECRET.

export DAB_OBO_CLIENT_ID="<api-app-client-id>"
export DAB_OBO_TENANT_ID="<tenant-id>"
export DAB_OBO_MANAGED_IDENTITY_CLIENT_ID="<user-assigned-managed-identity-client-id>"
unset DAB_OBO_CLIENT_SECRET

Existing client-secret configurations remain supported. Federation adds no JSON properties or CLI flags. Keep the same OBO API permissions, consent, SQL users and permissions, and connection-string settings. Result caching must remain disabled.

Step 2: Configure the data source

Enable OBO in your dab-config.json under the data-source section. The data source must be mssql.

{
  "data-source": {
    "database-type": "mssql",
    "connection-string": "@env('SQL_CONNECTION_STRING')",
    "user-delegated-auth": {
      "enabled": true,
      "provider": "EntraId",
      "database-audience": "https://database.windows.net"
    }
  }
}
Property Description
enabled Turns OBO on or off
provider The identity provider for the token exchange. Currently only EntraId is supported
database-audience The target audience for the downstream SQL token (required when OBO is enabled)

Step 3: Disable caching

Caching must be disabled when OBO is configured. Because each user gets a distinct database connection, cached results from one user's connection must not be served to another.

{
  "runtime": {
    "cache": {
      "enabled": false
    }
  }
}

Step 4: Configure using the CLI

You can also configure OBO entirely from the CLI:

dab configure --data-source.database-type mssql
dab configure --runtime.cache.enabled false
dab configure --data-source.user-delegated-auth.enabled true
dab configure --data-source.user-delegated-auth.provider EntraId
dab configure --data-source.user-delegated-auth.database-audience "https://database.windows.net"

Full configuration example

{
  "data-source": {
    "database-type": "mssql",
    "connection-string": "@env('SQL_CONNECTION_STRING')",
    "user-delegated-auth": {
      "enabled": true,
      "provider": "EntraId",
      "database-audience": "https://database.windows.net"
    }
  },
  "runtime": {
    "cache": {
      "enabled": false
    }
  }
}

Where SQL_CONNECTION_STRING must be a bare connection string with no Authentication= keyword — for example:

Server=tcp:<server>.database.windows.net,1433;Database=<db>;Encrypt=true;TrustServerCertificate=true

Per-user connection pooling

When OBO is enabled, DAB maintains separate SQL connection pools per user so that one user's access token is never reused for another user's request. When row-level security depends on who is connected, you can be confident that connection reuse across users doesn't silently grant the wrong access.

Note

When using OBO, any custom values you might put in SQL connection string application name field may be truncated.