Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,5 @@ CHANGELOG.ignore.md
__pycache__/
*.pyc

.cargo/

1 change: 1 addition & 0 deletions codex-rs/app-server-protocol/src/protocol/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ impl GitSha {
pub enum AuthMode {
ApiKey,
ChatGPT,
ProviderOAuth,
}

/// Generates an `enum ClientRequest` where each variant is a request that the
Expand Down
4 changes: 4 additions & 0 deletions codex-rs/app-server-protocol/src/protocol/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,10 @@ pub enum Account {
#[serde(rename = "chatgpt", rename_all = "camelCase")]
#[ts(rename = "chatgpt", rename_all = "camelCase")]
Chatgpt { email: String, plan_type: PlanType },

#[serde(rename = "providerOauth", rename_all = "camelCase")]
#[ts(rename = "providerOauth", rename_all = "camelCase")]
ProviderOauth {},
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
Expand Down
1 change: 1 addition & 0 deletions codex-rs/app-server/src/codex_message_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,7 @@ impl CodexMessageProcessor {
}
}
}
AuthMode::ProviderOAuth => Account::ProviderOauth {},
}),
None => None,
};
Expand Down
1 change: 1 addition & 0 deletions codex-rs/app-server/src/message_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ impl MessageProcessor {
config.codex_home.clone(),
false,
config.cli_auth_credentials_store_mode,
config.model_provider.clone(),
);
let conversation_manager = Arc::new(ConversationManager::new(
auth_manager.clone(),
Expand Down
2 changes: 2 additions & 0 deletions codex-rs/app-server/tests/common/auth_fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use base64::Engine;
use base64::engine::general_purpose::URL_SAFE_NO_PAD;
use chrono::DateTime;
use chrono::Utc;
use codex_core::CHATGPT_AUTH_MODE;
use codex_core::auth::AuthCredentialsStoreMode;
use codex_core::auth::AuthDotJson;
use codex_core::auth::save_auth;
Expand Down Expand Up @@ -129,6 +130,7 @@ pub fn write_chatgpt_auth(
openai_api_key: None,
tokens: Some(tokens),
last_refresh,
auth_mode: Some(CHATGPT_AUTH_MODE.to_string()),
};

save_auth(codex_home, &auth, cli_auth_credentials_store_mode).context("write auth.json")
Expand Down
2 changes: 1 addition & 1 deletion codex-rs/chatgpt/src/chatgpt_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub async fn init_chatgpt_token_from_auth(
codex_home: &Path,
auth_credentials_store_mode: AuthCredentialsStoreMode,
) -> std::io::Result<()> {
let auth = CodexAuth::from_auth_storage(codex_home, auth_credentials_store_mode)?;
let auth = CodexAuth::from_auth_storage(codex_home, auth_credentials_store_mode, None)?;
if let Some(auth) = auth {
let token_data = auth.get_token_data().await?;
set_chatgpt_token_data(token_data);
Expand Down
10 changes: 9 additions & 1 deletion codex-rs/cli/src/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@ pub async fn run_login_with_device_code(
pub async fn run_login_status(cli_config_overrides: CliConfigOverrides) -> ! {
let config = load_config_or_exit(cli_config_overrides).await;

match CodexAuth::from_auth_storage(&config.codex_home, config.cli_auth_credentials_store_mode) {
match CodexAuth::from_auth_storage(
&config.codex_home,
config.cli_auth_credentials_store_mode,
Some(config.model_provider.clone()),
) {
Ok(Some(auth)) => match auth.mode {
AuthMode::ApiKey => match auth.get_token().await {
Ok(api_key) => {
Expand All @@ -169,6 +173,10 @@ pub async fn run_login_status(cli_config_overrides: CliConfigOverrides) -> ! {
eprintln!("Logged in using ChatGPT");
std::process::exit(0);
}
AuthMode::ProviderOAuth => {
eprintln!("Logged in using ProviderOAuth");
std::process::exit(0);
}
},
Ok(None) => {
eprintln!("Not logged in");
Expand Down
1 change: 1 addition & 0 deletions codex-rs/cloud-tasks/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ pub async fn load_auth_manager() -> Option<AuthManager> {
config.codex_home,
false,
config.cli_auth_credentials_store_mode,
config.model_provider,
))
}

Expand Down
7 changes: 7 additions & 0 deletions codex-rs/codex-client/src/default_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ impl CodexRequestBuilder {
self.map(|builder| builder.json(value))
}

pub fn form<T>(self, form: &T) -> Self
where
T: Serialize,
{
self.map(|builder| builder.form(form))
}

pub async fn send(self) -> Result<Response, reqwest::Error> {
let headers = trace_headers();

Expand Down
Loading
Loading