X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FModels%2FTwitchToken.php;fp=app%2FModels%2FTwitchToken.php;h=3a35d8c8ca0ef10606ebbeb517250e18349f34af;hb=17d105b4d07ce544e94b7f90ff7f50feb86b244f;hp=a4c561eaffa40ce75cc49f5272cf13c8a1fb5b87;hpb=f3e985ec38b6221ef4c450e02b3e61e8ef08dc21;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(); }