Documentation
¶
Overview ¶
Package auth provides OAuth2 authentication and credential management for Google APIs.
Index ¶
- Constants
- Variables
- func CheckScopesMigration(grantedScopes []string) string
- func ExchangeAuthCode(ctx context.Context, config *oauth2.Config, code string) (*oauth2.Token, error)
- func GetAuthURL(config *oauth2.Config) string
- func GetConfigDir() (string, error)
- func GetCredentialsPath() (string, error)
- func GetHTTPClient(ctx context.Context) (*http.Client, error)
- func GetOAuthConfig() (*oauth2.Config, error)
- func GetTokenPath() (string, error)
- func ShortenPath(path string) string
Constants ¶
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 ¶
var AllScopes = []string{ gmail.GmailModifyScope, calendar.CalendarReadonlyScope, calendar.CalendarEventsScope, people.ContactsScope, people.UserinfoProfileScope, drive.DriveReadonlyScope, drive.DriveMetadataScope, }
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. Profile is required for people/me (names, emailAddresses fields) used by `gro me` and init verification.
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.", people.UserinfoProfileScope: "Profile — read the authenticated user's name and email address (required for 'gro me').", 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
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 ¶
GetAuthURL returns the OAuth authorization URL for the given config
func GetConfigDir ¶
GetConfigDir returns the configuration directory path, creating it if needed. Deprecated: Use config.GetConfigDir() instead
func GetCredentialsPath ¶
GetCredentialsPath returns the full path to credentials.json Deprecated: Use config.GetCredentialsPath() instead
func GetHTTPClient ¶
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 ¶
GetOAuthConfig loads OAuth configuration from credentials file with all scopes
func GetTokenPath ¶
GetTokenPath returns the full path to token.json (fallback storage) Deprecated: Use config.GetTokenPath() instead
func ShortenPath ¶
ShortenPath replaces the home directory prefix with ~ for display purposes. Deprecated: Use config.ShortenPath() instead
Types ¶
This section is empty.