token

package
v2.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package token provides utilities for retrieving and refreshing client_credentials tokens using an oauth.Client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider func(context.Context) (string, error)

Provider accepts a context and returns either:

(1) a nonempty token and a nil error, or

(2) an empty string and a non-nil error.

func CreateAndStartRefreshingOAuthProvider

func CreateAndStartRefreshingOAuthProvider(ctx context.Context, client oauth.ClientCredentialClient, clientID, clientSecret string, refreshInterval time.Duration) Provider

CreateAndStartRefreshingOAuthProvider returns a Provider which caches and periodically refreshes a client token. When it returns, we have not yet necessarily successfully fetched a valid token.

func NewRetryingTokenProvider

func NewRetryingTokenProvider(provideToken Provider) Provider

NewRetryingTokenProvider takes a TokenProvider and uses it to create another TokenProvider that retries forever.

type Refresher

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

Refresher periodically updates its token via its Provider. This type provides thread-safe access to an up-to-date token.

func NewRefresher

func NewRefresher(provideToken Provider, tokenTTL time.Duration) *Refresher

NewRefresher constructs a Refresher from a Provider and a token's TTL.

func (*Refresher) Run

func (r *Refresher) Run(ctx context.Context)

Run starts an endless refresh loop and is a blocking call; this will return once the context is cancelled.

func (*Refresher) Token

func (r *Refresher) Token(ctx context.Context) (string, error)

Token returns the currently stored token or an error if (1) there is no token stored and an attempt to get the token has failed, or (2) the stored token is not usable. This method will block until an attempt is completed to the provider to get the token (either success or fail).

func (*Refresher) TokenTTL

func (r *Refresher) TokenTTL() time.Duration

TokenTTL returns the TTL of the token.

Jump to

Keyboard shortcuts

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