-
Notifications
You must be signed in to change notification settings - Fork 2
/
token.go
48 lines (38 loc) · 836 Bytes
/
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
package test
import (
"context"
"errors"
"github.com/form3tech-oss/jwt-go"
)
// NewGenerator for test.
func NewGenerator(token string, err error) *Generator {
return &Generator{token: token, err: err}
}
// Generator for test.
type Generator struct {
token string
err error
}
func (g *Generator) Generate(ctx context.Context) ([]byte, error) {
return []byte(g.token), g.err
}
// NewVerifier for test.
func NewVerifier(token string) *Verifier {
return &Verifier{token: token}
}
// Verifier for test.
type Verifier struct {
token string
}
// nolint:goerr113
func (v *Verifier) Verify(ctx context.Context, token []byte) (*jwt.Token, error) {
if string(token) != v.token {
return nil, errors.New("invalid token")
}
jwtToken := &jwt.Token{
Claims: jwt.MapClaims{
"azp": v.token,
},
}
return jwtToken, nil
}