Skip to content

Commit

Permalink
Easee: validate token every 5min
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Jul 6, 2023
1 parent 16d0b02 commit 7f069b6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion charger/easee.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func NewEasee(user, password, charger string, timeout time.Duration) (*Easee, er

// refresh ensures tokens are refreshed even when not charging for longer time
func (c *Easee) refresh() {
for range time.Tick(time.Hour) {
for range time.Tick(5 * time.Minute) {
if _, err := c.Client.Transport.(*oauth2.Transport).Source.Token(); err != nil {
c.log.ERROR.Println("token refresh:", err)
}
Expand Down
2 changes: 1 addition & 1 deletion charger/easee/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TokenSource(log *util.Logger, user, password string) (oauth2.TokenSource, e
if err = c.DoJSON(req, &token); err == nil {
token := token.AsOAuth2Token()
ts := oauth.RefreshTokenSource(token, c)
c.TokenSource = oauth2.ReuseTokenSourceWithExpiry(token, ts, 6*time.Hour)
c.TokenSource = oauth2.ReuseTokenSourceWithExpiry(token, ts, 15*time.Minute)
}
}

Expand Down

2 comments on commit 7f069b6

@jheinitz
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moin @andig!
Sag mal, kann man das nicht auch so machen, dass man die Gültigkeit des Tokens ermittelt und dann entweder 1h vor Ablauf oder nach 80% der Zeit (um die kurzen zu erwischen) einen Refresh macht? Keine Ahnung, ob das geht und wenn ja, wieviel Aufwand das wäre. Nur so als Idee.....

@andig
Copy link
Member Author

@andig andig commented on 7f069b6 Jul 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So ist es ja jetzt. Wenn Easee auf die Idee kommt Tokens noch kürzer als 15min auszustellen hab ich endgültig keine Lust mehr…

Please sign in to comment.