-
Notifications
You must be signed in to change notification settings - Fork 3
/
auth0.go
69 lines (56 loc) · 1.77 KB
/
auth0.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
65
66
67
68
69
package auth0
import (
"github.com/alexfalkowski/go-service/security/jwt"
"github.com/alexfalkowski/go-service/transport/http"
"github.com/dgraph-io/ristretto"
"github.com/opentracing/opentracing-go"
"go.uber.org/fx"
"go.uber.org/zap"
)
// GeneratorParams for Auth0.
type GeneratorParams struct {
fx.In
Config *Config
HTTPConfig *http.Config
Logger *zap.Logger
Cache *ristretto.Cache
Tracer opentracing.Tracer
}
// NewGenerator for Auth0.
func NewGenerator(params GeneratorParams) jwt.Generator {
client := http.NewClient(
http.ClientParams{Config: params.HTTPConfig},
http.WithClientLogger(params.Logger),
http.WithClientBreaker(), http.WithClientRetry(),
http.WithClientTracer(params.Tracer),
)
var generator jwt.Generator = &generator{cfg: params.Config, client: client}
generator = &cachedGenerator{cfg: params.Config, cache: params.Cache, Generator: generator}
return generator
}
// CertificatorParams for Auth0.
type CertificatorParams struct {
fx.In
Config *Config
HTTPConfig *http.Config
Logger *zap.Logger
Cache *ristretto.Cache
Tracer opentracing.Tracer
}
// NewCertificator for Auth0.
func NewCertificator(params CertificatorParams) Certificator {
client := http.NewClient(
http.ClientParams{Config: params.HTTPConfig},
http.WithClientLogger(params.Logger),
http.WithClientBreaker(), http.WithClientRetry(),
http.WithClientTracer(params.Tracer),
)
var certificator Certificator = &pem{cfg: params.Config, client: client}
certificator = &cachedPEM{cfg: params.Config, cache: params.Cache, Certificator: certificator}
return certificator
}
// NewVerifier for Auth0.
func NewVerifier(cfg *Config, cert Certificator) jwt.Verifier {
var verifier jwt.Verifier = &verifier{cfg: cfg, cert: cert}
return verifier
}