nonce

package module
v0.0.0-...-335ab38 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2017 License: Apache-2.0 Imports: 14 Imported by: 0

README

go-nonce

Build Status GoDoc Go Report Card

Nonce "Service" written in go.

Install

go get -v github.com/bryanjeal/go-nonce

Help

cd <path>/github.com/bryanjeal/go-nonce Make help

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoToken       = errors.New("no token supplied")
	ErrInvalidToken  = errors.New("invalid token")
	ErrTokenUsed     = errors.New("duplicate submission")
	ErrTokenExpired  = errors.New("token expired")
	ErrTokenNotFound = errors.New("token not found")
)

Errors

View Source
var RemoveExpiredInterval = 24 * time.Hour

RemoveExpiredInterval can/should be set by applications using nonce. Default RemoveExpiredInterval is 24 Hours

Functions

This section is empty.

Types

type Nonce

type Nonce struct {
	ID        uuid.UUID
	UserID    uuid.UUID `db:"user_id"`
	Token     string
	Action    string
	Salt      string
	IsUsed    bool      `db:"is_used"`
	IsValid   bool      `db:"is_valid"`
	CreatedAt int64     `db:"created_at"`
	ExpiresAt time.Time `db:"expires_at"`
}

Nonce Model holds token and token details

type Service

type Service interface {
	// NewUserLocal registers a new user by a local account (email and password)
	// NOTE: time.Duraction is Truncated to the Second due to MySQL Date resolution
	New(action string, uid uuid.UUID, expiresIn time.Duration) (Nonce, error)

	// Check takes a Nonce token and checks to see if it is valid
	Check(token, action string, uid uuid.UUID) error

	// Consume takes a Nonce token and marks it as used
	Consume(token string) (Nonce, error)

	// CheckThenConsume checks to make sure Nonce token is valid and then marks it as used
	CheckThenConsume(token, action string, uid uuid.UUID) (Nonce, error)

	// Get takes a uid and action and returns the newest, valid nonce if it exists
	Get(action string, uid uuid.UUID) (Nonce, error)

	// Shutdown stops the removedExpired() function
	Shutdown()
}

Service is the interface that provides auth methods.

func NewInMemoryService

func NewInMemoryService() Service

NewInMemoryService creates an Nonce Service that stores all nonces in memory See service.inmem.go for implementation details

func NewService

func NewService(db *sqlx.DB) Service

NewService creates an Nonce Service that connects to provided DB information See service.sqlx.go for implementation details

Jump to

Keyboard shortcuts

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