Documentation
¶
Overview ¶
Package auth provides shared token sources for HTTP-based API clients (embeddings, LLM chat completions, etc.) that authenticate with CliProxyAPI-issued OAuth tokens or static API keys.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CliProxyFile ¶
type CliProxyFile struct {
// contains filtered or unexported fields
}
CliProxyFile reads a CliProxyAPI OAuth JSON file on demand and caches the access_token for a short TTL (default 5 minutes). When the cache expires the file is re-read, which allows the credential file to be rotated by an external refresh daemon without restarting the application.
func NewCliProxyFile ¶
func NewCliProxyFile(path string) *CliProxyFile
NewCliProxyFile returns a CliProxyFile that reads tokens from path.
func (*CliProxyFile) Token ¶
func (c *CliProxyFile) Token() (string, error)
Token implements TokenSource. It returns the cached access_token when it is still valid, otherwise re-reads the file from disk.
type StaticToken ¶
type StaticToken string
StaticToken returns the same string every call.
func (StaticToken) Token ¶
func (s StaticToken) Token() (string, error)
Token implements TokenSource.
type TokenSource ¶
TokenSource abstracts the means of obtaining a Bearer token. Implementations may return a cached token or read fresh from disk.
func Resolve ¶
func Resolve(staticKey, cliProxyPath string) TokenSource
Resolve constructs the appropriate TokenSource based on available inputs.
Precedence:
- staticKey non-empty → StaticToken
- cliProxyPath non-empty → CliProxyFile (OAuth token auto-refreshed from disk)
- both empty → nil (caller sends no Authorization header)