]> git.localhorst.tv Git - alttp.git/blobdiff - app/Models/TwitchToken.php
track twitch token expiration
[alttp.git] / app / Models / TwitchToken.php
index a4c561eaffa40ce75cc49f5272cf13c8a1fb5b87..3a35d8c8ca0ef10606ebbeb517250e18349f34af 100644 (file)
@@ -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();
        }