oauth

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package oauth provides OAuth2 authentication flows for Gmail.

Index

Constants

This section is empty.

Variables

View Source
var Scopes = []string{
	"https://www.googleapis.com/auth/gmail.readonly",
	"https://www.googleapis.com/auth/gmail.modify",
}

Scopes for normal msgvault operations (sync, search, read).

View Source
var ScopesDeletion = []string{
	"https://mail.google.com/",
}

ScopesDeletion includes full access required for batchDelete API. gmail.modify supports trash/untrash but NOT batchDelete.

Functions

func PrintHeadlessInstructions added in v0.4.0

func PrintHeadlessInstructions(email, tokensDir string)

PrintHeadlessInstructions prints setup instructions for headless servers. Google's device flow does not support Gmail scopes, so users must authorize on a machine with a browser and copy the token file. tokensDir should be the configured tokens directory (e.g., cfg.TokensDir()).

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager handles OAuth2 token acquisition and storage.

func NewManager

func NewManager(clientSecretsPath, tokensDir string, logger *slog.Logger) (*Manager, error)

NewManager creates an OAuth manager from client secrets.

func NewManagerWithScopes

func NewManagerWithScopes(clientSecretsPath, tokensDir string, logger *slog.Logger, scopes []string) (*Manager, error)

NewManagerWithScopes creates an OAuth manager with custom scopes.

func (*Manager) Authorize

func (m *Manager) Authorize(ctx context.Context, email string) error

Authorize performs the browser OAuth flow for a new account.

func (*Manager) DeleteToken

func (m *Manager) DeleteToken(email string) error

DeleteToken removes the token file for the given email.

func (*Manager) HasScope added in v0.3.0

func (m *Manager) HasScope(email string, scope string) bool

HasScope checks if the stored token for the given email was authorized with the specified scope. Returns false if the token doesn't exist or doesn't have scope metadata (legacy tokens saved before scope tracking).

func (*Manager) HasScopeMetadata added in v0.3.0

func (m *Manager) HasScopeMetadata(email string) bool

HasScopeMetadata returns true if the token file for this account has any scope metadata stored. Legacy tokens (saved before scope tracking) return false.

func (*Manager) HasToken

func (m *Manager) HasToken(email string) bool

HasToken checks if a token exists for the given email.

func (*Manager) TokenPath

func (m *Manager) TokenPath(email string) string

TokenPath returns the path to the token file for an email (for external use).

func (*Manager) TokenSource

func (m *Manager) TokenSource(ctx context.Context, email string) (oauth2.TokenSource, error)

TokenSource returns a token source for the given email. If a valid token exists, it will be reused and auto-refreshed.

Jump to

Keyboard shortcuts

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