auth

package
v1.0.41 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package auth provides OAuth2 authentication and credential management for Google APIs.

Index

Constants

View Source
const (
	// ConfigDirName is the name of the configuration directory
	// Deprecated: Use config.DirName instead
	ConfigDirName = config.DirName
	// CredentialsFile is the name of the OAuth credentials file
	// Deprecated: Use config.CredentialsFile instead
	CredentialsFile = config.CredentialsFile
	// TokenFile is the name of the OAuth token file (fallback storage)
	// Deprecated: Use config.TokenFile instead
	TokenFile = config.TokenFile
)

Re-export constants for backward compatibility

Variables

AllScopes contains all OAuth scopes used by the application. Gmail uses the modify scope for organizational operations (label, archive, star, mark read/unread). The modify scope is a superset of readonly — it includes all read access. Calendar uses both readonly (for calendar list metadata) and events (for RSVP/color operations). Note: calendar.events also permits event creation, which is an accepted trade-off for RSVP/color support. The architecture test (TestNoDestructiveAPIMethodsInProductionCode) prevents accidental misuse. Contacts uses the full contacts scope for group management and starring. The contacts scope is a superset of contacts.readonly — it includes all read access.

View Source
var ScopeDescriptions = map[string]string{
	gmail.GmailModifyScope:         "Gmail Modify — read messages, plus label, archive, star, and mark read/unread. No send or delete access.",
	gmail.GmailReadonlyScope:       "Gmail Read-Only — read messages and metadata.",
	calendar.CalendarReadonlyScope: "Calendar Read-Only — read calendars and events.",
	calendar.CalendarEventsScope:   "Calendar Events — read and update events (RSVP, color). No calendar settings access.",
	people.ContactsScope:           "Contacts — read contacts and groups, plus manage group membership and starring.",
	people.ContactsReadonlyScope:   "Contacts Read-Only — read contacts and groups.",
	drive.DriveReadonlyScope:       "Drive Read-Only — read files and metadata.",
	drive.DriveMetadataScope:       "Drive Metadata — read and update file metadata (star/unstar). No file content write access.",
}

ScopeDescriptions maps OAuth scope URLs to human-friendly descriptions.

Functions

func CheckScopesMigration added in v1.0.35

func CheckScopesMigration(grantedScopes []string) string

CheckScopesMigration compares the currently required scopes against the previously granted scopes. Returns a non-empty message if re-auth is needed.

func ExchangeAuthCode

func ExchangeAuthCode(ctx context.Context, config *oauth2.Config, code string) (*oauth2.Token, error)

ExchangeAuthCode exchanges an authorization code for a token

func GetAuthURL

func GetAuthURL(config *oauth2.Config) string

GetAuthURL returns the OAuth authorization URL for the given config

func GetConfigDir

func GetConfigDir() (string, error)

GetConfigDir returns the configuration directory path, creating it if needed. Deprecated: Use config.GetConfigDir() instead

func GetCredentialsPath

func GetCredentialsPath() (string, error)

GetCredentialsPath returns the full path to credentials.json Deprecated: Use config.GetCredentialsPath() instead

func GetHTTPClient

func GetHTTPClient(ctx context.Context) (*http.Client, error)

GetHTTPClient returns an HTTP client with OAuth2 authentication. It retrieves tokens from keychain (preferred) or falls back to file storage. Returns an error if no token is found - caller should direct user to run 'gro init'.

func GetOAuthConfig

func GetOAuthConfig() (*oauth2.Config, error)

GetOAuthConfig loads OAuth configuration from credentials file with all scopes

func GetTokenPath

func GetTokenPath() (string, error)

GetTokenPath returns the full path to token.json (fallback storage) Deprecated: Use config.GetTokenPath() instead

func ShortenPath

func ShortenPath(path string) string

ShortenPath replaces the home directory prefix with ~ for display purposes. Deprecated: Use config.ShortenPath() instead

Types

This section is empty.

Jump to

Keyboard shortcuts

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