Skip to content

Commit

Permalink
Porsche: fix token refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Jul 3, 2023
1 parent 4433a24 commit e8d95af
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions vehicle/porsche/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,16 @@ func (v *Identity) Login(oc *oauth2.Config, user, password string) error {
return err
}

v.TokenSource = oc.TokenSource(cctx, token)
ts := oc.TokenSource(cctx, token)
v.TokenSource = oauth2.ReuseTokenSourceWithExpiry(token, ts, 6*time.Hour)

go v.refresh()

return nil
}

func (v *Identity) refresh() {
for range time.Tick(6 * time.Hour) {
for range time.Tick(time.Hour) {
if _, err := v.Token(); err != nil {
v.log.ERROR.Printf("token refresh: %v", err)
}
Expand Down

0 comments on commit e8d95af

Please sign in to comment.