token

package module
v0.0.0-...-1c51a0f Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2017 License: Apache-2.0 Imports: 10 Imported by: 0

README

Secure Token Go library to emit tokens

Usage:

Please do copy & paste the code, don't create more dependencies :)

// Generate token with id
tgen := token.NewTokenHmacSha(secret)
token := tgen.Generate(id)

// Check if the token is valid for a given duration
valid, id, issueTime := tgen.Valid(token, 10*time.Minute)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TokenEmitter

type TokenEmitter interface {
	Generate(id string) string
	Valid(token string, d time.Duration) (valid bool, id string, issue time.Time)
}

TokenEmitter interface to be able to generate and validate tokens

func NewTokenHmacSha

func NewTokenHmacSha(secret string) TokenEmitter

type TokenHmacSha

type TokenHmacSha struct {
	// contains filtered or unexported fields
}

TokenHmacSha generate a tokes in the format <hash>.<rnd>.<id>.<ts> with hash = HMAC_SHA1 (secret, rnd + id + ts)

func (*TokenHmacSha) Generate

func (tk *TokenHmacSha) Generate(id string) string

func (*TokenHmacSha) Valid

func (tk *TokenHmacSha) Valid(token string, d time.Duration) (bool, string, time.Time)

Valid returns true if token is a valid and the Id associated with the token and the issue time

Jump to

Keyboard shortcuts

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