tokens

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package tokens defines a token holder to generate and validate access tokens.

The package also provides an in-memory implementation.

Documentation Last Review: 07.10.2020

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Holder

type Holder interface {
	// Generate creates a new token that is valid for the provided amount of
	// time.
	Generate(expiration time.Duration) string

	// Verify checks that the given token exists and is still valid.
	Verify(token string) bool
}

Holder is a store for access tokens.

type InMemoryHolder

type InMemoryHolder struct {
	sync.Mutex
	// contains filtered or unexported fields
}

InMemoryHolder stores access token in memory.

- implements tokens.Holder

func NewInMemoryHolder

func NewInMemoryHolder() *InMemoryHolder

NewInMemoryHolder creates a new empty token holder.

func (*InMemoryHolder) Generate

func (holder *InMemoryHolder) Generate(expiration time.Duration) string

Generate implements tokens.Holder. It generates a token that will expire after a given amount of time.

func (*InMemoryHolder) Verify

func (holder *InMemoryHolder) Verify(token string) bool

Verify implements tokens.Holder. It returns true if the token is valid.

Jump to

Keyboard shortcuts

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