token

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package token provides a thread-safe cache of a authorization token that may be used across http and grpc clients

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	TimeNow func() time.Time
	// contains filtered or unexported fields
}

Cache is a thread-safe cache of a authorization token that may be used across http and grpc clients

func NewCache

func NewCache(fetcher Fetcher, refreshToken string) *Cache

NewCache creates a new token cache

func (*Cache) GetToken

func (c *Cache) GetToken(ctx context.Context, minTTL time.Duration) (string, error)

GetToken returns the current token if its at least `minTTL` from expiration, or fetches a new one.

type Fetcher

type Fetcher func(ctx context.Context, refreshToken string) (*Token, error)

Fetcher is a function that fetches a new token

type Token

type Token struct {
	// Bearer is the bearer token
	Bearer string
	// Expires is the time the token expires
	Expires time.Time
}

Token is a bearer token

func (*Token) ExpiresAfter

func (t *Token) ExpiresAfter(tm time.Time) bool

ExpiresAfter returns true if the token expires after the given time

Jump to

Keyboard shortcuts

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