tokens

package
v0.0.0-...-8692103 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package tokens provides an implementation to fetch and manage OAuth2 tokens.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCacheSetupFailed = errors.New("cache setup failed")
	ErrCacheFailure     = errors.New("cache failure")
)

Err* are sentinel errors for this package.

Functions

func NewReuseTokenSource

func NewReuseTokenSource(cfg *oauth2.Config) func(context.Context, *oauth2.Token) oauth2.TokenSource

NewReuseTokenSource is the anticipated default token source for the caching source to wrap.

Types

type CachingSource

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

CachingSource is an implementation of TokenSource that will attempt to read the token from a cache. If it finds a valid token in the case, it'll use it. If not, it'll use the supplied "seed function" to fetch a new token.

func NewCachingSource

func NewCachingSource(
	ctx context.Context,
	tsf func(context.Context, *oauth2.Token) oauth2.TokenSource,
	sf seeds.Seed,
	str storage.Storage,
) (*CachingSource, error)

NewCachingSource allows creating a oauth2.TokenSource that caches the results in a storage layer (provided when the thing is constructed). Allows seeding the token source with a new token if there is nothing in the cache, or if what is in the cache is invalid (e.g. the user has never signed in before).

func (*CachingSource) Token

func (cs *CachingSource) Token() (*oauth2.Token, error)

Token implements the oauth2.TokenSource interface, allowing the user to query a token — wherever it comes from.

Directories

Path Synopsis
Package seeds provides a way to "seed" a token source; especially one that relies on caching.
Package seeds provides a way to "seed" a token source; especially one that relies on caching.
Package storage provides storage for the cachable token interface.
Package storage provides storage for the cachable token interface.

Jump to

Keyboard shortcuts

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