Documentation
¶
Overview ¶
Package oauth provides OAuth2 authentication flows for Gmail.
Index ¶
- Variables
- func PrintHeadlessInstructions(email, tokensDir string)
- type Manager
- func (m *Manager) Authorize(ctx context.Context, email string) error
- func (m *Manager) DeleteToken(email string) error
- func (m *Manager) HasScope(email string, scope string) bool
- func (m *Manager) HasScopeMetadata(email string) bool
- func (m *Manager) HasToken(email string) bool
- func (m *Manager) TokenPath(email string) string
- func (m *Manager) TokenSource(ctx context.Context, email string) (oauth2.TokenSource, error)
Constants ¶
This section is empty.
Variables ¶
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).
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 ¶
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) DeleteToken ¶
DeleteToken removes the token file for the given email.
func (*Manager) HasScope ¶ added in v0.3.0
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
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) TokenPath ¶
TokenPath returns the path to the token file for an email (for external use).
func (*Manager) TokenSource ¶
TokenSource returns a token source for the given email. If a valid token exists, it will be reused and auto-refreshed.