package tokens

import "go.dedis.ch/dela/mino/minogrpc/tokens"

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

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.

Source Files

mod.go

Version
v0.1.0 (latest)
Published
Apr 10, 2024
Platform
linux/amd64
Imports
4 packages
Last checked
1 month ago

Tools for package owners.