/** * Attempt to authenticate the user. * * @return boolean */ public function authenticate() { if (!isset($_REQUEST['code'])) { return false; } $token = $this->app->request()->post('/oauth2/token', ['client_id' => $this->app->client(), 'client_secret' => $this->app->secret(), 'grant_type' => 'authorization_code', 'redirect_uri' => $this->app->redirect(), 'code' => $_REQUEST['code']]); if ($token->error) { return false; } $user = $this->app->request()->get('/user', [], ['Authorization: OAuth ' . $token->access_token]); if ($user->error) { return false; } return $this->app->instance('TwitchApi\\Contracts\\User', [$token, $user]); }