argument('nick')); if (!$token) { $token = new TwitchToken(); $token->nick = $this->argument('nick'); $token->scope = ['chat:read', 'chat:edit']; } $url = $token->getAuthUrl(); $this->line('Please visit '.$url); $code = $this->ask('and enter the authorization code here'); $rsp = $this->fetchToken($code); $token->type = $rsp['token_type']; $token->access = $rsp['access_token']; $token->refresh = $rsp['refresh_token']; $token->save(); return Command::SUCCESS; } protected function fetchToken($code) { $rsp = Http::post('https://id.twitch.tv/oauth2/token', [ 'client_id' => config('twitch.client_id'), 'client_secret' => config('twitch.client_secret'), 'code' => $code, 'grant_type' => 'authorization_code', 'redirect_uri' => config('twitch.redirect_uri'), ]); if (!$rsp->successful()) { throw new \Exception($rsp['message']); } return $rsp->json(); } }