tokens

package
v0.0.0-...-f34d141 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2015 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBadToken = errors.New("Invalid CSRF token received in a form/header.")
View Source
var ErrMissingToken = errors.New("The CSRF token cannot be found.")

Functions

func DecodeToken

func DecodeToken(h string) ([]byte, error)

func EncodeToken

func EncodeToken(value []byte) string

Types

type Constant

type Constant string

Basic token for testing and debugging purposes.

func (Constant) Authenticate

func (t Constant) Authenticate(token string) bool

func (Constant) Generate

func (t Constant) Generate() string

type SHA256

type SHA256 struct {
	// Length of the one time token
	Length int

	// Secret known only to token storage
	Secret []byte
}

func (SHA256) Authenticate

func (t SHA256) Authenticate(token string) bool

func (SHA256) Generate

func (t SHA256) Generate() string

type Token

type Token interface {
	// Generates a token
	// the result is a hex encoded []byte
	// that can be checked by the Authenticate
	// method.
	Generate() string

	// Authenticate should take in the encoded token
	// and determine if it is a valid value.
	Authenticate(string) bool
}

func NewSHA256

func NewSHA256(length int) Token

type TokenFactory

type TokenFactory func(length int) Token

type TokenStorage

type TokenStorage interface {
	// load the token from the request.
	Load(*http.Request) (Token, error)

	// replaces the current token
	// with a newly generated token.
	// if for some reason it is impossible
	// to generate a token it should panic.
	NewToken(http.ResponseWriter, *http.Request) Token
}

Jump to

Keyboard shortcuts

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