11//! Unified auth portal integration for streamlined authentication
22//! Handles callbacks from https://app.kiro.dev/signin
33
4+ use std:: env;
45use std:: time:: Duration ;
56
67use bytes:: Bytes ;
@@ -35,7 +36,7 @@ use crate::auth::social::{
3536use crate :: database:: Database ;
3637use crate :: util:: system_info:: is_mwinit_available;
3738
38- const AUTH_PORTAL_URL : & str = "https://app.kiro.dev/signin " ;
39+ const DEFAULT_AUTH_PORTAL_URL : & str = "https://app.kiro.dev" ;
3940const DEFAULT_AUTHORIZATION_TIMEOUT : Duration = Duration :: from_secs ( 600 ) ;
4041
4142#[ derive( Debug , Clone ) ]
@@ -140,10 +141,11 @@ fn format_user_friendly_error(error_code: &str, description: Option<&str>, provi
140141fn build_auth_url ( redirect_base : & str , state : & str , challenge : & str ) -> String {
141142 let is_internal = is_mwinit_available ( ) ;
142143 let internal_param = if is_internal { "&from_amazon_internal=true" } else { "" } ;
144+ let auth_portal_url = get_auth_portal_url ( ) ;
143145
144146 format ! (
145- "{}?state={}&code_challenge={}&code_challenge_method=S256&redirect_uri={}{}&redirect_from=kirocli" ,
146- AUTH_PORTAL_URL ,
147+ "{}/signin ?state={}&code_challenge={}&code_challenge_method=S256&redirect_uri={}{}&redirect_from=kirocli" ,
148+ auth_portal_url ,
147149 state,
148150 challenge,
149151 urlencoding:: encode( redirect_base) ,
@@ -354,8 +356,8 @@ async fn handle_invalid_callback(path: &str) -> Result<Response<Full<Bytes>>, Au
354356
355357/// Build a redirect response to the auth portal
356358fn build_redirect_response ( status : & str , error_message : Option < & str > ) -> Result < Response < Full < Bytes > > , AuthError > {
357- let mut redirect_url = format ! ( "{AUTH_PORTAL_URL}?auth_status={status}&redirect_from=kirocli" ) ;
358-
359+ let auth_portal_url = get_auth_portal_url ( ) ;
360+ let mut redirect_url = format ! ( "{auth_portal_url}/signin?auth_status={status}&redirect_from=kirocli" ) ;
359361 if let Some ( msg) = error_message {
360362 redirect_url. push_str ( & format ! ( "&error_message={}" , urlencoding:: encode( msg) ) ) ;
361363 }
@@ -382,3 +384,7 @@ async fn bind_allowed_port(ports: &[u16]) -> Result<TcpListener, AuthError> {
382384 "All callback ports are in use. Please close some applications and try again." . into ( ) ,
383385 ) )
384386}
387+
388+ fn get_auth_portal_url ( ) -> String {
389+ env:: var ( "KIRO_AUTH_PORTAL_URL" ) . unwrap_or_else ( |_| DEFAULT_AUTH_PORTAL_URL . to_string ( ) )
390+ }
0 commit comments