Documentation
¶
Overview ¶
Package auth handles OAuth2 authentication and multi-account token management for Google APIs. It reads OAuth client credentials directly from a Google Cloud Console credentials.json file and stores per-account tokens separately.
Index ¶
- type Account
- type Config
- type Manager
- func (m *Manager) Authenticate(ctx context.Context, name string, scopes []string) error
- func (m *Manager) ClientOption(ctx context.Context, name string, scopes []string) (option.ClientOption, error)
- func (m *Manager) ConfigDir() string
- func (m *Manager) CredentialsFile() string
- func (m *Manager) ListAccounts() map[string]string
- func (m *Manager) RemoveAccount(name string) error
- func (m *Manager) ResolveAccounts(account string) ([]string, error)
- func (m *Manager) TokenSource(ctx context.Context, name string, scopes []string) (oauth2.TokenSource, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
Config holds per-account tokens. OAuth client credentials are read directly from the Google credentials.json file, not stored here.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles loading/saving tokens and reading credentials from the Google Cloud Console credentials.json file.
func NewManager ¶
NewManager creates a new auth manager.
configDir defaults to the platform-native config directory:
- Linux: $XDG_CONFIG_HOME/google-mcp (or ~/.config/google-mcp)
- macOS: ~/Library/Application Support/google-mcp
- Windows: %AppData%/google-mcp
credentialsFile defaults to <configDir>/credentials.json.
func (*Manager) Authenticate ¶
Authenticate runs the OAuth2 authorization code flow for a named account. It opens a browser for consent, runs a local callback server, and stores the resulting token.
func (*Manager) ClientOption ¶
func (m *Manager) ClientOption(ctx context.Context, name string, scopes []string) (option.ClientOption, error)
ClientOption returns a google API option.ClientOption for the named account.
func (*Manager) CredentialsFile ¶
CredentialsFile returns the path to the Google credentials.json file.
func (*Manager) ListAccounts ¶
ListAccounts returns all configured account names and their email addresses.
func (*Manager) RemoveAccount ¶
RemoveAccount removes an account by name.
func (*Manager) ResolveAccounts ¶
ResolveAccounts resolves an account parameter to a list of account names. If account is "all", it returns all configured account names. Otherwise it validates the account exists and returns it as a single-element slice.
func (*Manager) TokenSource ¶
func (m *Manager) TokenSource(ctx context.Context, name string, scopes []string) (oauth2.TokenSource, error)
TokenSource returns an oauth2.TokenSource for the named account. The token source automatically refreshes expired tokens and persists the updated token back to the tokens file.