Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
Update to tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
Cannonb4ll committed Feb 25, 2019
1 parent b4d2239 commit 67c8a63
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ All the access data is saved in the `storage/app/hue.json` file, this contains t
- [ ] Add capabilities resource
- [ ] Add exceptions
- [ ] Add testing
- [ ] Fix refresh token refreshing automatically
- [ ] Update readme methods

## Helpful links
https://www.meethue.com/api/nupnp
Expand Down
8 changes: 6 additions & 2 deletions src/HueClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function refreshAndGetAccessToken()
$tokens = json_decode(file_get_contents(storage_path('app/hue.json')));

// Check if the previous access token is still valid, if its valid then return it (reduces API calls)
if (Carbon::createFromTimestamp(strtotime($tokens->expires_at)) > Carbon::now()) {
if (Carbon::createFromTimestamp(strtotime($tokens->access_token_expires_at)) > Carbon::now()) {
return $tokens->access_token;
}

Expand Down Expand Up @@ -99,10 +99,14 @@ public function startOAuth()
public function setTokenFile($data)
{
$data = json_decode($data);
$data->expires_at = Carbon::now()
$data->access_token_expires_at = Carbon::now()
->addSeconds($data->access_token_expires_in)
->format('Y-m-d H:i:s');

$data->refresh_token_expires_at = Carbon::now()
->addSeconds($data->refresh_token_expires_in)
->format('Y-m-d H:i:s');

\Storage::put('hue.json', json_encode($data));
}

Expand Down

0 comments on commit 67c8a63

Please sign in to comment.