googleoauth

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: Apache-2.0 Imports: 14 Imported by: ? modules, 0 packages

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 googleoauth provides Google Authorization Code flow orchestration.

Index

Constants

View Source
const (
	AuthorizationEndpoint = "https://accounts.google.com/o/oauth2/v2/auth"
)

Variables

View Source
var (
	ErrConflict       = errors.New("Google identity is linked to another user")
	ErrInvalidConfig  = errors.New("invalid Google OAuth configuration")
	ErrInvalidInput   = errors.New("invalid Google OAuth input")
	ErrInvalidRecord  = errors.New("invalid Google OAuth record")
	ErrInvalidState   = errors.New("invalid or expired OAuth state")
	ErrLastCredential = errors.New("cannot remove the last sign-in method")
	ErrLinkRequired   = errors.New("existing user must authenticate before linking Google")
	ErrNotFound       = errors.New("Google OAuth record not found")
	ErrUnverified     = errors.New("Google identity email is not verified")
)

Functions

This section is empty.

Types

type Challenge

type Challenge struct {
	StateHash    [32]byte
	Nonce        string
	CodeVerifier string
	SubjectID    string
	CreatedAt    time.Time
	ExpiresAt    time.Time
}

type Config

type Config struct {
	ClientID         string
	AuthorizationURL string
	RedirectURL      string
	StateLifetime    time.Duration
	Identities       IdentityStore
	SecurityEvents   SecurityEventSink
	Now              func() time.Time
}

type EventType

type EventType string
const EventUnlinked EventType = "google_unlinked"

type ExchangeInput

type ExchangeInput struct {
	Code         string
	CodeVerifier string
	RedirectURL  string
	Audience     string
}

type GoogleProviderConfig

type GoogleProviderConfig struct {
	ClientID     string
	ClientSecret string
	HTTPClient   *http.Client
}

type Identity

type Identity struct {
	ProviderSubject string
	Email           string
	EmailVerified   bool
	Nonce           string
}

type IdentityResolution

type IdentityResolution struct {
	ProviderSubject string
	Email           string
	SubjectID       string
}

type IdentityStore

type IdentityStore interface {
	UnlinkIdentity(ctx context.Context, subjectID string, unlinkedAt time.Time) error
}

IdentityStore must atomically refuse removal of the user's last sign-in method.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func NewManager

func NewManager(store Store, provider Provider, config Config) (*Manager, error)

func (*Manager) Begin

func (manager *Manager) Begin(ctx context.Context, subjectID string) (Started, error)

func (*Manager) Complete

func (manager *Manager) Complete(ctx context.Context, state, code string) (User, error)
func (manager *Manager) Unlink(
	ctx context.Context,
	subjectID string,
	sourceKey string,
) error

type Provider

type Provider interface {
	Exchange(ctx context.Context, input ExchangeInput) (Identity, error)
}

Provider verifies the Google ID token signature, issuer, audience, and expiry.

func NewGoogleProvider

func NewGoogleProvider(config GoogleProviderConfig) (Provider, error)

type SecurityEvent

type SecurityEvent struct {
	Type       EventType
	SubjectID  string
	SourceKey  string
	OccurredAt time.Time
}

type SecurityEventSink

type SecurityEventSink interface {
	Record(ctx context.Context, event SecurityEvent)
}

type Started

type Started struct {
	AuthorizationURL string
	State            string
}

type Store

type Store interface {
	CreateChallenge(ctx context.Context, challenge Challenge) error
	ConsumeChallenge(ctx context.Context, stateHash [32]byte, consumedAt time.Time) (Challenge, error)
	// ResolveIdentity finds, links, or creates a user atomically. Each user may
	// have only one Google identity. ProviderSubject is the permanent account
	// key; an existing unlinked email returns ErrLinkRequired.
	ResolveIdentity(ctx context.Context, resolution IdentityResolution) (User, error)
}

type User

type User struct {
	ID string
}

Jump to

Keyboard shortcuts

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