mirror of
https://github.com/hanzo-fi/stack.git
synced 2026-10-30 20:34:43 +00:00
41 lines
700 B
Go
41 lines
700 B
Go
package auth
|
|
|
|
import (
|
|
"github.com/formancehq/stack/libs/go-libs/logging"
|
|
"go.uber.org/fx"
|
|
)
|
|
|
|
type ModuleConfig struct {
|
|
Enabled bool
|
|
Issuer string
|
|
ReadKeySetMaxRetries int
|
|
CheckScopes bool
|
|
Service string
|
|
}
|
|
|
|
func Module(cfg ModuleConfig) fx.Option {
|
|
options := make([]fx.Option, 0)
|
|
|
|
options = append(options,
|
|
fx.Provide(func() Auth {
|
|
return NewNoAuth()
|
|
}),
|
|
)
|
|
|
|
if cfg.Enabled {
|
|
options = append(options,
|
|
fx.Decorate(func(logger logging.Logger) Auth {
|
|
return newJWTAuth(
|
|
logger,
|
|
cfg.ReadKeySetMaxRetries,
|
|
cfg.Issuer,
|
|
cfg.Service,
|
|
cfg.CheckScopes,
|
|
)
|
|
}),
|
|
)
|
|
}
|
|
|
|
return fx.Options(options...)
|
|
}
|