Skip to content

Commit

Permalink
dont use accesstoken in auth-file because it could already be invalid…
Browse files Browse the repository at this point in the history
… on first call after restart
  • Loading branch information
skrollme committed Jun 11, 2024
1 parent e7700ef commit 9928431
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
3 changes: 3 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## version history

### 1.1.2
- Fixing "Invalid access token"-issue on restart (https://github.com/skrollme/homebridge-eveatmo/issues/81)

### 1.1.1
- Thanks to a PR (https://github.com/skrollme/homebridge-eveatmo/pull/76) from @Tellicious:
- Add new flag to enable/disable AirQuality sensor for indoor modules
Expand Down
14 changes: 7 additions & 7 deletions lib/netatmo-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var netatmo = function (args, homebridge) {
if (fs.existsSync(filename)) {
let rawData = fs.readFileSync(filename);
let tokenData = JSON.parse(rawData);
access_token = tokenData.access_token;
// access_token = tokenData.access_token; // dont read access_token because it may be already invalid on first use after restart
refresh_token = tokenData.refresh_token;
} else {
refresh_token = args.refresh_token;
Expand Down Expand Up @@ -182,20 +182,20 @@ netatmo.prototype.authenticate_refresh = function () {
}

body = JSON.parse(body);
refresh_token = body.refresh_token;

fs.writeFileSync(filename, JSON.stringify({
//'access_token': body.access_token, // dont store access_token because it may be already invalid on first use after restart
'refresh_token': body.refresh_token
}));

refresh_token = body.refresh_token;
if(access_token == null) {
access_token = body.access_token;
this.emit('authenticated');
} else {
access_token = body.access_token;
}

fs.writeFileSync(filename, JSON.stringify({
'access_token': body.access_token,
'refresh_token': body.refresh_token
}));

if (body.expires_in) {
setTimeout(this.authenticate_refresh.bind(this), (body.expires_in - 300) * 1000); // try refreshing the tokens 5min early
}
Expand Down

0 comments on commit 9928431

Please sign in to comment.