11use codex_app_server_protocol:: AuthMode ;
22use codex_common:: CliConfigOverrides ;
33use codex_core:: CodexAuth ;
4+ use codex_core:: auth:: AuthCredentialsStoreMode ;
45use codex_core:: auth:: CLIENT_ID ;
56use codex_core:: auth:: login_with_api_key;
67use codex_core:: auth:: logout;
@@ -17,11 +18,13 @@ use std::path::PathBuf;
1718pub async fn login_with_chatgpt (
1819 codex_home : PathBuf ,
1920 forced_chatgpt_workspace_id : Option < String > ,
21+ cli_auth_credentials_store_mode : AuthCredentialsStoreMode ,
2022) -> std:: io:: Result < ( ) > {
2123 let opts = ServerOptions :: new (
2224 codex_home,
2325 CLIENT_ID . to_string ( ) ,
2426 forced_chatgpt_workspace_id,
27+ cli_auth_credentials_store_mode,
2528 ) ;
2629 let server = run_login_server ( opts) ?;
2730
@@ -43,7 +46,13 @@ pub async fn run_login_with_chatgpt(cli_config_overrides: CliConfigOverrides) ->
4346
4447 let forced_chatgpt_workspace_id = config. forced_chatgpt_workspace_id . clone ( ) ;
4548
46- match login_with_chatgpt ( config. codex_home , forced_chatgpt_workspace_id) . await {
49+ match login_with_chatgpt (
50+ config. codex_home ,
51+ forced_chatgpt_workspace_id,
52+ config. cli_auth_credentials_store_mode ,
53+ )
54+ . await
55+ {
4756 Ok ( _) => {
4857 eprintln ! ( "Successfully logged in" ) ;
4958 std:: process:: exit ( 0 ) ;
@@ -66,7 +75,11 @@ pub async fn run_login_with_api_key(
6675 std:: process:: exit ( 1 ) ;
6776 }
6877
69- match login_with_api_key ( & config. codex_home , & api_key) {
78+ match login_with_api_key (
79+ & config. codex_home ,
80+ & api_key,
81+ config. cli_auth_credentials_store_mode ,
82+ ) {
7083 Ok ( _) => {
7184 eprintln ! ( "Successfully logged in" ) ;
7285 std:: process:: exit ( 0 ) ;
@@ -121,6 +134,7 @@ pub async fn run_login_with_device_code(
121134 config. codex_home ,
122135 client_id. unwrap_or ( CLIENT_ID . to_string ( ) ) ,
123136 forced_chatgpt_workspace_id,
137+ config. cli_auth_credentials_store_mode ,
124138 ) ;
125139 if let Some ( iss) = issuer_base_url {
126140 opts. issuer = iss;
@@ -140,7 +154,7 @@ pub async fn run_login_with_device_code(
140154pub async fn run_login_status ( cli_config_overrides : CliConfigOverrides ) -> ! {
141155 let config = load_config_or_exit ( cli_config_overrides) . await ;
142156
143- match CodexAuth :: from_auth_storage ( & config. codex_home ) {
157+ match CodexAuth :: from_auth_storage ( & config. codex_home , config . cli_auth_credentials_store_mode ) {
144158 Ok ( Some ( auth) ) => match auth. mode {
145159 AuthMode :: ApiKey => match auth. get_token ( ) . await {
146160 Ok ( api_key) => {
@@ -171,7 +185,7 @@ pub async fn run_login_status(cli_config_overrides: CliConfigOverrides) -> ! {
171185pub async fn run_logout ( cli_config_overrides : CliConfigOverrides ) -> ! {
172186 let config = load_config_or_exit ( cli_config_overrides) . await ;
173187
174- match logout ( & config. codex_home ) {
188+ match logout ( & config. codex_home , config . cli_auth_credentials_store_mode ) {
175189 Ok ( true ) => {
176190 eprintln ! ( "Successfully logged out" ) ;
177191 std:: process:: exit ( 0 ) ;
0 commit comments