feat: proactive token refresh 10 minutes before expiry

Amp-Thread-ID: https://ampcode.com/threads/T-019bd618-7e42-715a-960d-dd45425851e3
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
781456868@qq.com
2026-01-19 20:09:38 +08:00
parent 87edc6f35e
commit f87fe0a0e8
2 changed files with 20 additions and 11 deletions
+10 -10
View File
@@ -52,9 +52,9 @@ func (a *KiroAuthenticator) Provider() string {
}
// RefreshLead indicates how soon before expiry a refresh should be attempted.
// Set to 5 minutes to match Antigravity and avoid frequent refresh checks while still ensuring timely token refresh.
// Set to 10 minutes for proactive refresh before token expiry.
func (a *KiroAuthenticator) RefreshLead() *time.Duration {
d := 5 * time.Minute
d := 10 * time.Minute
return &d
}
@@ -126,8 +126,8 @@ func (a *KiroAuthenticator) createAuthRecord(tokenData *kiroauth.KiroTokenData,
UpdatedAt: now,
Metadata: metadata,
Attributes: attributes,
// NextRefreshAfter is aligned with RefreshLead (5min)
NextRefreshAfter: expiresAt.Add(-5 * time.Minute),
// NextRefreshAfter: 10 minutes before expiry
NextRefreshAfter: expiresAt.Add(-10 * time.Minute),
}
if tokenData.Email != "" {
@@ -208,8 +208,8 @@ func (a *KiroAuthenticator) LoginWithAuthCode(ctx context.Context, cfg *config.C
"source": "aws-builder-id-authcode",
"email": tokenData.Email,
},
// NextRefreshAfter is aligned with RefreshLead (5min)
NextRefreshAfter: expiresAt.Add(-5 * time.Minute),
// NextRefreshAfter: 10 minutes before expiry
NextRefreshAfter: expiresAt.Add(-10 * time.Minute),
}
if tokenData.Email != "" {
@@ -292,8 +292,8 @@ func (a *KiroAuthenticator) ImportFromKiroIDE(ctx context.Context, cfg *config.C
"email": tokenData.Email,
"region": tokenData.Region,
},
// NextRefreshAfter is aligned with RefreshLead (5min)
NextRefreshAfter: expiresAt.Add(-5 * time.Minute),
// NextRefreshAfter: 10 minutes before expiry
NextRefreshAfter: expiresAt.Add(-10 * time.Minute),
}
// Display the email if extracted
@@ -361,8 +361,8 @@ func (a *KiroAuthenticator) Refresh(ctx context.Context, cfg *config.Config, aut
updated.Metadata["refresh_token"] = tokenData.RefreshToken
updated.Metadata["expires_at"] = tokenData.ExpiresAt
updated.Metadata["last_refresh"] = now.Format(time.RFC3339) // For double-check optimization
// NextRefreshAfter is aligned with RefreshLead (5min)
updated.NextRefreshAfter = expiresAt.Add(-5 * time.Minute)
// NextRefreshAfter: 10 minutes before expiry
updated.NextRefreshAfter = expiresAt.Add(-10 * time.Minute)
return updated, nil
}