Documentation
¶
Overview ¶
Package auth provides OAuth2 authentication and credential management for Google APIs.
Index ¶
- Constants
- 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 ( // 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 ¶
This section is empty.
Functions ¶
func CheckScopesMigration ¶
CheckScopesMigration compares the registered CLI's currently-required scopes (config.Scopes(), set by the CLI via config.Register) against the scopes a token was previously granted. It returns a non-empty, actionable message when the token is missing any now-required scope, so a CLI that has widened its scope set can prompt the user to re-authenticate. The scope set, descriptions, and product name all come from the registered identity, so the same logic serves any CLI backed by this library.
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. The token is read solely from the OS keyring via credstore (§1.1/§2.3 — no security/secret-tool shell-out, no token.json fallback). The active credential_ref is captured once here; refreshed tokens persist back to that exact ref via the closure passed to the token source (the sole sanctioned non-ingress keyring write). Returns an actionable error if no token exists.
func GetOAuthConfig ¶
GetOAuthConfig loads the OAuth client config from the deployment-material OAuth client JSON referenced by config.yml's oauth_client_path (§1.2 — not a secret; lives on disk, never the keyring), 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.