feat(backend): 完善 Gemini OAuth Token 处理

- 修复 account_handler 中 token 字段类型转换(int64 转 string)
- 增强 Account.GetCredential 支持多种数值类型(float64, int, json.Number 等)
- 添加 Account.IsGemini() 方法用于平台判断
- 优化 refresh_token 和 scope 的空值处理
This commit is contained in:
ianshaw
2025-12-25 08:39:32 -08:00
parent e36fb98fb9
commit 03a8ae62e5
3 changed files with 57 additions and 15 deletions

View File

@@ -139,7 +139,8 @@ func (s *GeminiOAuthService) ExchangeCode(ctx context.Context, input *GeminiExch
}
s.sessionStore.Delete(input.SessionID)
expiresAt := time.Now().Unix() + tokenResp.ExpiresIn
// 计算过期时间时减去 5 分钟安全时间窗口,考虑网络延迟和时钟偏差
expiresAt := time.Now().Unix() + tokenResp.ExpiresIn - 300
projectID, _ := s.fetchProjectID(ctx, tokenResp.AccessToken, proxyURL)
return &GeminiTokenInfo{
@@ -167,7 +168,8 @@ func (s *GeminiOAuthService) RefreshToken(ctx context.Context, refreshToken, pro
tokenResp, err := s.oauthClient.RefreshToken(ctx, refreshToken, proxyURL)
if err == nil {
expiresAt := time.Now().Unix() + tokenResp.ExpiresIn
// 计算过期时间时减去 5 分钟安全时间窗口,考虑网络延迟和时钟偏差
expiresAt := time.Now().Unix() + tokenResp.ExpiresIn - 300
return &GeminiTokenInfo{
AccessToken: tokenResp.AccessToken,
RefreshToken: tokenResp.RefreshToken,