Skip to content

Commit 8840937

Browse files
committed
fix refresh token
1 parent 6735d1a commit 8840937

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
.DS_Store
2-
.idea
2+
.idea
3+
/vendor
4+
/composer.lock

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"homepage": "https://github.com/dcblogdev/laravel-dropbox",
1313
"keywords": ["Laravel", "Dropbox"],
1414
"require": {
15-
"illuminate/support": "^5.5|^5.6|^5.7|^5.8|^6.0|^7.0|^8.0|^9.0|^10.0",
15+
"illuminate/support": "^8.0|^9.0|^10.0",
1616
"guzzlehttp/guzzle": "^6|^7"
1717
},
1818
"autoload": {

src/Dropbox.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Dcblogdev\Dropbox;
44

5+
use Carbon\Carbon;
56
use Dcblogdev\Dropbox\Facades\Dropbox as Api;
67
use Dcblogdev\Dropbox\Models\DropboxToken;
78
use Dcblogdev\Dropbox\Resources\Files;
@@ -171,8 +172,7 @@ public function getAccessToken($returnNullNoAccessToken = null)
171172
if (isset($token->refresh_token)) {
172173
// Check if token is expired
173174
// Get current time + 5 minutes (to allow for time differences)
174-
$now = time() + 300;
175-
if ($token->expires_in <= $now) {
175+
if ($token->expires_in->lessThan(Carbon::now()->addMinutes(5))) {
176176
// Token is expired (or very close to it) so let's refresh
177177
$params = [
178178
'grant_type' => 'refresh_token',

src/Models/DropboxToken.php

+4
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@
77
class DropboxToken extends Model
88
{
99
protected $guarded = [];
10+
11+
protected $casts = [
12+
'expires_in' => 'datetime',
13+
];
1014
}

0 commit comments

Comments
 (0)