Skip to content

Commit 000c0ff

Browse files
committed
add func to update auth url
1 parent 3cd8474 commit 000c0ff

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
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+
}

0 commit comments

Comments
 (0)