-
Notifications
You must be signed in to change notification settings - Fork 3
/
token.go
54 lines (42 loc) · 1.19 KB
/
token.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package token
import (
"context"
"github.com/alexfalkowski/go-service/crypto/argon2"
ta "github.com/alexfalkowski/go-service/security/token/argon2"
)
type (
// Generator allows the implementation of different types generators.
Generator interface {
// Generate a new token or error.
Generate(ctx context.Context) (context.Context, []byte, error)
}
// Verifier allows the implementation of different types of verifiers.
Verifier interface {
// Verify a token or error.
Verify(ctx context.Context, token []byte) (context.Context, error)
}
// Tokenizer will generate and verify.
Tokenizer interface {
Generator
Verifier
// GenerateConfig to be used by the Tokenizer.
GenerateConfig() (string, string, error)
}
none struct{}
)
// NewTokenizer for token.
func NewTokenizer(cfg *Config, algo argon2.Algo) Tokenizer {
if !IsEnabled(cfg) {
return &none{}
}
return ta.NewTokenizer(cfg.Argon2, algo)
}
func (*none) GenerateConfig() (string, string, error) {
return "", "", nil
}
func (*none) Generate(ctx context.Context) (context.Context, []byte, error) {
return ctx, nil, nil
}
func (*none) Verify(ctx context.Context, _ []byte) (context.Context, error) {
return ctx, nil
}