Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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
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 ¶
NewService creates an Nonce Service that connects to provided DB information See service.sqlx.go for implementation details