/** * Construct the request to be verified * * @param string $uri * @param string $method * @param * array params The request parameters */ public function __construct($storages = [], array $config = [], $uri = null, $method = null, $params = null) { if ($params) { $encodedParams = array(); foreach ($params as $k => $v) { if (preg_match('/^oauth_/', $k)) { continue; } $encodedParams[rawurlencode($k)] = rawurlencode($v); } $this->params = array_merge($this->params, $encodedParams); } parent::__construct($uri, $method); // Setup storages $storages = is_array($storages) ? $storages : [$storages]; $this->storages = []; foreach ($storages as $key => $service) { $this->addStorage($service, $key); } }
/** * Handle request token, access token and xAuth login */ protected function handle($action) { $response = []; //\Debugbar::disable(); $now = new Carbon(); try { $statusCode = 200; $response = ['result' => ['status' => 'success', 'code' => $statusCode, 'server' => $_SERVER['SERVER_ADDR'], 'time' => $now->timestamp, 'version' => 1]]; switch ($action) { case 'requestToken': $result = OAuthServer::requestToken(); break; case 'accessToken': $result = OAuthServer::accessToken(); break; case 'xAuth': $result = OAuthServer::xAuth(); break; case 'logout': $result = OAuthServer::logout(); break; default: throw OAuthException::make(OAuthException::SERVICE_UNAVAILABLE); } $response = array_merge($response, $result); } catch (OAuthException $e) { $statusCode = 400; $response = ['result' => ['status' => 'error', 'code' => $statusCode, 'message' => $e->getName(), 'server' => $_SERVER['SERVER_ADDR'], 'time' => $now->timestamp, 'version' => 1, 'errors' => [['message' => $e->getMessage(), 'code' => $e->getCode(), 'method' => \Request::method(), 'url' => \Request::fullUrl()]]]]; } catch (\Exception $e) { \Log::error($e, ['method' => \Request::method(), 'url' => \Request::fullUrl(), 'error' => 'OAuth exception occured']); $statusCode = 500; $response = ['status' => 'error', 'code' => $statusCode, 'server' => $_SERVER['SERVER_ADDR'], 'time' => $now->timestamp, 'version' => 1, 'errors' => [['message' => 'Error occured', 'code' => 500, 'method' => \Request::method(), 'url' => \Request::fullUrl()]]]; } finally { return \Response::json($response, $statusCode); } }