oauth

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 5 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 oauth defines provider interfaces and shared OAuth profile types used by Canopy.

Provider implementations are responsible for constructing OAuth2 configuration, exchanging authorization codes, refreshing provider access tokens, and normalizing verified provider profile data into Canopy's account model.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DiscoverProvider added in v1.0.0

func DiscoverProvider(ctx context.Context, issuer string) (*oidc.Provider, error)

DiscoverProvider returns a cached successful OIDC discovery result. Failed and canceled discovery attempts are not cached.

Types

type Profile

type Profile struct {
	ProviderID            string
	AccountID             string
	Email                 string
	EmailVerified         bool
	Name                  string
	Image                 string
	IDToken               string
	AccessToken           string
	RefreshToken          string
	Scope                 string
	AccessTokenExpiresAt  *time.Time
	RefreshTokenExpiresAt *time.Time
}

type Provider

type Provider interface {
	ID() string
	Config(ctx context.Context) (*oauth2.Config, error)
	AuthCodeOptions(StartOptions) []oauth2.AuthCodeOption
	Exchange(ctx context.Context, code string, verifier string) (*oauth2.Token, error)
	Refresh(ctx context.Context, refreshToken string) (*oauth2.Token, error)
	Profile(ctx context.Context, token *oauth2.Token, nonce string) (*Profile, error)
}

type RedirectExchanger added in v1.0.1

type RedirectExchanger interface {
	ExchangeWithRedirect(ctx context.Context, code string, verifier string, redirectURL string) (*oauth2.Token, error)
}

RedirectExchanger is an optional provider capability. A provider that implements it can exchange an authorization code with a redirect URL that replaces the configured one. The value must equal the redirect URL of the authorization request, because OAuth requires the two to match.

The built-in providers implement this interface. A caller must type-assert it and must fall back to Provider.Exchange when a provider does not implement it.

type StartOptions

type StartOptions struct {
	State        string
	Nonce        string
	PKCEVerifier string
	CallbackURL  string
	Scopes       []string
	// RedirectURL replaces the redirect URL that the provider is configured
	// with. It applies to this authorization request and to the matching
	// token exchange. An empty value keeps the configured redirect URL.
	//
	// A module sets this when its own callback route is not the core OAuth
	// callback route. The value must come from server-side configuration.
	// Never build it from request input.
	//
	// OAuth requires the redirect_uri of the token exchange to match the
	// redirect_uri of the authorization request. A provider that honors this
	// field must also implement RedirectExchanger, so that the caller can
	// send the same value at the exchange.
	RedirectURL string
}

type Validator added in v1.0.0

type Validator interface {
	Validate() error
}

Validator is an optional provider capability used by canopy.New to reject incomplete provider configuration before serving requests.

Jump to

Keyboard shortcuts

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