acquire

package
v0.11.7 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: Apache-2.0 Imports: 9 Imported by: 19

Documentation

Overview

Package acquire is used for getting Auths to pass in http requests.

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyCredentials = errors.New("Empty credentials are not valid")

ErrEmptyCredentials is returned whenever an Acquirer is attempted to be built with empty credentials. Use DefaultAcquirer for such no-op use case.

Functions

func AddAuth

func AddAuth(r *http.Request, acquirer Acquirer) error

AddAuth adds an auth value to the Authorization header of an http request.

func DefaultExpirationParser

func DefaultExpirationParser(data []byte) (time.Time, error)

DefaultExpirationParser extracts a bearer token expiration date as defined by a SimpleBearer in a payload.

func DefaultTokenParser

func DefaultTokenParser(data []byte) (string, error)

DefaultTokenParser extracts a bearer token as defined by a SimpleBearer in a payload.

func RawTokenExpirationParser added in v0.10.1

func RawTokenExpirationParser(data []byte) (time.Time, error)

func RawTokenParser added in v0.10.1

func RawTokenParser(data []byte) (string, error)

Types

type Acquirer

type Acquirer interface {
	Acquire() (string, error)
}

Acquirer gets an Authorization value that can be added to an http request. The format of the string returned should be the key, a space, and then the auth string: '[AuthType] [AuthValue]'

type DefaultAcquirer

type DefaultAcquirer struct{}

DefaultAcquirer is a no-op Acquirer.

func (*DefaultAcquirer) Acquire

func (d *DefaultAcquirer) Acquire() (string, error)

Acquire returns the zero values of the return types.

type FixedValueAcquirer added in v0.4.0

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

FixedValueAcquirer implements Acquirer with a constant authorization value.

func NewFixedAuthAcquirer added in v0.4.0

func NewFixedAuthAcquirer(authValue string) (*FixedValueAcquirer, error)

NewFixedAuthAcquirer returns a FixedValueAcquirer with the given authValue.

func (*FixedValueAcquirer) Acquire added in v0.4.0

func (f *FixedValueAcquirer) Acquire() (string, error)

type ParseExpiration

type ParseExpiration func([]byte) (time.Time, error)

ParseExpiration defines the function signature of a bearer token expiration date extractor.

type RemoteBearerTokenAcquirer added in v0.4.0

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

RemoteBearerTokenAcquirer implements Acquirer and fetches the tokens from a remote location with caching strategy.

func NewRemoteBearerTokenAcquirer added in v0.4.0

func NewRemoteBearerTokenAcquirer(options RemoteBearerTokenAcquirerOptions) (*RemoteBearerTokenAcquirer, error)

NewRemoteBearerTokenAcquirer returns a RemoteBearerTokenAcquirer configured with the given options.

func (*RemoteBearerTokenAcquirer) Acquire added in v0.4.0

func (acquirer *RemoteBearerTokenAcquirer) Acquire() (string, error)

Acquire provides the cached token or, if it's near its expiry time, contacts the server for a new token to cache.

type RemoteBearerTokenAcquirerOptions added in v0.4.0

type RemoteBearerTokenAcquirerOptions struct {
	AuthURL        string            `json:"authURL"`
	Timeout        time.Duration     `json:"timeout"`
	Buffer         time.Duration     `json:"buffer"`
	RequestHeaders map[string]string `json:"requestHeaders"`

	GetToken      TokenParser
	GetExpiration ParseExpiration
}

RemoteBearerTokenAcquirerOptions provides configuration for the RemoteBearerTokenAcquirer.

type SimpleBearer added in v0.4.0

type SimpleBearer struct {
	ExpiresInSeconds float64 `json:"expires_in"`
	Token            string  `json:"serviceAccessToken"`
}

SimpleBearer defines the field name mappings used by the default bearer token and expiration parsers.

type TokenParser added in v0.4.0

type TokenParser func([]byte) (string, error)

TokenParser defines the function signature of a bearer token extractor from a payload.

Jump to

Keyboard shortcuts

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