auth

package
v0.20.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 13, 2026 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

type TokenSource interface {
	Token() (string, error)
}

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:

  1. staticKey non-empty → StaticToken
  2. cliProxyPath non-empty → CliProxyFile (OAuth token auto-refreshed from disk)
  3. both empty → nil (caller sends no Authorization header)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL