google

package
v0.2.21 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2025 License: Apache-2.0 Imports: 10 Imported by: 10 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package google implements the OAuth provider interface for Google OAuth 2.0. It supports user authentication, token exchange, and access to Google APIs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	ClientID       string
	ClientSecret   string
	RedirectURL    string
	Scopes         []string
	HTTPClient     *http.Client  // Optional custom HTTP client
	RequestTimeout time.Duration // Timeout for provider API calls (default: 30s)
}

Config holds Google OAuth configuration

type Provider

type Provider struct {
	*oauth2.Config
	// contains filtered or unexported fields
}

Provider implements the providers.Provider interface for Google OAuth. Embeds oauth2.Config directly to avoid duplication.

func NewProvider

func NewProvider(cfg *Config) (*Provider, error)

NewProvider creates a new Google OAuth provider

func (*Provider) AuthorizationURL

func (p *Provider) AuthorizationURL(state string, codeChallenge string, codeChallengeMethod string, scopes []string) string

AuthorizationURL generates the Google OAuth authorization URL with optional PKCE. Supports OAuth 2.1 defense-in-depth. See SECURITY_ARCHITECTURE.md for details. If scopes is empty, the provider's default configured scopes are used.

func (*Provider) DefaultScopes added in v0.1.37

func (p *Provider) DefaultScopes() []string

DefaultScopes returns the provider's configured default scopes. Returns a deep copy to prevent external modification.

func (*Provider) ExchangeCode

func (p *Provider) ExchangeCode(ctx context.Context, code string, verifier string) (*oauth2.Token, error)

ExchangeCode exchanges an authorization code for tokens with optional PKCE verification. Returns standard oauth2.Token. See SECURITY_ARCHITECTURE.md for security model details.

func (*Provider) HealthCheck added in v0.1.24

func (p *Provider) HealthCheck(ctx context.Context) error

HealthCheck verifies that Google's OAuth endpoints are reachable. It performs a lightweight check by fetching the OpenID Connect discovery document. Uses the provided context for timeout and cancellation. If context has no deadline, uses provider's default request timeout.

Security Considerations:

  • This method is designed for server-side health monitoring (k8s probes, monitoring systems)
  • DO NOT expose the returned error messages directly to untrusted clients
  • Error messages may contain HTTP status codes that could leak provider state information
  • For public health endpoints, return generic "healthy/unhealthy" status only

Recommended usage:

// Internal monitoring - detailed errors OK
if err := provider.HealthCheck(ctx); err != nil {
    log.Error("Provider health check failed", "error", err)
    return http.StatusInternalServerError
}

// Public endpoint - hide error details
if err := provider.HealthCheck(ctx); err != nil {
    w.WriteHeader(http.StatusServiceUnavailable)
    json.NewEncoder(w).Encode(map[string]string{"status": "unhealthy"})
    return
}

func (*Provider) Name

func (p *Provider) Name() string

Name returns the provider name

func (*Provider) RefreshToken

func (p *Provider) RefreshToken(ctx context.Context, refreshToken string) (*oauth2.Token, error)

RefreshToken refreshes an expired token Returns standard oauth2.Token directly

func (*Provider) RevokeToken

func (p *Provider) RevokeToken(ctx context.Context, token string) error

RevokeToken revokes a token at Google's revocation endpoint

func (*Provider) ValidateToken

func (p *Provider) ValidateToken(ctx context.Context, accessToken string) (*providers.UserInfo, error)

ValidateToken validates an access token by calling Google's userinfo endpoint

Jump to

Keyboard shortcuts

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