token

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package token implements Token.

Index

Constants

This section is empty.

Variables

View Source
var DefaultTokenCache = &memoryCache{}

DefaultTokenCache provides default implementation for token cache.

Functions

This section is empty.

Types

type Token

type Token struct {
	Value    string    `json:"value"`
	Deadline time.Time `json:"deadline"`

	// By default Token is non-expirable.
	// It becomes expirable when either Expire() or SetExpiration() is applied.
	// SetExpiration() is used to take explicit expires_in field into effect.
	// Expire() is used to invalidate the Token, since the server
	// refused it and a new one must be retrieved.
	//
	Expirable bool `json:"expirable"`
}

Token holds a token.

func NewTokenFromJSON

func NewTokenFromJSON(buf []byte) (Token, error)

NewTokenFromJSON creates token from json.

func (*Token) Expire

func (t *Token) Expire()

Expire expires the token.

func (Token) ExportJSON

func (t Token) ExportJSON() ([]byte, error)

ExportJSON exports token as json.

func (*Token) IsValid

func (t *Token) IsValid(now time.Time, softExpire time.Duration, debugf func(format string, v ...any)) bool

IsValid checks whether token is valid.

func (*Token) SetExpiration

func (t *Token) SetExpiration(deadline time.Time)

SetExpiration schedules token expiration time.

type TokenCache

type TokenCache interface {
	Get() (Token, error)
	Put(t Token) error
	Expire() error
}

TokenCache defines a cache interface for storing tokens.

Jump to

Keyboard shortcuts

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