oauth2

package
v0.37.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package oauth2 implements a generic configurable OAuth2 auth handler. Each CustomOAuth2Config registers as its own named auth.Handler supporting authorization code + PKCE, device code (RFC 8628), and client credentials (RFC 6749 §4.4).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateConfig

func ValidateConfig(cfg config.CustomOAuth2Config) error

ValidateConfig validates a CustomOAuth2Config for required fields and constraints.

Types

type Handler

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

Handler implements auth.Handler for generic configurable OAuth2 services.

func New

func New(cfg config.CustomOAuth2Config, opts ...Option) (*Handler, error)

New creates a new generic OAuth2 auth handler from a CustomOAuth2Config.

func (*Handler) Capabilities

func (h *Handler) Capabilities() []auth.Capability

Capabilities returns the handler's capabilities.

func (*Handler) DisplayName

func (h *Handler) DisplayName() string

DisplayName returns the human-readable name.

func (*Handler) GetToken

func (h *Handler) GetToken(ctx context.Context, opts auth.TokenOptions) (*auth.Token, error)

GetToken returns a valid access token, refreshing if necessary. If tokenExchange is configured, returns the derived token.

func (*Handler) InjectAuth

func (h *Handler) InjectAuth(ctx context.Context, req *http.Request, opts auth.TokenOptions) error

InjectAuth adds an Authorization header to the HTTP request.

func (*Handler) ListCachedTokens added in v0.17.0

func (h *Handler) ListCachedTokens(ctx context.Context) ([]*auth.CachedTokenInfo, error)

ListCachedTokens returns all cached tokens for this handler.

func (*Handler) Login

func (h *Handler) Login(ctx context.Context, opts auth.LoginOptions) (*auth.Result, error)

Login performs authentication using the configured OAuth2 flow.

func (*Handler) Logout

func (h *Handler) Logout(ctx context.Context) error

Logout clears all stored tokens for this handler.

func (*Handler) Name

func (h *Handler) Name() string

func (*Handler) PurgeExpiredTokens added in v0.17.0

func (h *Handler) PurgeExpiredTokens(ctx context.Context) (int, error)

PurgeExpiredTokens removes all expired access tokens from the cache.

func (*Handler) RegistryUsername

func (h *Handler) RegistryUsername() string

RegistryUsername returns the configured OCI registry username convention for this handler (e.g. "$oauthtoken" for Quay.io). An empty string means the caller should use the default convention. This implements the optional catalog.RegistryUsernameProvider interface consumed by BridgeAuthToRegistry.

func (*Handler) Status

func (h *Handler) Status(ctx context.Context) (*auth.Status, error)

Status returns the current authentication state.

func (*Handler) SupportedFlows

func (h *Handler) SupportedFlows() []auth.Flow

SupportedFlows returns the flows this handler supports based on config.

type Option

type Option func(*Handler)

Option configures the Handler.

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

WithHTTPClient sets a custom HTTP client.

func WithLogger

func WithLogger(lgr logr.Logger) Option

WithLogger sets the logger for the handler.

func WithSecretKeyPrefix added in v0.17.0

func WithSecretKeyPrefix(prefix string) Option

WithSecretKeyPrefix overrides the default secret key prefix used for storing secrets in the keychain. This allows the generic oauth2.Handler to share tokens written by plugin auth handlers that use a different prefix convention.

func WithSecretStore

func WithSecretStore(store secrets.Store) Option

WithSecretStore sets a custom secrets store.

Jump to

Keyboard shortcuts

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