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'), 'client_secret' => config('twitch.client_secret'), 'grant_type' => 'refresh_token', 'refresh_token' => $this->refresh, ]); if (!$rsp->successful()) { throw new \Exception($rsp['message']); } $this->type = $rsp['token_type']; $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(); } public function request() { return Http::baseUrl('https://api.twitch.tv/helix') ->withToken($this->access) ->withHeaders([ 'Client-Id' => config('twitch.client_id'), ]); } protected $casts = [ 'scope' => 'array', ]; protected $hidden = [ 'access', 'refresh', ]; }