@@ -22,20 +22,23 @@ type ModuleConfig struct {
2222}
2323
2424func Module (cfg ModuleConfig ) fx.Option {
25- options := make ([]fx.Option , 0 )
25+ options := ModuleOptions ()
26+ options = append (options , fx .Provide (func () ModuleConfig {
27+ return cfg
28+ }))
29+ return fx .Module ("auth" , options ... )
30+ }
2631
27- if ! cfg .Enabled {
28- options = append (options ,
29- fx .Provide (func () Authenticator {
30- return NewNoAuth ()
31- }),
32- )
33- return fx .Module ("auth" , options ... )
34- }
32+ func ModuleOptions () []fx.Option {
33+ options := make ([]fx.Option , 0 )
3534
3635 options = append (options ,
3736 fx .Supply (http .DefaultClient ),
38- fx .Provide (func (httpClient * http.Client ) (oidc.KeySet , error ) {
37+ fx .Provide (func (cfg ModuleConfig , httpClient * http.Client ) (oidc.KeySet , error ) {
38+ if ! cfg .Enabled {
39+ // this won't be used by the NoAuth
40+ return oidc .NewStaticKeySet (), nil
41+ }
3942 retryableHttpClient := retryablehttp .NewClient ()
4043 retryableHttpClient .RetryMax = cfg .ReadKeySetMaxRetries
4144 retryableHttpClient .HTTPClient = httpClient
@@ -54,7 +57,11 @@ func Module(cfg ModuleConfig) fx.Option {
5457 )
5558
5659 options = append (options ,
57- fx .Provide (func (keySet oidc.KeySet ) Authenticator {
60+ fx .Provide (func (cfg ModuleConfig , keySet oidc.KeySet ) Authenticator {
61+ if ! cfg .Enabled {
62+ return NewNoAuth ()
63+ }
64+
5865 return NewJWTAuth (
5966 keySet ,
6067 cfg .Issuer ,
@@ -64,5 +71,5 @@ func Module(cfg ModuleConfig) fx.Option {
6471 )
6572 }),
6673 )
67- return fx . Module ( "auth" , options ... )
74+ return options
6875}
0 commit comments