Skip to content

Commit a77bc8b

Browse files
evanliu048kkashilk
authored andcommitted
add endpoint override (#848)
1 parent 5848fbd commit a77bc8b

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

crates/chat-cli/src/auth/portal.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Unified auth portal integration for streamlined authentication
22
//! Handles callbacks from https://app.kiro.dev/signin
33
4+
use std::env;
45
use std::time::Duration;
56

67
use bytes::Bytes;
@@ -35,7 +36,7 @@ use crate::auth::social::{
3536
use crate::database::Database;
3637
use 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";
3940
const DEFAULT_AUTHORIZATION_TIMEOUT: Duration = Duration::from_secs(600);
4041

4142
#[derive(Debug, Clone)]
@@ -143,10 +144,11 @@ fn format_user_friendly_error(error_code: &str, description: Option<&str>, provi
143144
fn build_auth_url(redirect_base: &str, state: &str, challenge: &str) -> String {
144145
let is_internal = is_mwinit_available();
145146
let internal_param = if is_internal { "&from_amazon_internal=true" } else { "" };
147+
let auth_portal_url = get_auth_portal_url();
146148

147149
format!(
148-
"{}?state={}&code_challenge={}&code_challenge_method=S256&redirect_uri={}{}&redirect_from=kirocli",
149-
AUTH_PORTAL_URL,
150+
"{}/signin?state={}&code_challenge={}&code_challenge_method=S256&redirect_uri={}{}&redirect_from=kirocli",
151+
auth_portal_url,
150152
state,
151153
challenge,
152154
urlencoding::encode(redirect_base),
@@ -357,7 +359,11 @@ async fn handle_invalid_callback(path: &str) -> Result<Response<Full<Bytes>>, Au
357359

358360
/// Build a redirect response to the auth portal
359361
fn build_redirect_response(status: &str, error_message: Option<&str>) -> Result<Response<Full<Bytes>>, AuthError> {
360-
let mut redirect_url = format!("{}?auth_status={}&redirect_from=kirocli", AUTH_PORTAL_URL, status);
362+
let auth_portal_url = get_auth_portal_url();
363+
let mut redirect_url = format!(
364+
"{}/signin?auth_status={}&redirect_from=kirocli",
365+
auth_portal_url, status
366+
);
361367

362368
if let Some(msg) = error_message {
363369
redirect_url.push_str(&format!("&error_message={}", urlencoding::encode(msg)));
@@ -385,3 +391,7 @@ async fn bind_allowed_port(ports: &[u16]) -> Result<TcpListener, AuthError> {
385391
"All callback ports are in use. Please close some applications and try again.".into(),
386392
))
387393
}
394+
395+
fn get_auth_portal_url() -> String {
396+
env::var("KIRO_AUTH_PORTAL_URL").unwrap_or_else(|_| DEFAULT_AUTH_PORTAL_URL.to_string())
397+
}

crates/fig_auth/src/portal.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// params).
44

55
use std::collections::HashMap;
6+
use std::env;
67
use std::time::Duration;
78

89
use 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";
4445
const 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
201202
fn 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

357360
async 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

Comments
 (0)