Feature request: Support Microsoft Entra ID (Azure AD) OAuth2 Client Credentials for model providers (tenant_id/client_id/client_secret)

Resolved 💬 5 comments Opened Jan 12, 2026 by c0okB Closed Mar 20, 2026
💡 Likely answer: A maintainer (etraut-openai, contributor) responded on this thread — see the highlighted reply below.

What feature would you like to see?

Summary

Please add first-class support in Codex CLI for authenticating to LLM endpoints using Microsoft Entra ID (Azure AD) OAuth 2.0 client credentials (tenant_id + client_id + client_secret), and automatically attaching the resulting Bearer access token to requests.

This is needed for enterprise environments where API keys are disallowed and access must be governed via Entra ID app registrations / service principals.

Background / Why

Codex currently supports:

  • Sign in with ChatGPT (subscription)
  • Sign in with API key
  • For custom model providers: OpenAI auth (requires_openai_auth = true) or provider-specific API key via env var (env_key), or no auth.

However, many enterprises expose OpenAI-compatible endpoints behind Azure API Management / gateways that require Entra ID Bearer tokens, not API keys. We need Codex to obtain and refresh those tokens automatically.
(See Microsoft identity platform: OAuth2 client credentials grant flow.)

Current behavior

There is no built-in way for a custom provider to:
1) Fetch an Entra ID access token from https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token
2) Cache/refresh it
3) Attach Authorization: Bearer <token> to provider requests

Desired behavior

Add a new provider auth mode, e.g. auth.type = "entra_client_credentials" that:

  • Exchanges (tenant_id, client_id, client_secret) for an access token
  • Supports scope = "<resource>/.default" (v2 token endpoint) as the common enterprise pattern
  • Automatically refreshes token before expiry
  • Stores secrets securely (prefer OS keyring; allow env var references)
  • Sends requests with Authorization: Bearer <access_token>

Proposed config (example)

# ~/.codex/config.toml

[[model_providers]]
name = "my-enterprise-gateway"
base_url = "https://my-gateway.example.com/openai"
# OpenAI-compatible routes, e.g. /v1/chat/completions
requires_openai_auth = false

[model_providers.auth]
type = "entra_client_credentials"
tenant_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
client_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
# Prefer env var to avoid secrets in files
client_secret_env = "AZURE_CLIENT_SECRET"
# Token endpoint (optional; can be derived from tenant_id)
token_url = "https://login.microsoftonline.com/${tenant_id}/oauth2/v2.0/token"
# Typical v2 scope format for client credentials
scope = "https://cognitiveservices.azure.com/.default"
# Optional: audience/resource override if needed by gateway
# audience = "https://cognitiveservices.azure.com/"


### Additional information

_No response_

View original on GitHub ↗

5 Comments

etraut-openai contributor · 7 months ago

Thanks for the suggestion. There are already some other feature requests that overlap this one (and have existing upvotes):

https://github.com/openai/codex/issues/2522
https://github.com/openai/codex/issues/4484
https://github.com/openai/codex/issues/8732

c0okB · 7 months ago
Thanks for the suggestion. There are already some other feature requests that overlap this one (and have existing upvotes): #2522 #4484 #8732

It seems codex does not implement support for connecting to Azure OpenAI using Entra ID so far. I can't see relevant code in source code.

etraut-openai contributor · 5 months ago

This feature request hasn't received enough upvotes, so closing.

bahtman · 5 months ago

@etraut-openai I Think it is very disingenuous that for any PR/Issue that describes this exact issue (EntraID auth) you guys are completely radio silent. That is up until you get any excuse to close these item.

Can you please provide some clarification to whether you have any ambition to support orgs that want to use your product?

silenceroom · 2 months ago

this is woulbe an excellent feature for orgs that would like to deploy codex.