feat(api): add OAuth token fields and new provider types support

Add support for OAuth-based authentication with access/refresh tokens
and expiration tracking for API keys. Extend provider groups with
static headers configuration and headers profile options.

Changes include:
- Add AccessToken, RefreshToken, ExpiresAt, AccountID, ProjectID to APIKey model
- Add StaticHeaders and HeadersProfile to ProviderGroup model
- Add TokenRefresh configuration for background token management
- Support new provider types: ClaudeCode, Codex, GeminiCLI, Antigravity
- Update sync service to include new fields in provider snapshots
This commit is contained in:
zenfun
2025-12-28 02:49:54 +08:00
parent cca0802620
commit f0fe9f0dad
8 changed files with 132 additions and 22 deletions

View File

@@ -20,6 +20,7 @@ type Config struct {
Quota QuotaConfig
Internal InternalConfig
SyncOutbox SyncOutboxConfig
TokenRefresh TokenRefreshConfig
}
type ServerConfig struct {
@@ -80,6 +81,13 @@ type SyncOutboxConfig struct {
MaxRetries int
}
type TokenRefreshConfig struct {
IntervalSeconds int
RefreshSkewSeconds int
BatchSize int
MaxRetries int
}
func Load() (*Config, error) {
v := viper.New()
@@ -111,6 +119,10 @@ func Load() (*Config, error) {
v.SetDefault("sync_outbox.interval_seconds", 5)
v.SetDefault("sync_outbox.batch_size", 200)
v.SetDefault("sync_outbox.max_retries", 10)
v.SetDefault("token_refresh.interval_seconds", 1800)
v.SetDefault("token_refresh.refresh_skew_seconds", 3000)
v.SetDefault("token_refresh.batch_size", 200)
v.SetDefault("token_refresh.max_retries", 3)
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
v.AutomaticEnv()
@@ -143,6 +155,10 @@ func Load() (*Config, error) {
_ = v.BindEnv("sync_outbox.interval_seconds", "EZ_SYNC_OUTBOX_INTERVAL_SECONDS")
_ = v.BindEnv("sync_outbox.batch_size", "EZ_SYNC_OUTBOX_BATCH_SIZE")
_ = v.BindEnv("sync_outbox.max_retries", "EZ_SYNC_OUTBOX_MAX_RETRIES")
_ = v.BindEnv("token_refresh.interval_seconds", "EZ_TOKEN_REFRESH_INTERVAL_SECONDS")
_ = v.BindEnv("token_refresh.refresh_skew_seconds", "EZ_TOKEN_REFRESH_SKEW_SECONDS")
_ = v.BindEnv("token_refresh.batch_size", "EZ_TOKEN_REFRESH_BATCH_SIZE")
_ = v.BindEnv("token_refresh.max_retries", "EZ_TOKEN_REFRESH_MAX_RETRIES")
if configFile := os.Getenv("EZ_CONFIG_FILE"); configFile != "" {
v.SetConfigFile(configFile)
@@ -208,6 +224,12 @@ func Load() (*Config, error) {
BatchSize: v.GetInt("sync_outbox.batch_size"),
MaxRetries: v.GetInt("sync_outbox.max_retries"),
},
TokenRefresh: TokenRefreshConfig{
IntervalSeconds: v.GetInt("token_refresh.interval_seconds"),
RefreshSkewSeconds: v.GetInt("token_refresh.refresh_skew_seconds"),
BatchSize: v.GetInt("token_refresh.batch_size"),
MaxRetries: v.GetInt("token_refresh.max_retries"),
},
}
return cfg, nil