@@ -36,6 +36,7 @@ use crate::database::{
3636 Database ,
3737 Secret ,
3838} ;
39+ use crate :: util:: system_info:: is_mwinit_available;
3940
4041const AUTH_PORTAL_URL : & str = "https://gamma.app.kiro.aws.dev/signin" ;
4142const DEFAULT_AUTHORIZATION_TIMEOUT : Duration = Duration :: from_secs ( 600 ) ;
@@ -46,13 +47,14 @@ struct AuthPortalCallback {
4647 login_option : String ,
4748 code : Option < String > ,
4849 issuer_uri : Option < String > ,
50+ sso_region : Option < String > ,
4951 state : String ,
5052 path : String ,
5153}
5254
5355pub enum PortalResult {
5456 Social ( SocialProvider ) ,
55- Internal { issuer_uri : String } ,
57+ Internal { issuer_uri : String , idc_region : String } ,
5658}
5759
5860/// Local-only: open unified portal and handle single callback
@@ -80,13 +82,15 @@ pub async fn start_unified_auth(db: &mut Database) -> Result<PortalResult, AuthE
8082 // this base.
8183 let redirect_base = format ! ( "http://localhost:{}" , port) ;
8284 info ! ( %port, %redirect_base, "Unified auth portal listening (base) for callback" ) ;
85+ let is_internal = is_mwinit_available ( ) ;
8386
8487 let auth_url = format ! (
85- "{}?state={}&code_challenge={}&code_challenge_method=S256&redirect_uri={}&redirect_from=kirocli" ,
88+ "{}?state={}&code_challenge={}&code_challenge_method=S256&redirect_uri={}{internal} &redirect_from=kirocli" ,
8689 AUTH_PORTAL_URL ,
8790 state,
8891 challenge,
89- urlencoding:: encode( & redirect_base)
92+ urlencoding:: encode( & redirect_base) ,
93+ internal = if is_internal { "&from_amazon_internal=true" } else { "" } ,
9094 ) ;
9195
9296 crate :: util:: open:: open_url_async ( & auth_url)
@@ -118,8 +122,14 @@ pub async fn start_unified_auth(db: &mut Database) -> Result<PortalResult, AuthE
118122 let issuer_uri = callback
119123 . issuer_uri
120124 . ok_or_else ( || AuthError :: OAuthCustomError ( "Missing issuer_uri for internal auth" . into ( ) ) ) ?;
121- // DO NOT register here. Let caller run start_pkce_authorization(issuer_uri).
122- Ok ( PortalResult :: Internal { issuer_uri } )
125+ let sso_region = callback
126+ . sso_region
127+ . ok_or_else ( || AuthError :: OAuthCustomError ( "Missing sso_region for internal auth" . into ( ) ) ) ?;
128+ // DO NOT register here. Let caller run start_pkce_authorization(issuer_uri, sso_region).
129+ Ok ( PortalResult :: Internal {
130+ issuer_uri,
131+ idc_region : sso_region,
132+ } )
123133 } ,
124134 other => Err ( AuthError :: OAuthCustomError ( format ! ( "Unknown login_option: {}" , other) ) ) ,
125135 }
@@ -192,6 +202,7 @@ impl Service<Request<Incoming>> for AuthCallbackService {
192202 login_option : query_params. get ( "login_option" ) . cloned ( ) . unwrap_or_default ( ) ,
193203 code : query_params. get ( "code" ) . cloned ( ) ,
194204 issuer_uri : query_params. get ( "issuer_uri" ) . cloned ( ) ,
205+ sso_region : query_params. get ( "idc_region" ) . cloned ( ) ,
195206 state : query_params. get ( "state" ) . cloned ( ) . unwrap_or_default ( ) ,
196207 path : path. to_string ( ) ,
197208 } ;
0 commit comments