Fix token bug

This commit is contained in:
Ben Toogood 2020-05-14 13:30:21 +01:00
parent 1b18730d54
commit c220686c29
2 changed files with 7 additions and 6 deletions

View File

@ -315,9 +315,9 @@ func NewAuth(opts ...auth.Option) auth.Auth {
ruleTimer := time.NewTicker(time.Second * 30) ruleTimer := time.NewTicker(time.Second * 30)
for { for {
<-ruleTimer.C
time.Sleep(jitter.Do(time.Second * 5)) time.Sleep(jitter.Do(time.Second * 5))
service.loadRules() service.loadRules()
<-ruleTimer.C
} }
}() }()

View File

@ -252,7 +252,7 @@ func (s *service) generateAccount() error {
// generate the first token // generate the first token
token, err := s.Options().Auth.Token( token, err := s.Options().Auth.Token(
auth.WithCredentials(accID, accSecret), auth.WithCredentials(accID, accSecret),
auth.WithExpiry(time.Minute*15), auth.WithExpiry(time.Minute*10),
) )
if err != nil { if err != nil {
return err return err
@ -272,14 +272,15 @@ func (s *service) generateAccount() error {
<-timer.C <-timer.C
// don't refresh the token if it's not close to expiring // don't refresh the token if it's not close to expiring
if token.Expiry.Unix() > time.Now().Add(time.Minute).Unix() { tok := s.Options().Auth.Options().Token
if tok.Expiry.Unix() > time.Now().Add(time.Minute).Unix() {
continue continue
} }
// generate the first token // generate the first token
token, err := s.Options().Auth.Token( tok, err := s.Options().Auth.Token(
auth.WithCredentials(accID, accSecret), auth.WithCredentials(accID, accSecret),
auth.WithExpiry(time.Minute*15), auth.WithExpiry(time.Minute*10),
) )
if err != nil { if err != nil {
logger.Warnf("[Auth] Error refreshing token: %v", err) logger.Warnf("[Auth] Error refreshing token: %v", err)
@ -287,7 +288,7 @@ func (s *service) generateAccount() error {
} }
// set the token // set the token
s.Options().Auth.Init(auth.ClientToken(token)) s.Options().Auth.Init(auth.ClientToken(tok))
} }
}() }()