33// params).
44
55use std:: collections:: HashMap ;
6+ use std:: env;
67use std:: time:: Duration ;
78
89use bytes:: Bytes ;
@@ -40,7 +41,7 @@ use crate::{
4041 Result ,
4142} ;
4243
43- const AUTH_PORTAL_URL : & str = "https://app.kiro.dev/signin " ;
44+ const DEFAULT_AUTH_PORTAL_URL : & str = "https://app.kiro.dev" ;
4445const DEFAULT_AUTHORIZATION_TIMEOUT : Duration = Duration :: from_secs ( 600 ) ;
4546
4647#[ derive( Debug , Clone ) ]
@@ -201,10 +202,11 @@ fn format_user_friendly_error(error_code: &str, description: Option<&str>, provi
201202fn build_auth_url ( redirect_base : & str , state : & str , challenge : & str ) -> String {
202203 let is_internal = is_mwinit_available ( ) ;
203204 let internal_param = if is_internal { "&from_amazon_internal=true" } else { "" } ;
205+ let auth_portal_url = get_auth_portal_url ( ) ;
204206
205207 format ! (
206- "{}?state={}&code_challenge={}&code_challenge_method=S256&redirect_uri={}{}&redirect_from=kirocli" ,
207- AUTH_PORTAL_URL ,
208+ "{}/signin ?state={}&code_challenge={}&code_challenge_method=S256&redirect_uri={}{}&redirect_from=kirocli" ,
209+ auth_portal_url ,
208210 state,
209211 challenge,
210212 urlencoding:: encode( redirect_base) ,
@@ -330,6 +332,7 @@ async fn handle_valid_callback(
330332 } ;
331333
332334 let _ = tx. send ( callback. clone ( ) ) . await ;
335+ let auth_portal_url = get_auth_portal_url ( ) ;
333336
334337 // Determine redirect status based on error presence
335338 let redirect_url = if callback. error . is_some ( ) {
@@ -338,12 +341,12 @@ async fn handle_valid_callback(
338341 . as_deref ( )
339342 . unwrap_or ( callback. error . as_deref ( ) . unwrap_or ( "Authentication failed" ) ) ;
340343 format ! (
341- "{}?auth_status=error&redirect_from=kirocli&error_message={}" ,
342- AUTH_PORTAL_URL ,
344+ "{}/signin ?auth_status=error&redirect_from=kirocli&error_message={}" ,
345+ auth_portal_url ,
343346 urlencoding:: encode( error_msg)
344347 )
345348 } else {
346- format ! ( "{}?auth_status=success&redirect_from=kirocli" , AUTH_PORTAL_URL )
349+ format ! ( "{}?auth_status=success&redirect_from=kirocli" , auth_portal_url )
347350 } ;
348351
349352 Response :: builder ( )
@@ -356,10 +359,11 @@ async fn handle_valid_callback(
356359
357360async fn handle_invalid_callback ( path : & str ) -> Result < Response < Full < Bytes > > > {
358361 debug ! ( "Invalid callback path: {}" , path) ;
362+ let auth_portal_url = get_auth_portal_url ( ) ;
359363
360364 let redirect_url = format ! (
361- "{}?auth_status=error&redirect_from=kirocli&error_message={}" ,
362- AUTH_PORTAL_URL ,
365+ "{}/signin ?auth_status=error&redirect_from=kirocli&error_message={}" ,
366+ auth_portal_url ,
363367 urlencoding:: encode( "Invalid callback path" )
364368 ) ;
365369
@@ -382,3 +386,7 @@ async fn bind_allowed_port(ports: &[u16]) -> Result<TcpListener> {
382386 "All callback ports are in use. Please close some applications and try again." . to_string ( ) ,
383387 ) )
384388}
389+
390+ fn get_auth_portal_url ( ) -> String {
391+ env:: var ( "KIRO_AUTH_PORTAL_URL" ) . unwrap_or_else ( |_| DEFAULT_AUTH_PORTAL_URL . to_string ( ) )
392+ }
0 commit comments