@@ -1230,110 +1230,6 @@ async fn run_login_oauth(base: &BaseArgs, args: AuthLoginArgs) -> Result<()> {
12301230 Ok ( ( ) )
12311231}
12321232
1233- pub ( crate ) async fn login_interactive_oauth ( base : & mut BaseArgs ) -> Result < String > {
1234- let api_url = base
1235- . api_url
1236- . clone ( )
1237- . unwrap_or_else ( || DEFAULT_API_URL . to_string ( ) ) ;
1238- let app_url = base
1239- . app_url
1240- . clone ( )
1241- . unwrap_or_else ( || DEFAULT_APP_URL . to_string ( ) ) ;
1242- let provisional_profile = base
1243- . profile
1244- . as_deref ( )
1245- . map ( str:: trim)
1246- . filter ( |name| !name. is_empty ( ) )
1247- . unwrap_or ( "default" ) ;
1248- let client_id = default_oauth_client_id ( provisional_profile) ;
1249-
1250- let ( pkce_challenge, pkce_verifier) = PkceCodeChallenge :: new_random_sha256 ( ) ;
1251- let state = generate_random_token ( 32 ) ?;
1252-
1253- let listener = TcpListener :: bind ( ( "127.0.0.1" , 0 ) )
1254- . await
1255- . context ( "failed to bind oauth callback listener" ) ?;
1256- let callback_port = listener
1257- . local_addr ( )
1258- . context ( "failed to read callback listener address" ) ?
1259- . port ( ) ;
1260- let redirect_uri = format ! ( "http://127.0.0.1:{callback_port}/callback" ) ;
1261- let oauth_client = build_oauth_client ( & api_url, & client_id, Some ( & redirect_uri) ) ?;
1262- let ( authorize_url, _) = oauth_client
1263- . authorize_url ( || CsrfToken :: new ( state. clone ( ) ) )
1264- . add_scope ( Scope :: new ( OAUTH_SCOPE . to_string ( ) ) )
1265- . set_pkce_challenge ( pkce_challenge)
1266- . url ( ) ;
1267- let authorize_url = authorize_url. to_string ( ) ;
1268-
1269- let _ = open:: that ( & authorize_url) ;
1270- eprintln ! ( "Complete authorization in your browser." ) ;
1271- eprintln ! ( ) ;
1272- eprintln ! ( "{}" , dialoguer:: console:: style( & authorize_url) . dim( ) ) ;
1273- eprintln ! ( ) ;
1274-
1275- let callback =
1276- collect_oauth_callback ( listener, is_ssh_session ( ) , explicitly_quiet ( base) ) . await ?;
1277- if let Some ( error) = callback. error {
1278- bail ! ( "oauth authorization failed: {error}" ) ;
1279- }
1280- let auth_code = callback
1281- . code
1282- . ok_or_else ( || anyhow:: anyhow!( "no authorization code received" ) ) ?;
1283- if callback. state . is_none ( ) {
1284- bail ! ( "oauth callback missing state; paste the full callback URL (or code=...&state=...)" ) ;
1285- }
1286- if callback. state . as_deref ( ) != Some ( state. as_str ( ) ) {
1287- bail ! ( "oauth state mismatch; please try again" ) ;
1288- }
1289-
1290- let oauth_tokens = exchange_oauth_authorization_code (
1291- & api_url,
1292- & client_id,
1293- & redirect_uri,
1294- & auth_code,
1295- pkce_verifier,
1296- )
1297- . await ?;
1298-
1299- let login_orgs = fetch_login_orgs ( & oauth_tokens. access_token , & app_url) . await ?;
1300- let selected_org = select_login_org (
1301- login_orgs. clone ( ) ,
1302- base. org_name . as_deref ( ) ,
1303- ui:: can_prompt ( ) ,
1304- false ,
1305- false ,
1306- explicitly_quiet ( base) ,
1307- ) ?;
1308- let selected_api_url =
1309- resolve_profile_api_url ( base. api_url . clone ( ) , selected_org. as_ref ( ) , & login_orgs) ?;
1310- let store = load_auth_store ( ) ?;
1311- let jwt_id = decode_jwt_identity ( & oauth_tokens. access_token ) ;
1312- let ( profile_name, should_confirm_overwrite) = resolve_oauth_login_profile_name (
1313- base. profile . as_deref ( ) ,
1314- selected_org. as_ref ( ) . map ( |org| org. name . as_str ( ) ) ,
1315- & selected_api_url,
1316- & app_url,
1317- & jwt_id,
1318- & store,
1319- ) ?;
1320- if should_confirm_overwrite {
1321- confirm_profile_overwrite ( & profile_name) ?;
1322- }
1323-
1324- commit_oauth_profile (
1325- & profile_name,
1326- & oauth_tokens,
1327- selected_api_url,
1328- app_url,
1329- client_id,
1330- selected_org. as_ref ( ) . map ( |org| org. name . clone ( ) ) ,
1331- ) ?;
1332-
1333- base. profile = Some ( profile_name. clone ( ) ) ;
1334- Ok ( profile_name)
1335- }
1336-
13371233pub ( crate ) fn commit_api_key_profile (
13381234 profile_name : & str ,
13391235 api_key : & str ,
0 commit comments