clientcredentials

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package clientcredentials helps with oauth2 client-credentials flow.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaulIsBadTokenStatus added in v0.2.0

func DefaulIsBadTokenStatus(status int) bool

DefaulIsBadTokenStatus is used as default function when option IsBadTokenStatus is left undefined. DefaulIsBadTokenStatus just checks for status 401.

Types

type Client

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

Client is context for invokations with client-credentials flow.

func New

func New(options Options) *Client

New creates a client.

func (*Client) Do

func (c *Client) Do(req *http.Request) (*http.Response, error)

Do sends an HTTP request.

type HTTPDoer added in v0.3.0

type HTTPDoer interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPDoer is interface for http client.

type Options

type Options struct {
	TokenURL     string
	ClientID     string
	ClientSecret string
	Scope        string

	// HTTPClient is the HTTP client to use to make requests.
	// If nil, http.DefaultClient is used.
	HTTPClient HTTPDoer

	// IsTokenStatusCodeOk defines custom function to check whether the
	// token server response status is OK.
	// If undefined, defaults to nil, which means any 2xx status is OK.
	IsTokenStatusCodeOk func(status int) bool

	// 0 defaults to 10 seconds. Set to -1 to no soft expire.
	//
	// Example: consider expire_in = 30 seconds and soft expire = 10 seconds.
	// The token will hard expire after 30 seconds, but we will consider it
	// expired after (30-10) = 20 seconds, in order to attempt renewal before
	// hard expiration.
	//
	SoftExpireInSeconds int

	Cache token.TokenCache

	// Time source used to check token expiration.
	// If unspecified, defaults to time.Now().
	TimeSource func() time.Time

	DisableSingleFlight bool

	// Logging function, if undefined defaults to log.Printf
	Logf func(format string, v ...any)

	// Enable debug logging.
	Debug bool

	// IsBadTokenStatus defines custom function to check whether the
	// server response status is bad token.
	// If undefined, defaults to DefaulIsBadTokenStatus that just checks
	// for status 401.
	IsBadTokenStatus func(status int) bool
}

Options define client options.

Jump to

Keyboard shortcuts

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