token

package
v4.0.0-...-6e18eb5 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is returned when a token cannot be found
	ErrNotFound = errors.New("token not found")
	// ErrEncodingToken is returned when the service encounters an error during encoding
	ErrEncodingToken = errors.New("error encoding the token")
	// ErrInvalidToken is returned when the token provided is not valid
	ErrInvalidToken = errors.New("invalid token provided")
)

Functions

This section is empty.

Types

type GenerateOption

type GenerateOption func(o *GenerateOptions)

func WithExpiry

func WithExpiry(d time.Duration) GenerateOption

WithExpiry for the generated account's token expires

type GenerateOptions

type GenerateOptions struct {
	// Expiry for the token
	Expiry time.Duration
}

func NewGenerateOptions

func NewGenerateOptions(opts ...GenerateOption) GenerateOptions

NewGenerateOptions from a slice of options

type JWT

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

JWT implementation of token provider

func (*JWT) Generate

func (j *JWT) Generate(acc *auth.Account, opts ...GenerateOption) (*Token, error)

Generate a new JWT

func (*JWT) Inspect

func (j *JWT) Inspect(t string) (*auth.Account, error)

Inspect a JWT

func (*JWT) String

func (j *JWT) String() string

String returns JWT

type Option

type Option func(o *Options)

func WithPrivateKey

func WithPrivateKey(key string) Option

WithPrivateKey sets the JWT private key

func WithPublicKey

func WithPublicKey(key string) Option

WithPublicKey sets the JWT public key

func WithStore

func WithStore(s store.Store) Option

WithStore sets the token providers store

type Options

type Options struct {
	// Store to persist the tokens
	Store store.Store
	// PublicKey base64 encoded, used by JWT
	PublicKey string
	// PrivateKey base64 encoded, used by JWT
	PrivateKey string
}

func NewOptions

func NewOptions(opts ...Option) Options

type Provider

type Provider interface {
	Generate(account *auth.Account, opts ...GenerateOption) (*Token, error)
	Inspect(token string) (*auth.Account, error)
	String() string
}

Provider generates and inspects tokens

func New

func New(opts ...Option) Provider

New returns an initialized basic provider

type Token

type Token struct {
	// The actual token
	Token string `json:"token"`
	// Time of token creation
	Created time.Time `json:"created"`
	// Time of token expiry
	Expiry time.Time `json:"expiry"`
}

Jump to

Keyboard shortcuts

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