X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FModels%2FTwitchToken.php;h=3a35d8c8ca0ef10606ebbeb517250e18349f34af;hb=8645b77ea2dc402f0265e1c8022ba18302506ca1;hp=a4c561eaffa40ce75cc49f5272cf13c8a1fb5b87;hpb=4caeac216c5e5a044d81b63a8aa5b66451162271;p=alttp.git diff --git a/app/Models/TwitchToken.php b/app/Models/TwitchToken.php index a4c561e..3a35d8c 100644 --- a/app/Models/TwitchToken.php +++ b/app/Models/TwitchToken.php @@ -18,6 +18,10 @@ class TwitchToken extends Model .'&scope='.implode('+', array_map('rawurlencode', $this->scope)); } + public function hasExpired() { + return now()->isAfter($this->expires_at); + } + public function refresh() { $rsp = Http::post('https://id.twitch.tv/oauth2/token', [ 'client_id' => config('twitch.client_id'), @@ -32,6 +36,7 @@ class TwitchToken extends Model $this->scope = $rsp['scope']; $this->access = $rsp['access_token']; $this->refresh = $rsp['refresh_token']; + $this->expires_at = now()->add($rsp['expires_in'], 'second'); $this->save(); }