Skip to content

Added Microsoft Entra ID Support for Keyless Auth #1778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

lavaman131
Copy link

Problem

This PR introduces support for Microsoft Entra ID as a keyless authentication method for Azure OpenAI, refactors token handling, and enhances configuration and error management across multiple modules. The changes primarily focus on enabling seamless integration with Azure services, improving token caching mechanisms, and updating the authentication logic. It follows up on some of @thegovind's work [#769, #92] adding support for Azure OpenAI, but now in the new Rust API and without introducing any new dependencies to the project.

Why?

Many companies have API keys disabled (Microsoft is one example) for security reasons preventing access to codex. This would allow for more developers to be able to use the CLI.

Changes

Support for Microsoft Entra ID and Azure OpenAI Integration:

  • Added AuthMode::MicrosoftEntraID to support keyless authentication via Microsoft Entra ID. Updated token retrieval logic to use Azure CLI for fetching access tokens and implemented caching with expiration checks (codex-rs/login/src/lib.rs). [1] [2]
  • Updated load_auth function to handle Azure-specific configurations, including environment variables and model provider names (codex-rs/login/src/lib.rs). [1] [2]
  • Modified relevant functions across modules (run_login_status, run_main, init_codex, etc.) to pass model provider details for authentication (codex-rs/cli/src/login.rs, codex-rs/cli/src/proto.rs, codex-rs/core/src/codex_wrapper.rs, codex-rs/tui/src/lib.rs). [1] [2] [3] [4]

Configuration Enhancements:

  • Added documentation for configuring Microsoft Entra ID in config.md, including instructions for setting up Azure CLI and modifying the codex configuration file (codex-rs/config.md). [1] [2]
  • Introduced query parameter handling in ModelClient for Azure-specific API requirements, ensuring proper URL construction (codex-rs/core/src/client.rs). [1] [2]

Code Refactoring and Cleanup:

  • Reorganized imports in client.rs to improve readability and removed unused dependencies (codex-rs/core/src/client.rs). [1] [2]
  • Replaced synchronous file operations with asynchronous equivalents for better performance and compatibility (codex-rs/login/src/lib.rs). [1] [2]

Error Handling Improvements:

  • Enhanced error messages for missing environment variables and Azure CLI issues to guide users during setup (codex-rs/core/src/client.rs, codex-rs/login/src/lib.rs). [1] [2]
  • Added fallback mechanisms for token retrieval and caching to ensure robustness in authentication workflows (codex-rs/login/src/lib.rs).

Copy link

github-actions bot commented Aug 1, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@lavaman131
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Aug 1, 2025
pub fn load_auth(
codex_home: &Path,
model_provider_name: &str,
env_key: &Option<String>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to use Option<&str> than &Option<String>.
With Option<&str>, you can pass None directly without reference and convert Option<String> to Option<&str> by calling as_deref() method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants