-
Notifications
You must be signed in to change notification settings - Fork 3
/
auth0.go
76 lines (63 loc) · 2 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
70
71
72
73
74
75
76
package auth0
import (
"github.com/alexfalkowski/go-service/security/jwt"
"github.com/alexfalkowski/go-service/transport/http"
"github.com/alexfalkowski/go-service/transport/http/telemetry/tracer"
"github.com/dgraph-io/ristretto"
"go.opentelemetry.io/otel/metric"
"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 tracer.Tracer
Meter metric.Meter
}
// NewGenerator for Auth0.
func NewGenerator(params GeneratorParams) (jwt.Generator, error) {
client, err := http.NewClient(params.HTTPConfig,
http.WithClientLogger(params.Logger),
http.WithClientBreaker(), http.WithClientRetry(),
http.WithClientTracer(params.Tracer), http.WithClientMetrics(params.Meter),
)
if err != nil {
return nil, err
}
var generator jwt.Generator = &generator{cfg: params.Config, client: client}
generator = &cachedGenerator{cfg: params.Config, cache: params.Cache, Generator: generator}
return generator, nil
}
// CertificatorParams for Auth0.
type CertificatorParams struct {
fx.In
Config *Config
HTTPConfig *http.Config
Logger *zap.Logger
Cache *ristretto.Cache
Tracer tracer.Tracer
Meter metric.Meter
}
// NewCertificator for Auth0.
func NewCertificator(params CertificatorParams) (Certificator, error) {
client, err := http.NewClient(params.HTTPConfig,
http.WithClientLogger(params.Logger),
http.WithClientBreaker(), http.WithClientRetry(),
http.WithClientTracer(params.Tracer), http.WithClientMetrics(params.Meter),
)
if err != nil {
return nil, err
}
var certificator Certificator = &pem{cfg: params.Config, client: client}
certificator = &cachedPEM{cfg: params.Config, cache: params.Cache, Certificator: certificator}
return certificator, nil
}
// NewVerifier for Auth0.
func NewVerifier(cfg *Config, cert Certificator) jwt.Verifier {
var verifier jwt.Verifier = &verifier{cfg: cfg, cert: cert}
return verifier
}