Add support for Azure DefaultAzureCredential authentication when using codex CLI with Azure Hosted Models
Resolved 💬 13 comments Opened Jan 5, 2026 by niketansrane Closed May 1, 2026
💡 Likely answer: A maintainer (lostmygithubaccount, contributor)
responded on this thread — see the highlighted reply below.
What feature would you like to see?
Many organizations disable key-based authentication on Azure OpenAI resources for security compliance reasons. Currently, the Codex CLI only supports:
- OpenAI API key authentication (OPENAI_API_KEY/CODEX_API_KEY)
- ChatGPT OAuth authentication
This prevents users from using Codex CLI with Azure OpenAI deployments that require Azure AD authentication.
Additional information
Use Case
- This would enable enterprise users to use Codex CLI with their organization's Azure OpenAI resources while maintaining security best practices and compliance requirements.
13 Comments
Workaround for now: Use Azure CLI to get a bearer token and set it as an environment variable.
I have an implementation my team has been using for this feature here would love to continue the conversation. The implementation currently requires a config which looks like this:
also happy to contribute this
In this way the token in always up to date or you have to send this command every time?
Solutions using env_key for the tokens need to be restarted whenever the tokens expire since env var are not updated in running processes.
Assuming your personal tokens have the right permissions for your Azure OpenAI resource, you can implemented a work around using a locally hosted proxy server.
Set up the config.toml like you would for Azure. Except the base_url is now http://127.0.0.1:8787/ (or whatever port you assign.) setting Env_key doesn't matter as the proxy will eat it. The proxy should route all paths and methods to the Azure endpoint. (Which would normally be in the base_url config field)
The proxy then uses DefaultAzureCrednetial() to get a valid token for cognitiveservices.azure.com and replaces the Authentication field in the header with this new bearer token.
The proxy server only requests a token at start up. Any time a request returns HTTP_UNAUTHORIZED, it assumes the token expired and requests a new one.
To get this to work, you may need to strip a couple other fields off the header which triggers some validation checks, like content-length.
I kept my proxy tiny as this is really just a crutch until there is better native support for Azure credentials.
Now you just start the server and enjoy the vibes.
---
I have model and model_reasoning_effort hard coded in the config.toml. With this set up, I have no model or reasoning selection. Anyone know how to provide model lists to Codex in VSCode using a custom model provider?
could someone be allowed to contribute this?
@niketansrane , please close as "Resolved". We can now use command-backed authentication as described here: https://developers.openai.com/codex/config-advanced#custom-model-providers (search for
model_providers.proxy.auth).For the next windows person
[model_providers.azure.auth]
command = "powershell"
args = ["-File", "C:\\FILE_LOCATION"]
timeout_ms = 5000
refresh_interval_ms = 300000
On macOS using codex-cli 0.125.0 with the following config.toml results in repeated attempts to authenticate via browser, but none of the authentication flows stick (browser pops, click on account, redirected, repeat):
Any guidance is appreciated. MS documentation says Entra ID is still not supported https://learn.microsoft.com/en-us/azure/foundry/openai/how-to/codex
After messing around with a shell script, this appears to work properly (it double-prompts on first launching _codex_, but then you can use _codex_ with Foundry models as you would with envVar API Key approach):
config.toml
azure-auth.sh
hey guys,
Could we solve the Azure auth issue generically so it will be a fit for CLI, MCP-Server and any other ways which require integration with Azure auth?
We need to support of the following:
1) Developer credentials, so developers can authenticate when running locally.
2) Managed Identity and Workload Identity credentials.
3) Credential caching and renewal.
4) Other optional credential modes.
We can solve it in code by depending on the azure_core and azure_identity crates, we should be able to support most of this with minimal custom implementation, it will integrate smoothly with existing Codex auth model.
Unfortunately, we will not be able to benefit from the CLI authentication solution proposed in custom model providers. The main problem is that we run Codex as an MCP server and we need to use Workload Identity, which is not a CLI concern (there is no cli for workload identity, everybody will need to re-implement it).
I have a solution integrated with the latest codex, I'm looking forward to contributing into codex.
@etraut-openai , appreciate it if we can gain traction on this effort.
The browser loop happens because the auth command is running
az login. That command is interactive and does not emit the bearer token Codex needs on stdout, so Codex keeps asking for auth instead of receiving a reusable token.A safer shape is:
az login --tenant <tenant>once outside Codex.refresh_interval_msbelow the token lifetime.Example script:
Then point the provider auth command at that script. On Windows, the PowerShell version should do the same thing: no browser login inside the command, only
az account get-access-tokenand print the token.If the token command works but requests still fail, the next things to verify are the Azure OpenAI
base_urldeployment path, theapi-versionquery param, and that the signed-in Azure principal has access to the specific Azure OpenAI resource.Do not babysit people who don’t know how to read documentation.
This whole thread should have stopped when I posted this comment.
@cixtor ,
do you have a proposal how to deal with this using the custom model providers?