Skip to content

Move auth code into login crate#15150

Merged
aibrahim-oai merged 25 commits intomainfrom
auth-crate-split
Mar 20, 2026
Merged

Move auth code into login crate#15150
aibrahim-oai merged 25 commits intomainfrom
auth-crate-split

Conversation

@aibrahim-oai
Copy link
Collaborator

@aibrahim-oai aibrahim-oai commented Mar 19, 2026

  • Move the auth implementation and token data into codex-login.
  • Keep codex-core re-exporting that surface from codex-login for existing callers.

aibrahim-oai added a commit that referenced this pull request Mar 19, 2026
Fix moved auth test imports, add auth-crate test deps, and expose testing constructors used by codex-core.

Co-authored-by: Codex <noreply@openai.com>
aibrahim-oai added a commit that referenced this pull request Mar 19, 2026
Make auth testing constructors public for codex-core callers across the new crate boundary.

Co-authored-by: Codex <noreply@openai.com>
aibrahim-oai added a commit that referenced this pull request Mar 19, 2026
Add a Bazel package marker for the extracted auth crate so the new source package is visible to Bazel.

Co-authored-by: Codex <noreply@openai.com>
aibrahim-oai added a commit that referenced this pull request Mar 19, 2026
Define the auth source filegroup expected by the parent Bazel package after extracting auth into a nested crate.

Co-authored-by: Codex <noreply@openai.com>
aibrahim-oai added a commit that referenced this pull request Mar 19, 2026
Declare the extracted auth package as a Bazel Rust crate target so codex-core can depend on it under Bazel.

Co-authored-by: Codex <noreply@openai.com>
aibrahim-oai added a commit that referenced this pull request Mar 19, 2026
Point the extracted auth Bazel crate at its nonstandard root-level Rust sources so the :auth library target is generated.

Co-authored-by: Codex <noreply@openai.com>
aibrahim-oai added a commit that referenced this pull request Mar 19, 2026
Pass the extracted auth config to enforce_login_restrictions at the remaining Rust callsites.

Co-authored-by: Codex <noreply@openai.com>
aibrahim-oai added a commit that referenced this pull request Mar 19, 2026
Construct AuthConfig explicitly at the remaining login restriction callsites after the auth split.

Co-authored-by: Codex <noreply@openai.com>
@aibrahim-oai
Copy link
Collaborator Author

@codex review this

Copy link
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

