mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-02 20:40:52 +08:00
- Replaced `TokenRecord` with `coreauth.Auth` for centralized and consistent authentication data structures. - Migrated `TokenStore` interface to `coreauth.Store` for alignment with core CLIProxy authentication. - Updated related login methods, token persistence logic, and file storage handling to use the new `coreauth.Auth` model.
36 lines
697 B
Go
36 lines
697 B
Go
package auth
|
|
|
|
import (
|
|
"sync"
|
|
|
|
coreauth "github.com/router-for-me/CLIProxyAPI/v6/sdk/cliproxy/auth"
|
|
)
|
|
|
|
var (
|
|
storeMu sync.RWMutex
|
|
registeredStore coreauth.Store
|
|
)
|
|
|
|
// RegisterTokenStore sets the global token store used by the authentication helpers.
|
|
func RegisterTokenStore(store coreauth.Store) {
|
|
storeMu.Lock()
|
|
registeredStore = store
|
|
storeMu.Unlock()
|
|
}
|
|
|
|
// GetTokenStore returns the globally registered token store.
|
|
func GetTokenStore() coreauth.Store {
|
|
storeMu.RLock()
|
|
s := registeredStore
|
|
storeMu.RUnlock()
|
|
if s != nil {
|
|
return s
|
|
}
|
|
storeMu.Lock()
|
|
defer storeMu.Unlock()
|
|
if registeredStore == nil {
|
|
registeredStore = NewFileTokenStore()
|
|
}
|
|
return registeredStore
|
|
}
|