Documentation
¶
Index ¶
- Constants
- Variables
- func GetClient(ctx context.Context, config *oauth2.Config, tokenPath string, interactive bool) (*http.Client, error)
- func IsAuthRejected(err error) bool
- func IsInvalidGrant(err error) bool
- func LoggingMiddleware(next http.Handler) http.Handler
- func TokenClientID(tokenPath string) (string, error)
- func ValidateTokenFile(tokenPath string) error
Constants ¶
const ( AuthTimeout = 300 * time.Second AuthListenAddr = "localhost" AuthListenPort = 9080 AuthScheme = "http://" CallBackURL = "/callback" DefaultPerms = 0o600 ReadTimeout = 5 * time.Second WriteTimeout = 5 * time.Second IdleTimeout = 60 * time.Second ReadHeaderTimeout = 10 * time.Second )
Variables ¶
var ( ErrOAuthUUID = errors.New("unable to generate UUID") ErrOAuthHTTPServer = errors.New("unable to start HTTP server") ErrOAuthBrowser = errors.New("unable to open system browser") ErrOAuthTimeout = errors.New("timeout while waiting for authentication to finish") ErrOAuthTokenFetch = errors.New("unable to retrieve token from Google API") ErrOAuthTokenSave = errors.New("unable to save token to file") ErrOAuthTokenEncode = errors.New("unable to encode OAuth token to JSON") ErrInvalidCallbackState = errors.New("invalid OAuth callback state") ErrOAuthDenied = errors.New("OAuth consent flow returned an error") ErrOAuthGrantRevoked = errors.New("OAuth grant revoked or expired") ErrOAuthTokenMissing = errors.New("no usable OAuth token file") )
Functions ¶
func GetClient ¶
func GetClient(ctx context.Context, config *oauth2.Config, tokenPath string, interactive bool) (*http.Client, error)
GetClient returns an authenticated client, persisting any rotation. A tokenPath holding no token runs the interactive consent flow only when interactive is set; otherwise it fails with ErrOAuthTokenMissing at once. Poll cycles pass false: the flow binds the callback port and waits out AuthTimeout for a consent nobody watching a daemon will give.
func IsAuthRejected ¶ added in v0.44.0
IsAuthRejected reports a token-endpoint rejection only re-authentication or a new client fixes: IsInvalidGrant, plus a deleted or reconfigured client.
func IsInvalidGrant ¶ added in v0.35.1
IsInvalidGrant reports a revoked or expired refresh token. Only interactive re-authentication helps; retrying is pointless.
func LoggingMiddleware ¶
LoggingMiddleware logs one line per request. The path, not the URI: the callback's query carries the auth code and state.
func TokenClientID ¶ added in v0.45.0
TokenClientID returns the client that tokenPath's token belongs to, or "" for a token saved before clients were recorded. An error means no usable token.
func ValidateTokenFile ¶ added in v0.35.1
ValidateTokenFile reports whether tokenPath decodes. Presence alone is not enough: a truncated or hand-edited file would otherwise fail every poll cycle at runtime instead of once, clearly, at startup.
Types ¶
This section is empty.