oauth

package
v0.46.6 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
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

View Source
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

func IsAuthRejected(err error) bool

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

func IsInvalidGrant(err error) bool

IsInvalidGrant reports a revoked or expired refresh token. Only interactive re-authentication helps; retrying is pointless.

func LoggingMiddleware

func LoggingMiddleware(next http.Handler) http.Handler

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

func TokenClientID(tokenPath string) (string, error)

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

func ValidateTokenFile(tokenPath string) error

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.

Jump to

Keyboard shortcuts

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