fix(认证): 修复 OAuth token 缓存失效与 401 处理
新增 token 缓存失效接口并在刷新后清理 401 限流支持自定义规则与可配置冷却时间 补齐缓存失效与 401 处理测试 测试: make test
This commit is contained in:
35
backend/internal/service/token_cache_invalidator.go
Normal file
35
backend/internal/service/token_cache_invalidator.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package service
|
||||
|
||||
import "context"
|
||||
|
||||
type TokenCacheInvalidator interface {
|
||||
InvalidateToken(ctx context.Context, account *Account) error
|
||||
}
|
||||
|
||||
type CompositeTokenCacheInvalidator struct {
|
||||
geminiCache GeminiTokenCache
|
||||
}
|
||||
|
||||
func NewCompositeTokenCacheInvalidator(geminiCache GeminiTokenCache) *CompositeTokenCacheInvalidator {
|
||||
return &CompositeTokenCacheInvalidator{
|
||||
geminiCache: geminiCache,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *CompositeTokenCacheInvalidator) InvalidateToken(ctx context.Context, account *Account) error {
|
||||
if c == nil || c.geminiCache == nil || account == nil {
|
||||
return nil
|
||||
}
|
||||
if account.Type != AccountTypeOAuth {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch account.Platform {
|
||||
case PlatformGemini:
|
||||
return c.geminiCache.DeleteAccessToken(ctx, GeminiTokenCacheKey(account))
|
||||
case PlatformAntigravity:
|
||||
return c.geminiCache.DeleteAccessToken(ctx, AntigravityTokenCacheKey(account))
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user