tokens

package
v2.0.3+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2016 License: MIT Imports: 13 Imported by: 17

Documentation

Index

Constants

View Source
const TTLMargin = 5 * time.Second

Variables

View Source
var NullStore = &nullStore{}

NullStore is a TokenStore that does not store tokens at all

Functions

func RestrictScope

func RestrictScope(server string, token string, scope []string) (string, error)

RestrictScope requests a new token with a different, more specific scope

Types

type HTTPError

type HTTPError struct {
	Code    int    `json:"code"`
	Message string `json:"error"`
}

HTTPError is an error that arises from HTTP

func (HTTPError) Error

func (e HTTPError) Error() string

type Manager

type Manager interface {
	// Get a token for the specified scope
	TokenForScope(scope string) (string, error)
}

Manager represent all types that can manage tokens

func HTTPManager

func HTTPManager(server, token string, store TokenStore) Manager

HTTPManager creates a new token manager that uses the specified store to store and retrieve tokens

type TokenStore

type TokenStore interface {

	// Get gets a token from the TokenStore, returning
	// the empty string if the token does not exist
	Get(parent string, scope string) (string, error)

	// Set saves a token, but only stores it for a given time
	Set(parent string, scope []string, token string, TTL time.Duration) error
}

TokenStore is the interface of all the token storage engines

func ConstStore

func ConstStore(token string) TokenStore

ConstStore creates a TokensStore that always returns the same token

func DirStore

func DirStore(dirname string) TokenStore

DirStore creates a filestore that stores tokens in the specified directory

func DirStoreWithFormat

func DirStoreWithFormat(dirname, format string) TokenStore

DirStoreWithFormat creates a filestore that stores tokens in the specified directory under with a custom filename

func FileStore

func FileStore(filename string) TokenStore

func FileStoreWithNameFn

func FileStoreWithNameFn(dirname string, nameFn func(string) string) TokenStore

DirStoreWithNameFn creates a filestore that stores tokens in the specified directory under with a custom filename

func MemoryStore

func MemoryStore() TokenStore

MemoryStore returns a new TokenStore that stores the tokens in memory

func RedisStore

func RedisStore(client *redis.Client) TokenStore

RedisStore returns a TokenStore that stores tokens in redis

Jump to

Keyboard shortcuts

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