refactor: make config stateful
This commit is contained in:
parent
bbe7e8e053
commit
8dd6e83fae
|
@ -18,6 +18,7 @@ type Oauth struct {
|
||||||
token *oauth2.Token
|
token *oauth2.Token
|
||||||
refresher oauth2.TokenSource
|
refresher oauth2.TokenSource
|
||||||
keepAliveRunning bool
|
keepAliveRunning bool
|
||||||
|
oauthCfg *oauth2.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewOauth(lc fx.Lifecycle, cfg *config.Config, logger *zap.Logger) *Oauth {
|
func NewOauth(lc fx.Lifecycle, cfg *config.Config, logger *zap.Logger) *Oauth {
|
||||||
|
@ -35,7 +36,8 @@ func NewOauth(lc fx.Lifecycle, cfg *config.Config, logger *zap.Logger) *Oauth {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o Oauth) config() *oauth2.Config {
|
func (o Oauth) config() *oauth2.Config {
|
||||||
cfg := &oauth2.Config{
|
if o.oauthCfg == nil {
|
||||||
|
o.oauthCfg = &oauth2.Config{
|
||||||
ClientID: o.cfg.Oauth.ClientId,
|
ClientID: o.cfg.Oauth.ClientId,
|
||||||
ClientSecret: o.cfg.Oauth.ClientSecret,
|
ClientSecret: o.cfg.Oauth.ClientSecret,
|
||||||
Scopes: []string{"admin"},
|
Scopes: []string{"admin"},
|
||||||
|
@ -46,10 +48,11 @@ func (o Oauth) config() *oauth2.Config {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
o.loadToken(cfg)
|
}
|
||||||
|
o.loadToken(o.oauthCfg)
|
||||||
o.keepAlive()
|
o.keepAlive()
|
||||||
|
|
||||||
return cfg
|
return o.oauthCfg
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o Oauth) authUrl() string {
|
func (o Oauth) authUrl() string {
|
||||||
|
|
Loading…
Reference in New Issue