auth

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 12 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	Email string        `json:"email,omitempty"`
	Token *oauth2.Token `json:"token"`
}

Account holds the OAuth2 token for a single Google account.

type Config

type Config struct {
	Accounts map[string]*Account `json:"accounts"`
}

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

func NewManager(configDir, credentialsFile string) (*Manager, error)

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

func (m *Manager) Authenticate(ctx context.Context, name string, scopes []string) error

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) ConfigDir

func (m *Manager) ConfigDir() string

ConfigDir returns the configuration directory path.

func (*Manager) CredentialsFile

func (m *Manager) CredentialsFile() string

CredentialsFile returns the path to the Google credentials.json file.

func (*Manager) ListAccounts

func (m *Manager) ListAccounts() map[string]string

ListAccounts returns all configured account names and their email addresses.

func (*Manager) RemoveAccount

func (m *Manager) RemoveAccount(name string) error

RemoveAccount removes an account by name.

func (*Manager) ResolveAccounts

func (m *Manager) ResolveAccounts(account string) ([]string, error)

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.

Jump to

Keyboard shortcuts

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