Documentation
¶
Overview ¶
Package oauth provides OAuth2 authentication flows for Gmail.
Index ¶
- Variables
- type Manager
- func (m *Manager) Authorize(ctx context.Context, email string, headless bool) 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 ¶
This section is empty.
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) Authorize ¶
Authorize performs the OAuth flow for a new account. If headless is true, uses device code flow; otherwise opens browser.
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.