if let Err(err) = enforce_login_restrictions(&config) {

P0 Badge Replace removed auth restriction call in TUI startup

run_main still calls enforce_login_restrictions(&config), but this commit removed that API in favor of enforce_login_restrictions_with_client. With no in-scope replacement at this callsite, codex-tui no longer compiles.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

aibrahim-oai added a commit that referenced this pull request Mar 19, 2026
Switch the remaining TUI login restriction callsite to the explicit client path so codex-tui builds after removing the no-client auth wrapper.

Co-authored-by: Codex <noreply@openai.com>
@aibrahim-oai
Copy link
Collaborator Author

@codex review this

@chatgpt-codex-connector
Copy link
Contributor

Codex Review: Didn't find any major issues. Can't wait for the next one!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

aibrahim-oai added a commit that referenced this pull request Mar 19, 2026
Move the codex-terminal dev-dependency to the mcp test support crate that imports it so CI can compile mcp_test_support again.

Co-authored-by: Codex <noreply@openai.com>
#[cfg(test)]
#[path = "default_client_tests.rs"]
mod tests;
pub use codex_client::CODEX_INTERNAL_ORIGINATOR_OVERRIDE_ENV_VAR;
Copy link
Collaborator Author

@aibrahim-oai aibrahim-oai Mar 19, 2026

Choose a reason for hiding this comment

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

should I reexport like that or make other crates depend on the new auth crate?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think reexporting makes more sense to keep auth centralized

aibrahim-oai added a commit that referenced this pull request Mar 19, 2026
Instantiate the environment before fetching the filesystem so app-server compiles under Bazel again.

Co-authored-by: Codex <noreply@openai.com>
aibrahim-oai added a commit that referenced this pull request Mar 19, 2026
Instantiate the exec-server environment before fetching the filesystem so the PR merge ref compiles under Bazel.

Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
@aibrahim-oai aibrahim-oai changed the base branch from main to terminal-crate-split March 19, 2026 19:56
@aibrahim-oai aibrahim-oai changed the title Make core auth a separate crate Move auth code into login crate Mar 19, 2026
Co-authored-by: Codex <noreply@openai.com>
@aibrahim-oai aibrahim-oai changed the base branch from terminal-crate-split to auth-behavioral-split March 19, 2026 20:26
@aibrahim-oai aibrahim-oai changed the base branch from auth-behavioral-split to terminal-crate-split March 19, 2026 20:34
aibrahim-oai and others added 3 commits March 19, 2026 13:39
Co-authored-by: Codex <noreply@openai.com>
- Move the auth implementation and token data into .
- Keep  re-exporting that surface from  for existing callers.

Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
@aibrahim-oai
Copy link
Collaborator Author

@codex review this

aibrahim-oai added a commit that referenced this pull request Mar 19, 2026
Co-authored-by: Codex <noreply@openai.com>
aibrahim-oai added a commit that referenced this pull request Mar 19, 2026
Move the telemetry auth-mode conversion back into codex-core callsites to avoid an orphan impl in codex-login, and include the stale Cargo.lock cleanup from the core dependency removal.

Co-authored-by: Codex <noreply@openai.com>
aibrahim-oai added a commit that referenced this pull request Mar 19, 2026
Import AuthMode from the auth module in codex-core; it is not re-exported at the crate root.

Co-authored-by: Codex <noreply@openai.com>
@aibrahim-oai
Copy link
Collaborator Author

@codex review this

Copy link
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fa2b69dc78

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +487 to +489
"originator".to_string(),
originator().value.as_str().to_string(),
std::env::var("CODEX_INTERNAL_ORIGINATOR_OVERRIDE")
.unwrap_or_else(|_| "codex_cli_rs".to_string()),
Copy link
Contributor

Choose a reason for hiding this comment

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

P1 Badge Preserve runtime originator in OAuth authorize URL

build_authorize_url now derives originator only from CODEX_INTERNAL_ORIGINATOR_OVERRIDE or a hardcoded codex_cli_rs. That ignores runtime originators set via set_default_originator (used by non-CLI entrypoints), so login requests are mislabeled. This changes behavior from pre-move code and can break client attribution or backend logic keyed on the originator query parameter.

Useful? React with 👍 / 👎.

Comment on lines +157 to +163
fn build_auth_http_client() -> CodexHttpClient {
let inner =
build_reqwest_client_with_custom_ca(reqwest::Client::builder()).unwrap_or_else(|error| {
tracing::warn!(error = %error, "failed to build auth reqwest client");
reqwest::Client::new()
});
CodexHttpClient::new(inner)
Copy link
Contributor

Choose a reason for hiding this comment

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

P2 Badge Reuse default HTTP client policy for token refresh

Auth refresh now uses a bare reqwest builder (build_auth_http_client) instead of the previous default client path. This drops default header wiring (originator/residency) and sandbox proxy behavior (no_proxy). In proxied or residency-constrained environments, refresh calls can fail or be routed with incorrect request metadata.

Useful? React with 👍 / 👎.

Copy link
Contributor

@joshka-oai joshka-oai left a comment

Choose a reason for hiding this comment

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

LGTM generally - a few questions about the reasons for the changed behavior bits

Some(auth) => match auth.auth_mode() {
CoreAuthMode::ApiKey => Some(Account::ApiKey {}),
CoreAuthMode::Chatgpt => {
CoreAuthMode::Chatgpt | CoreAuthMode::ChatgptAuthTokens => {
Copy link
Contributor

Choose a reason for hiding this comment

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

What's this change about?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We have multiple enums and we should unify at some point

"originator".to_string(),
originator().value.as_str().to_string(),
std::env::var("CODEX_INTERNAL_ORIGINATOR_OVERRIDE")
.unwrap_or_else(|_| "codex_cli_rs".to_string()),
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reasone for this change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

reverted

@aibrahim-oai
Copy link
Collaborator Author

@codex review this

Copy link
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 178a0dc31c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@aibrahim-oai
Copy link
Collaborator Author

@codex review latest commit

Copy link
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 178a0dc31c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +32 to +35
pub use auth::login_with_api_key;
pub use auth::logout;
pub use auth::read_openai_api_key_from_env;
pub use auth::save_auth;
Copy link
Contributor

Choose a reason for hiding this comment

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

P1 Badge Re-export missing auth helpers for compatibility

The commit message says codex-core should keep the old auth surface, but codex-login root no longer re-exports helpers like login_with_chatgpt_auth_tokens and read_codex_api_key_from_env. Internal code had to switch to codex_login::auth::..., so downstream callers using codex_core::auth::... will hit source-level breakage.

Useful? React with 👍 / 👎.

pub use auth::logout;
pub use auth::read_openai_api_key_from_env;
pub use auth::save_auth;
pub use codex_app_server_protocol::AuthMode;
Copy link
Contributor

Choose a reason for hiding this comment

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

P1 Badge Preserve old AuthMode type at re-export boundary

codex-login now re-exports codex_app_server_protocol::AuthMode, which adds ChatgptAuthTokens. Existing callers that exhaustively match codex_core::auth::AuthMode will no longer compile (the repo itself added new match arms). That contradicts the stated goal of keeping existing caller compatibility.

Useful? React with 👍 / 👎.

@aibrahim-oai aibrahim-oai merged commit 2aa4873 into main Mar 20, 2026
33 checks passed
@aibrahim-oai aibrahim-oai deleted the auth-crate-split branch March 20, 2026 01:58
@github-actions github-actions bot locked and limited conversation to collaborators Mar 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants