"use client"; import { useState } from "react"; import PropTypes from "prop-types"; import { Modal, Button, Input } from "@/shared/components"; import { useCopyToClipboard } from "@/shared/hooks/useCopyToClipboard"; /** * Kiro Auth Method Selection Modal * Allows user to choose between multiple Kiro authentication methods: * 1. AWS Builder ID (Device Code) * 2. AWS IAM Identity Center/IDC (Device Code with custom startUrl/region) * 3. Google Social Login (Manual callback) * 4. GitHub Social Login (Manual callback) * 5. Import Token (Paste refresh token) */ export default function KiroAuthModal({ isOpen, onMethodSelect, onClose }) { const [selectedMethod, setSelectedMethod] = useState(null); const [idcStartUrl, setIdcStartUrl] = useState(""); const [idcRegion, setIdcRegion] = useState("us-east-1"); const [refreshToken, setRefreshToken] = useState(""); const [error, setError] = useState(null); const [importing, setImporting] = useState(false); const { copied, copy } = useCopyToClipboard(); const handleMethodSelect = (method) => { setSelectedMethod(method); setError(null); }; const handleBack = () => { setSelectedMethod(null); setError(null); }; const handleImportToken = async () => { if (!refreshToken.trim()) { setError("Please enter a refresh token"); return; } setImporting(true); setError(null); try { const res = await fetch("/api/oauth/kiro/import", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ refreshToken: refreshToken.trim() }), }); const data = await res.json(); if (!res.ok) { throw new Error(data.error || "Import failed"); } // Success - close modal onClose(); } catch (err) { setError(err.message); } finally { setImporting(false); } }; const handleIdcContinue = () => { if (!idcStartUrl.trim()) { setError("Please enter your IDC start URL"); return; } onMethodSelect("idc", { startUrl: idcStartUrl.trim(), region: idcRegion }); }; const handleSocialLogin = (provider) => { onMethodSelect("social", { provider }); }; return (
{/* Method Selection */} {!selectedMethod && (

Choose your authentication method:

{/* AWS Builder ID */} {/* AWS IAM Identity Center (IDC) - HIDDEN */} {/* Google Social Login - HIDDEN */} {/* GitHub Social Login - HIDDEN */} {/* Import Token */}
)} {/* IDC Configuration */} {selectedMethod === "idc" && (
setIdcStartUrl(e.target.value)} placeholder="https://your-org.awsapps.com/start" className="font-mono text-sm" />

Your organization's AWS IAM Identity Center URL

setIdcRegion(e.target.value)} placeholder="us-east-1" className="font-mono text-sm" />

AWS region for your Identity Center (default: us-east-1)

{error && (

{error}

)}
)} {/* Social Login Info (Google) */} {selectedMethod === "social-google" && (
info

Manual Callback Required

After login, you'll need to copy the callback URL from your browser and paste it back here.

)} {/* Social Login Info (GitHub) */} {selectedMethod === "social-github" && (
info

Manual Callback Required

After login, you'll need to copy the callback URL from your browser and paste it back here.

)} {/* Import Token */} {selectedMethod === "import" && (

💡 Please login to Kiro IDE first.

setRefreshToken(e.target.value)} placeholder="aorAAAAAG..." className="font-mono text-sm" type="password" />

Find it in Kiro IDE at: ~/.aws/sso/cache/kiro-auth-token.json

{error && (

{error}

)}
)}
); } KiroAuthModal.propTypes = { isOpen: PropTypes.bool.isRequired, onMethodSelect: PropTypes.func.isRequired, onClose: PropTypes.func.isRequired, };