Configure Microsoft Entra ID

Use Microsoft Entra ID as the identity provider for your Dtwo gateway, with OAuth for Claude Code, Claude Desktop, Codex, and Cursor.

On this page
  1. Overview
  2. Register the gateway application in Entra
  3. Optional: add the upn claim
  4. Configure your Dtwo gateway
  5. Register your AI clients and test the connection

Overview

Microsoft Entra ID can act as the identity provider for your Dtwo gateway, so users sign in with their existing Entra accounts. You register the gateway as an application in your own Entra tenant. Each AI client that connects to the gateway is registered as its own Entra application with the redirect URI that client uses.

This guide uses Entra’s v2.0 access tokens.

If you’ve already set up Dtwo in Entra with v1.0 access tokens and would like to upgrade to v2.0, follow Migrate Entra to v2.0 access tokens.

Register the gateway application in Entra

  1. In the Microsoft Entra admin center, go to App registrations → New registration. Give it a name (for example Dtwo Gateway), set Supported account types to Single tenant only, and select Register.

  2. From the app’s Overview page, copy the Directory (tenant) ID (<DirectoryId>) and the Application (client) ID (<ApplicationId>).

  3. Go to Expose an API. Next to Application ID URI, select Add and accept the default (api://<ApplicationId>).

  4. Under Scopes defined by this API, select Add a scope and create the scope your clients will request:

    • Scope name: mcp
    • Who can consent: Admins and users
    • Display name and Description: Access MCP
    • Select Add scope.
  5. Open Manifest to edit the raw JSON. Make two changes:

    • Find identifierUris. It should read [ "api://<ApplicationId>" ]. Add your gateway’s URL to the list:

      "identifierUris": [
        "api://<ApplicationId>",
        "<GatewayURL>"
      ],

      Replace <GatewayURL> with your gateway’s MCP URL, found in the Overview tab for your gateway in the Dtwo UI.

    • Find accessTokenAcceptedVersion and set it to 2. In the Microsoft Graph App Manifest tab, the same setting is api.requestedAccessTokenVersion.

  6. Select Save at the top of the Manifest screen.

Entra may refuse the gateway URL with “identifier URIs must be on a verified domain.” If it does, verify the domain first (see Verify your gateway’s custom domain), then add the URL again.

Optional: add the upn claim

Some policies identify a person by the upn or email claim in their access token. Entra’s v2.0 access tokens don’t include either claim by default. If your policies read them, go to Token configuration → Add optional claim, choose Access, select upn, and select Add.

Configure your Dtwo gateway

Go to your gateway in the Dtwo UI and open Configuration → Advanced. In the gateway section, add the following entry:

authentication:
  enabled: true
  jwks_info:
    jwt_algorithm: "RS256"
    jwt_jwks_uri: "https://login.microsoftonline.com/<DirectoryId>/discovery/v2.0/keys"
    jwt_issuer: "https://login.microsoftonline.com/<DirectoryId>/v2.0"
    jwt_audience: "<ApplicationId>"
  sso_issuer: "https://login.microsoftonline.com/<DirectoryId>/v2.0"
  mcp_oauth_resource_metadata_enabled: true
  jwt_issuer_verification: true
  jwt_audience_verification: true
  require_jti: false
  require_token_expiration: true
  sso_generic_scope: openid profile email <GatewayURL>/mcp

Replace the placeholder values:

  • <DirectoryId>: the Directory (tenant) ID of the gateway application.
  • <ApplicationId>: the Application (client) ID of the gateway application.
  • <GatewayURL>: your gateway’s MCP URL, the same URL you added to identifierUris. The last entry in sso_generic_scope is that URL followed by /mcp, the scope you created in step 4. A Dtwo gateway URL already ends in /mcp, so the entry ends in /mcp/mcp, for example https://<customer>.hosted.us1.prod.dtwo.ai/mcp/mcp. This is intended: the first /mcp is part of the gateway URL, and the second is the scope name.

Save the configuration and deploy the gateway.

Register your AI clients and test the connection

Each AI client needs its own app registration in Entra, because each one has a different redirect URI. Pick your client below to register it, then connect it for yourself to check that sign-in and the gateway work before you roll it out to your organization.

Register Claude Desktop in Entra

  1. Go to App registrations → New registration, name it after the client (for example Claude Desktop), set Supported account types to Single Tenant Only — Default Directory, and select Register.
  2. From Overview, copy the Application (client) ID — this is the client’s <ClientId>.
  3. Under Authentication → Add a platform, select Mobile and desktop applications and add the redirect URI https://claude.ai/api/mcp/auth_callback.
  4. Under API permissions → Add a permission, open the APIs my organization uses tab, search for <ApplicationId>, select your gateway application, check the mcp scope, and select Add permissions.

Connect Claude Desktop

  1. Open the place where you add connectors:
    • Free, Pro, and Max: in Claude Desktop, open Customize → Connectors and click Add custom connector.
    • Team and Enterprise: open Organization settings → Connectors, click Add, then Custom. If you’re asked for a connector type, choose Web. You need to be an Owner, or on Enterprise, have a custom role that manages the organization’s libraries. This adds the gateway for your whole organization, not just for you.
  2. Name the connector after your gateway, if asked, and enter your gateway’s MCP URL. Copy it from your gateway’s Overview tab in the Dtwo UI. It must start with https://.
  3. Choose Use your own OAuth client and enter the <ClientId> you copied when you registered the client in your identity provider.
  4. Click Add.
  5. Click Connect and sign in when your browser opens. On Team and Enterprise, you’ll find Connect under Customize → Connectors, not in Organization settings.
  6. Start a new chat, click + in the message box, choose Connectors, and switch your gateway’s connector on. A connector that’s added but switched off is never used.

Register Claude Code in Entra

  1. Go to App registrations → New registration, name it after the client (for example Claude Code), set Supported account types to Single Tenant Only — Default Directory, and select Register.
  2. From Overview, copy the Application (client) ID — this is the client’s <ClientId>.
  3. Under Authentication → Add a platform, select Mobile and desktop applications and add the redirect URI http://localhost:33418/callback.
  4. Under API permissions → Add a permission, open the APIs my organization uses tab, search for <ApplicationId>, select your gateway application, check the mcp scope, and select Add permissions.

Connect Claude Code

In a terminal, add the gateway as an MCP server:

claude mcp add --transport http --scope user <GatewayName> <GatewayURL> --client-id <ClientId> --callback-port 33418

Replace the placeholders:

  • <GatewayName>: your gateway’s name. This is the name you’ll see for the server in Claude Code.
  • <GatewayURL>: your gateway’s MCP URL. Copy it from your gateway’s Overview tab in the Dtwo UI. It must start with https://.
  • <ClientId>: the client ID you copied when you registered the client in your identity provider.

The --callback-port must match the port in the redirect URI registered for Claude Code in your identity provider.

--scope sets where the gateway is available:

  • --scope user (used above): every project you open in Claude Code.
  • --scope local: only the project you ran the command in, and only for you. This is the default if you leave --scope out.
  • --scope project: the project you ran the command in, for everyone who works on it. Claude Code saves the gateway to a .mcp.json file in the project, which you commit to your repository.

Then start Claude Code, run /mcp, select your gateway, and sign in when your browser opens.

To share the setup through your repository without running the command, add the gateway to .mcp.json at the project root yourself, using the same values:

{
  "mcpServers": {
    "<GatewayName>": {
      "type": "http",
      "url": "<GatewayURL>",
      "oauth": {
        "clientId": "<ClientId>",
        "callbackPort": 33418
      }
    }
  }
}

Then run /mcp, select the gateway, and choose Authenticate.

Register Cursor in Entra

  1. Go to App registrations → New registration, name it after the client (for example Cursor), set Supported account types to Single Tenant Only — Default Directory, and select Register.
  2. From Overview, copy the Application (client) ID — this is the client’s <ClientId>.
  3. Under Authentication → Add a platform, select Mobile and desktop applications and add the redirect URI http://localhost:8787/callback.
  4. Under API permissions → Add a permission, open the APIs my organization uses tab, search for <ApplicationId>, select your gateway application, check the mcp scope, and select Add permissions.

Connect Cursor

  1. Add the gateway to ~/.cursor/mcp.json to use it in every project, or to .cursor/mcp.json in a project to use it there only:

    {
      "mcpServers": {
        "<GatewayName>": {
          "url": "<GatewayURL>",
          "auth": {
            "CLIENT_ID": "<ClientId>"
          }
        }
      }
    }

    Replace the placeholders:

    • <GatewayName>: your gateway’s name.
    • <GatewayURL>: your gateway’s MCP URL. Copy it from your gateway’s Overview tab in the Dtwo UI. It must start with https://.
    • <ClientId>: the client ID you copied when you registered the client in your identity provider.

    If the file already lists other servers, add this entry next to them.

  2. Open Customize in the sidebar, go to MCPs, and switch your gateway on.

  3. Sign in when your browser opens.

If the gateway doesn’t appear, run Developer: Reload Window from the command palette.

Register Codex in Entra

  1. Go to App registrations → New registration, name it after the client (for example Codex), set Supported account types to Single Tenant Only — Default Directory, and select Register.
  2. From Overview, copy the Application (client) ID — this is the client’s <ClientId>.
  3. Under Authentication → Add a platform, select Mobile and desktop applications and add the redirect URI http://127.0.0.1:33419/callback.
  4. Under API permissions → Add a permission, open the APIs my organization uses tab, search for <ApplicationId>, select your gateway application, check the mcp scope, and select Add permissions.

Connect Codex

  1. Add the gateway to ~/.codex/config.toml. Create the file if it doesn’t exist yet.

    [mcp_servers.<GatewayName>]
    url = "<GatewayURL>"
    
    [mcp_servers.<GatewayName>.oauth]
    client_id = "<ClientId>"
    callback_port = <CallbackPort>
    callback_url = "http://127.0.0.1:<CallbackPort>/callback"

    Replace the placeholders:

    • <GatewayName>: the server name. If your organization approves only the gateway, use the exact name your admin gave you. Codex blocks a server with any other name.
    • <GatewayURL>: your gateway’s MCP URL. Copy it from your gateway’s Overview tab in the Dtwo UI. It must start with https://.
    • <ClientId>: the client ID you copied when you registered the client in your identity provider.
    • <CallbackPort>: the port in the redirect URI registered for Codex in your identity provider. If it was registered following these docs, it’s 33419. callback_port and callback_url must match that redirect URI exactly.
  2. Sign in. In the Codex app, open Settings → MCP servers and select Authenticate next to your gateway. From a terminal, run codex mcp login <GatewayName> instead.

Once it works for you, roll out your gateway to your organization. That includes turning off direct connections to MCP servers.

Having trouble?

Email us and we'll help you get set up.

Email support
Get in touch

Tell us what you need to govern.

A few lines is plenty — what you're deploying, and what you need control over. We read every one.

↑↓ to navigate ↵ to open