mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-03-30 04:03:18 +00:00
- Introduce Provider interface pattern for standard OAuth protocols - Create unified controller/oauth.go with common OAuth logic - Add OAuthError type for translatable error messages - Add i18n keys and translations (zh/en) for OAuth messages - Use common.ApiErrorI18n/ApiSuccessI18n for consistent responses - Preserve backward compatibility for existing routes and data
44 lines
869 B
Go
44 lines
869 B
Go
package oauth
|
|
|
|
import (
|
|
"sync"
|
|
)
|
|
|
|
var (
|
|
providers = make(map[string]Provider)
|
|
mu sync.RWMutex
|
|
)
|
|
|
|
// Register registers an OAuth provider with the given name
|
|
func Register(name string, provider Provider) {
|
|
mu.Lock()
|
|
defer mu.Unlock()
|
|
providers[name] = provider
|
|
}
|
|
|
|
// GetProvider returns the OAuth provider for the given name
|
|
func GetProvider(name string) Provider {
|
|
mu.RLock()
|
|
defer mu.RUnlock()
|
|
return providers[name]
|
|
}
|
|
|
|
// GetAllProviders returns all registered OAuth providers
|
|
func GetAllProviders() map[string]Provider {
|
|
mu.RLock()
|
|
defer mu.RUnlock()
|
|
result := make(map[string]Provider, len(providers))
|
|
for k, v := range providers {
|
|
result[k] = v
|
|
}
|
|
return result
|
|
}
|
|
|
|
// IsProviderRegistered checks if a provider is registered
|
|
func IsProviderRegistered(name string) bool {
|
|
mu.RLock()
|
|
defer mu.RUnlock()
|
|
_, ok := providers[name]
|
|
return ok
|
|
}
|