This PR does the following: * Adds the ability to paste or type an API key. * Removes the `preferred_auth_method` config option. The last login method is always persisted in auth.json, so this isn't needed. * If OPENAI_API_KEY env variable is defined, the value is used to prepopulate the new UI. The env variable is otherwise ignored by the CLI. * Adds a new MCP server entry point "login_api_key" so we can implement this same API key behavior for the VS Code extension. <img width="473" height="140" alt="Screenshot 2025-09-04 at 3 51 04 PM" src="https://github.com/user-attachments/assets/c11bbd5b-8a4d-4d71-90fd-34130460f9d9" /> <img width="726" height="254" alt="Screenshot 2025-09-04 at 3 51 32 PM" src="https://github.com/user-attachments/assets/6cc76b34-309a-4387-acbc-15ee5c756db9" />
29 lines
816 B
Rust
29 lines
816 B
Rust
use codex_core::CodexAuth;
|
|
use std::path::Path;
|
|
use std::sync::LazyLock;
|
|
use std::sync::RwLock;
|
|
|
|
use codex_core::token_data::TokenData;
|
|
|
|
static CHATGPT_TOKEN: LazyLock<RwLock<Option<TokenData>>> = LazyLock::new(|| RwLock::new(None));
|
|
|
|
pub fn get_chatgpt_token_data() -> Option<TokenData> {
|
|
CHATGPT_TOKEN.read().ok()?.clone()
|
|
}
|
|
|
|
pub fn set_chatgpt_token_data(value: TokenData) {
|
|
if let Ok(mut guard) = CHATGPT_TOKEN.write() {
|
|
*guard = Some(value);
|
|
}
|
|
}
|
|
|
|
/// Initialize the ChatGPT token from auth.json file
|
|
pub async fn init_chatgpt_token_from_auth(codex_home: &Path) -> std::io::Result<()> {
|
|
let auth = CodexAuth::from_codex_home(codex_home)?;
|
|
if let Some(auth) = auth {
|
|
let token_data = auth.get_token_data().await?;
|
|
set_chatgpt_token_data(token_data);
|
|
}
|
|
Ok(())
|
|
}
|