-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathstore.go
29 lines (24 loc) · 927 Bytes
/
store.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package passwordless
import (
"errors"
"time"
"context"
_ "github.com/pzduniak/mcf/scrypt"
)
var (
ErrTokenNotFound = errors.New("the token does not exist")
ErrTokenNotValid = errors.New("the token is incorrect")
)
// TokenStore is a storage mechanism for tokens.
type TokenStore interface {
// Store securely stores the given token with the given expiry time
Store(ctx context.Context, token, uid string, ttl time.Duration) error
// Exists returns true if a token is stored for the user. If the expiry
// time is available this is also returned, otherwise it will be zero
// and can be tested with `Time.IsZero()`.
Exists(ctx context.Context, uid string) (bool, time.Time, error)
// Verify returns true if the given token is valid for the user
Verify(ctx context.Context, token, uid string) (bool, error)
// Delete removes the token for the specified user
Delete(ctx context.Context, uid string) error
}