oauth2

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClientIDMustBeSet = errors.New("clientID must be set")
	ErrTokenURLRequired  = errors.New("tokenURL must be set")
)
View Source
var (
	ErrFirstTokenRequestFailed = errors.New("failed to get token")
	ErrTokenReuse              = errors.New("failed to reuse token")
	ErrFailedToExecuteRequest  = errors.New("failed to execute request")
)

Functions

func NewClient

func NewClient(opts ...Option) (*http.Client, error)

Types

type ClientConfig

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

type Option

type Option func(*ClientConfig)

func WithAPIClient

func WithAPIClient(client *http.Client) Option

func WithAuthURL

func WithAuthURL(url string) Option

func WithClientID

func WithClientID(id string) Option

func WithClientSecret

func WithClientSecret(secret string) Option

func WithScopes

func WithScopes(scopes ...string) Option

func WithTLSConfig

func WithTLSConfig(cfg *tls.Config) Option

func WithTokenURL

func WithTokenURL(url string) Option

type TokenInjector

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

TokenInjector is a struct that implements http.RoundTripper and injects headers into requests.

func NewTokenInjector

func NewTokenInjector(
	apiClient *http.Client,
	tokenClient *http.Client,
	clientCredentialsConfig *clientcredentials.Config,
) *TokenInjector

NewTokenInjector creates a new instance of TokenInjector. It requires an apiClient, tokenClient, and clientCredentialsConfig. The apiClient is used to execute HTTP requests. The tokenClient is used to fetch tokens. The clientCredentialsConfig is used to create a token source. The token is stored in the TokenInjector and reused for subsequent requests. If the token is nil or expired, a new token is fetched. In other cases, the token is reused. The token is injected into the request done by apiClient as a Bearer token.

func (*TokenInjector) RoundTrip

func (h *TokenInjector) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip executes a single HTTP transaction and injects headers into the request.

Jump to

Keyboard shortcuts

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