Merge pull request #15 from StriveMario/feature/fix-kiro-refreshtoken

fix kiro cannot refresh the token
This commit is contained in:
Luis Pater
2025-12-10 00:22:36 +08:00
committed by GitHub
+16 -1
View File
@@ -1272,7 +1272,7 @@ func (w *Watcher) SnapshotCoreAuths() []*coreauth.Auth {
} }
for i := range cfg.KiroKey { for i := range cfg.KiroKey {
kk := cfg.KiroKey[i] kk := cfg.KiroKey[i]
var accessToken, profileArn string var accessToken, profileArn, refreshToken string
// Try to load from token file first // Try to load from token file first
if kk.TokenFile != "" && kAuth != nil { if kk.TokenFile != "" && kAuth != nil {
@@ -1282,6 +1282,7 @@ func (w *Watcher) SnapshotCoreAuths() []*coreauth.Auth {
} else { } else {
accessToken = tokenData.AccessToken accessToken = tokenData.AccessToken
profileArn = tokenData.ProfileArn profileArn = tokenData.ProfileArn
refreshToken = tokenData.RefreshToken
} }
} }
@@ -1292,6 +1293,9 @@ func (w *Watcher) SnapshotCoreAuths() []*coreauth.Auth {
if kk.ProfileArn != "" { if kk.ProfileArn != "" {
profileArn = kk.ProfileArn profileArn = kk.ProfileArn
} }
if kk.RefreshToken != "" {
refreshToken = kk.RefreshToken
}
if accessToken == "" { if accessToken == "" {
log.Warnf("kiro config[%d] missing access_token, skipping", i) log.Warnf("kiro config[%d] missing access_token, skipping", i)
@@ -1313,6 +1317,9 @@ func (w *Watcher) SnapshotCoreAuths() []*coreauth.Auth {
if kk.AgentTaskType != "" { if kk.AgentTaskType != "" {
attrs["agent_task_type"] = kk.AgentTaskType attrs["agent_task_type"] = kk.AgentTaskType
} }
if refreshToken != "" {
attrs["refresh_token"] = refreshToken
}
proxyURL := strings.TrimSpace(kk.ProxyURL) proxyURL := strings.TrimSpace(kk.ProxyURL)
a := &coreauth.Auth{ a := &coreauth.Auth{
ID: id, ID: id,
@@ -1324,6 +1331,14 @@ func (w *Watcher) SnapshotCoreAuths() []*coreauth.Auth {
CreatedAt: now, CreatedAt: now,
UpdatedAt: now, UpdatedAt: now,
} }
if refreshToken != "" {
if a.Metadata == nil {
a.Metadata = make(map[string]any)
}
a.Metadata["refresh_token"] = refreshToken
}
out = append(out, a) out = append(out, a)
} }
for i := range cfg.OpenAICompatibility { for i := range cfg.OpenAICompatibility {