fix: only run keep alive if loading token is a success

This commit is contained in:
Derrick Hammer 2024-02-11 22:32:22 -05:00
parent 4faa7c9b88
commit a439ca8002
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 6 additions and 3 deletions

View File

@ -49,8 +49,9 @@ func (o Oauth) config() *oauth2.Config {
}
}
o.loadToken(o.oauthCfg)
if o.loadToken(o.oauthCfg) {
o.keepAlive()
}
return o.oauthCfg
}
@ -59,7 +60,7 @@ func (o Oauth) authUrl() string {
return o.config().AuthCodeURL("state")
}
func (o Oauth) loadToken(config *oauth2.Config) {
func (o Oauth) loadToken(config *oauth2.Config) bool {
token := &oauth2.Token{}
if o.cfg.Oauth.Token != "" {
@ -92,11 +93,13 @@ func (o Oauth) loadToken(config *oauth2.Config) {
token = o.token
} else {
o.logger.Info("Token is expired, ignoring")
return false
}
}
}
o.refresher = config.TokenSource(context.Background(), token)
return true
}
func (o Oauth) keepAlive() {