credentials

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package credentials stores and resolves the OAuth refresh token.

Resolution order, the same one gh uses:

  1. GDOCS_REFRESH_TOKEN in the environment (CI, automation).
  2. The OS keyring (Secret Service on Linux, Keychain on macOS, Credential Manager on Windows), account = profile name.
  3. A 0600 file under the profile directory, written only when the keyring was unavailable at login time; the caller is warned.

A missing keyring entry falls through; a broken keyring (no session bus, no secret service) also falls through to the file so a headless machine still works, and the underlying error is reported if nothing else is found.

Index

Constants

View Source
const EnvVar = "GDOCS_REFRESH_TOKEN"

EnvVar is the environment override.

View Source
const ServiceName = "google-docs-mcp"

ServiceName is the keyring service identifier.

Variables

View Source
var ErrNotFound = errors.New("credentials: no refresh token found; run `google-docs-mcp login`")

ErrNotFound means no token is stored anywhere.

Functions

func IsKeyringNotFound

func IsKeyringNotFound(err error) bool

IsKeyringNotFound reports whether err is the keyring's "no entry" error.

Types

type Backend

type Backend interface {
	Get(service, account string) (string, error)
	Set(service, account, secret string) error
	Delete(service, account string) error
}

Backend is the keyring contract. Tests substitute an in-memory one.

func OSKeyring

func OSKeyring() Backend

OSKeyring returns the production keyring backend.

type Source

type Source string

Source identifies where a token came from.

const (
	SourceEnv     Source = "env"
	SourceKeyring Source = "keyring"
	SourceFile    Source = "file"
)

Source values.

type Store

type Store struct {
	Profile  string
	Keyring  Backend
	FilePath string
	Env      func(string) string
	// Warn receives human-readable warnings (plaintext fallback in use).
	Warn func(string)
}

Store resolves and saves the refresh token for one profile.

func (*Store) Delete

func (s *Store) Delete() error

Delete removes the token from every store. Missing entries are fine.

func (*Store) Resolve

func (s *Store) Resolve() (string, Source, error)

Resolve returns the refresh token and where it came from.

func (*Store) ResolveStored added in v0.2.0

func (s *Store) ResolveStored() (string, Source, error)

ResolveStored returns the token from the keyring or the file, ignoring the environment override: the token logout can revoke and delete.

func (*Store) Save

func (s *Store) Save(token string) (Source, error)

Save stores the token in the keyring, or in the file when the keyring fails. It returns where the token ended up.

Jump to

Keyboard shortcuts

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