-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtokenmanager.go
64 lines (53 loc) · 2.62 KB
/
tokenmanager.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
55
56
57
58
59
60
61
62
63
64
package prototokens
import (
"context"
tokenpb "github.com/lusis/prototokens/proto/gen/go/prototokens/v1"
)
// TokenManager is something that can work with [tokenpb.ProtoToken] and [tokenpb.SignedToken]
type TokenManager interface {
// Sign signs the token
Sign(context.Context, *tokenpb.ProtoToken) (*tokenpb.SignedToken, error)
// Decode decodes a signed token from a string representation
Decode(context.Context, string) (*tokenpb.SignedToken, error)
// Encode encodes a signed token as a string
Encode(context.Context, *tokenpb.SignedToken) (string, error)
// Validate validates the provided [tokenpb.SignedToken]
Validate(context.Context, *tokenpb.SignedToken) error
// ValidFor validates if the token can be used for the provided usages
ValidFor(context.Context, *tokenpb.SignedToken, tokenpb.TokenUsages) error
// GetValidatedToken turns a [tokenpb.SignedToken] into a [tokenpb.ProtoToken] after validation
GetValidatedToken(context.Context, *tokenpb.SignedToken) (*tokenpb.ProtoToken, error)
// RevokeToken revokes a token
RevokeToken(context.Context, *tokenpb.ProtoToken) error
}
// UnimplementedTokenManager is a TokenManager implementation designed to be
// used for testing and embedding in other implementations to maintain compatibility
type UnimplementedTokenManager struct{}
// Sign signs the token
func (up *UnimplementedTokenManager) Sign(_ context.Context, _ *tokenpb.ProtoToken) (*tokenpb.SignedToken, error) {
return nil, ErrUnimplemented
}
// Decode decodes a signed token from a string representation
func (up *UnimplementedTokenManager) Decode(_ context.Context, _ string) (*tokenpb.SignedToken, error) {
return nil, ErrUnimplemented
}
// Encode encodes a signed token as a string
func (up *UnimplementedTokenManager) Encode(_ context.Context, _ *tokenpb.SignedToken) (string, error) {
return "", ErrUnimplemented
}
// Validate validates the provided [tokenpb.SignedToken]
func (up *UnimplementedTokenManager) Validate(_ context.Context, _ *tokenpb.SignedToken) error {
return ErrUnimplemented
}
// ValidFor validates if the token can be used for the provided usages
func (up *UnimplementedTokenManager) ValidFor(_ context.Context, _ *tokenpb.SignedToken, _ tokenpb.TokenUsages) error {
return ErrUnimplemented
}
// GetValidatedToken turns a [tokenpb.SignedToken] into a [tokenpb.ProtoToken] after validation
func (up *UnimplementedTokenManager) GetValidatedToken(_ context.Context, _ *tokenpb.SignedToken) (*tokenpb.ProtoToken, error) {
return nil, ErrUnimplemented
}
// RevokeToken revokes a token
func (up *UnimplementedTokenManager) RevokeToken(_ context.Context, _ *tokenpb.ProtoToken) error {
return ErrUnimplemented
}