tokenstore

package
v0.15.14 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2024 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("auth token not found")
)

Functions

func ShouldRefreshToken

func ShouldRefreshToken(token oauth2.Token, now time.Time) bool

func StoreNewToken

func StoreNewToken(t *oauth2.Token) error

func WithKeyring

func WithKeyring(k keyring.Keyring) func(o *Opts)

WithKeyring specifies a custom keyring to use.

Types

type NotifyRefreshTokenSource

type NotifyRefreshTokenSource struct {
	New oauth2.TokenSource

	T         *oauth2.Token
	SaveToken TokenNotifyFunc // called when token refreshed so new refresh token can be persisted
	// contains filtered or unexported fields
}

NotifyRefreshTokenSource is essentially `oauth2.ResuseTokenSource` with `TokenNotifyFunc` added.

func (*NotifyRefreshTokenSource) Token

func (s *NotifyRefreshTokenSource) Token() (*oauth2.Token, error)

Token returns the current token if it's still valid, else will refresh the current token (using r.Context for HTTP client information) and return the new one.

type Opts

type Opts struct {
	// Keyring is a custom keyring to use rather than
	// the default one, which is configured with
	// environment variables.
	Keyring keyring.Keyring
}

type Storage

type Storage struct {
	Context string
	// contains filtered or unexported fields
}

func New

func New(context string, opts ...func(*Opts)) Storage

New creates a new token storage driver. The context is the authentication context to use. This is usually 'default' and in future can be expanded to allow CLI users to switch between separate Common Fate tenancies.

func (*Storage) Clear

func (s *Storage) Clear() error

Clear the token

func (*Storage) Save

func (s *Storage) Save(token *oauth2.Token) error

Save the token

func (*Storage) Token

func (s *Storage) Token() (*oauth2.Token, error)

Token returns the OAuth2.0 token. It meets the TokenSource interface in the oauth2 package.

type TokenNotifyFunc

type TokenNotifyFunc func(*oauth2.Token) error

TokenNotifyFunc is a function that accepts an oauth2 Token upon refresh, and returns an error if it should not be used.

Jump to

Keyboard shortcuts

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