token

package
v0.0.0-...-614d85d Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const KeyLength = 32

Variables

View Source
var NotFoundError = errors.New("token not found")

Functions

This section is empty.

Types

type Payload

type Payload struct {
	Username string `json:"username"`
	Data     string `json:"data"`
}

func NewPayload

func NewPayload(jsonString string) (p Payload, err error)

func (Payload) String

func (t Payload) String() string

serialize to string

type Store

type Store interface {
	// Generate creates a random token for user with payload and saves to store
	Generate(username string, data string, lifetime time.Duration) (string, error)

	// StoreToken saves a token and data to store with limited lifetime
	StoreToken(username, token, data string, lifetime time.Duration) error

	// DeleteToken removes a sigle token from store
	DeleteToken(t string) error

	// GetData returns the stored data of the token
	GetData(token string) (data string, err error)

	// GetUserTokens returns list of tokens of the given user
	GetUserTokens(username string) ([]string, error)

	// DeleteUserTokens removes all tokens of the user
	DeleteUserTokens(username string) error
}

Store contains methods to manage tokens

func NewEtcdStore

func NewEtcdStore(indexKeyPrefix, payloadKeyPrefix string, etcdClient *etcd.Client) (Store, error)

NewEtcdStore creates a Store managing access tokens. A token `x` is stored at both place:

- $(indexKeyPrefix)/users/${u}/x: this key is used for indexing and listing tokens of user `u`.

- $(payloadKeyPrefix)/x: this key contains actual payload data of the token. It's used for fast lookup tokens

Jump to

Keyboard shortcuts

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