예제 #1
0
 /**
  * Support method -- get parameters to log into an account (but allow override of
  * individual parameters so we can test different scenarios).
  *
  * @param array $overrides Associative array of parameters to override.
  *
  * @return \Zend\Http\Request
  */
 protected function getLoginRequest($overrides = array())
 {
     $post = $overrides + array('username' => 'testuser', 'password' => 'testpass');
     $request = new \Zend\Http\Request();
     $request->setPost(new \Zend\Stdlib\Parameters($post));
     return $request;
 }
예제 #2
0
 /**
  * Test route matches against various URIs
  */
 public function testRouter()
 {
     $application = \Library\Application::init('Console', true);
     $router = $application->getServiceManager()->get('HttpRouter');
     $request = new \Zend\Http\Request();
     $matchDefaultDefault = array('controller' => 'client', 'action' => 'index');
     $matchControllerDefault = array('controller' => 'controllername', 'action' => 'index');
     $matchControllerAction = array('controller' => 'controllername', 'action' => 'actionname');
     $request->setUri('/');
     $this->assertEquals($matchDefaultDefault, $router->match($request)->getParams());
     $request->setUri('/controllername');
     $this->assertEquals($matchControllerDefault, $router->match($request)->getParams());
     $request->setUri('/controllername/');
     $this->assertEquals($matchControllerDefault, $router->match($request)->getParams());
     $request->setUri('/controllername/actionname');
     $this->assertEquals($matchControllerAction, $router->match($request)->getParams());
     $request->setUri('/controllername/actionname/');
     $this->assertEquals($matchControllerAction, $router->match($request)->getParams());
     $request->setUri('/controllername/actionname/invalid');
     $this->assertNull($router->match($request));
     $request->setUri('/console');
     $this->assertEquals($matchDefaultDefault, $router->match($request)->getParams());
     $request->setUri('/console/');
     $this->assertEquals($matchDefaultDefault, $router->match($request)->getParams());
     $request->setUri('/console/controllername');
     $this->assertEquals($matchControllerDefault, $router->match($request)->getParams());
     $request->setUri('/console/controllername/');
     $this->assertEquals($matchControllerDefault, $router->match($request)->getParams());
     $request->setUri('/console/controllername/actionname');
     $this->assertEquals($matchControllerAction, $router->match($request)->getParams());
     $request->setUri('/console/controllername/actionname/');
     $this->assertEquals($matchControllerAction, $router->match($request)->getParams());
     $request->setUri('/console/controllername/actionname/invalid');
     $this->assertNull($router->match($request));
 }
 /**
  * Creates a new HTTP POST request with the appropriate content, headers 
  * and such, which can then be used to send JSON-RPC requests.
  * @param string $content the request content
  * @return \Zend\Http\Request the request
  * @throws ClientException if the Content-Type header cannot be set
  */
 private function createHttpRequest($content)
 {
     $httpRequest = new \Zend\Http\Request();
     $httpRequest->setUri($this->_endPoint);
     $httpRequest->setMethod(\Zend\Http\Request::METHOD_POST);
     $httpRequest->setContent($content);
     // Set headers
     $headers = $httpRequest->getHeaders();
     if (!$headers instanceof \Zend\Http\Headers) {
         throw new ClientException('Unable to configure HTTP headers');
     }
     $headers->addHeaderLine('Content-Type', 'application/json');
     $httpRequest->setHeaders($headers);
     return $httpRequest;
 }
 /**
  * Delegate checking of user credentials to ZfcUser's onboard adapter chain
  *
  * @param  string  $username
  * @param  string  $password
  * @return boolean
  */
 public function checkUserCredentials($username, $password)
 {
     $request = new \Zend\Http\Request();
     $request->getPost()->set('identity', $username);
     $request->getPost()->set('credential', $password);
     $adapterResult = $this->authAdapter->prepareForAuthentication($request);
     if ($adapterResult instanceof \Zend\Stdlib\ResponseInterface) {
         return false;
     }
     $authResult = $this->auth->authenticate($this->authAdapter);
     if (!$authResult->isValid()) {
         $this->authAdapter->resetAdapters();
         return false;
     }
     return true;
 }
예제 #5
0
 public static function sendRequest($url, $postString = '', $method = \Zend\Http\Request::METHOD_POST)
 {
     $client = new \Zend\Http\Client();
     $client->setAdapter(new \Zend\Http\Client\Adapter\Curl());
     $request = new \Zend\Http\Request();
     $request->setUri($url);
     $request->setMethod($method);
     if (is_array($postString)) {
         $params = $postString;
         $postString = '';
         foreach ($params as $key => $value) {
             $postString .= $key . '=' . urlencode($value) . '&';
         }
         $postString = substr($postString, 0, strlen($postString) - 1);
     }
     $request->setContent($postString);
     $response = $client->dispatch($request);
     return $response->getContent();
 }
예제 #6
0
 /**
  * Set session with authenticated user data
  * 
  * 
  * @access public
  * @param Users/Entity/User $user ,default is null
  * @uses AuthenticationService
  */
 public function newSession($user = null)
 {
     if (is_null($user)) {
         $user = $this->query->findOneBy('Users\\Entity\\User', array('username' => $this->request->getPost('username')));
     }
     $auth = new AuthenticationService();
     $storage = $auth->getStorage();
     // here to add new entries to the session
     $storage->write(array('id' => $user->id, 'firstName' => $user->getFirstName(), 'middleName' => $user->getMiddleName(), 'lastName' => $user->getLastName(), 'name' => $user->getFullName(), 'username' => $user->getUsername(), 'email' => $user->getEmail(), 'photo' => $user->getPhoto(), 'status' => $user->getStatus(), 'roles' => $user->getRolesNames(), 'agreements' => $user->getRolesAgreementsStatus()));
 }
예제 #7
0
<?php

/**
 * Created by PhpStorm.
 * User: user
 * Date: 07/12/15
 * Time: 14:43
 */
require "./vendor/autoload.php";
$route = \Zend\Mvc\Router\Http\Segment::factory(array('route' => '/:chemin', 'constraints' => array('chemin' => '[a-zA-Z]+')));
$req = new \Zend\Http\Request();
$req->setUri('http://monsite/st9');
$match = $route->match($req);
if ($match !== null) {
    echo "ok\n";
} else {
    echo "ressource non connue \n";
}
예제 #8
0
파일: PICA.php 프로젝트: tillk/vufind
 /**
  * Patron Login
  *
  * This is responsible for authenticating a patron against the catalog.
  *
  * @param string $barcode  The patron username
  * @param string $password The patron's password
  *
  * @throws ILSException
  * @return mixed          Associative array of patron info on successful login,
  * null on unsuccessful login.
  */
 public function patronLogin($barcode, $password)
 {
     // Build request:
     $request = new \Zend\Http\Request();
     $request->getPost()->set('username', $barcode)->set('password', $password);
     // First try local database:
     $db = new \VuFind\Auth\Database();
     try {
         $user = $db->authenticate($request);
     } catch (\VuFind\Exception\Auth $e) {
         // Next try LDAP:
         $ldap = new \VuFind\Auth\LDAP();
         $user = $ldap->authenticate($request);
     }
     $_SESSION['picauser'] = $user;
     return ['id' => $user->id, 'firstname' => $user->firstname, 'lastname' => $user->lastname, 'email' => $user->email, 'username' => $barcode, 'password' => $password, 'cat_username' => $barcode, 'cat_password' => $password];
 }
예제 #9
0
    }
    if (!$valt->validate('import_remote')) {
        ${$error}->add($valt->getErrorMessage());
    }
    if (count($incoming_urls) < 1) {
        $error->add(t('You must specify at least one valid URL.'));
    }
}
$import_responses = array();
$files = array();
// if we haven't gotten any errors yet then try to process the form
if (!$error->has()) {
    // itterate over each incoming URL adding if relevant
    foreach ($incoming_urls as $this_url) {
        // try to D/L the provided file
        $request = new \Zend\Http\Request();
        $request->setUri($this_url);
        $client = new \Zend\Http\Client();
        $response = $client->dispatch($request);
        if ($response->isSuccess()) {
            $headers = $response->getHeaders();
            $contentType = $headers->get('ContentType')->getFieldValue();
            $fpath = $file->getTemporaryDirectory();
            // figure out a filename based on filename, mimetype, ???
            if (preg_match('/^.+?[\\/]([-\\w%]+\\.[-\\w%]+)$/', $request->getUri(), $matches)) {
                // got a filename (with extension)... use it
                $fname = $matches[1];
            } elseif ($contentType) {
                // use mimetype from http response
                $fextension = Core::make("helper/mime")->mimeToExtension($contentType);
                if ($fextension === false) {
예제 #10
0
 public function testUnknownAccept()
 {
     $this->config['diagnostics']['group']['test1'] = $check1 = new AlwaysSuccessCheck();
     ob_start();
     $request = new \Zend\Http\Request();
     $request->getHeaders()->addHeader(\Zend\Http\Header\Accept::fromString('Accept: application/baz'));
     $result = $this->controller->dispatch($request);
     $this->assertEquals('', ob_get_clean());
     $this->assertInstanceOf('Zend\\View\\Model\\ViewModel', $result);
     $this->assertInstanceOf('ZendDiagnostics\\Result\\Collection', $result->getVariable('results'));
 }
예제 #11
0
파일: Ajax.php 프로젝트: hiveclick/mojavi
 /**
  * Sends the data via cURL
  * @param array $params
  * @param integer $method
  * @param string $raw_body
  * @return Zend_Http_Response
  */
 private function curl($orig_url, $params = array(), $method = Request::GET, $headers = array(), $remove_unsafe_params = true, $retry_count = 0)
 {
     try {
         if (is_null($orig_url) && defined('MO_API_URL')) {
             $orig_url = MO_API_URL;
         } else {
             if (is_null($orig_url)) {
                 throw new \Exception('No url was provided and MO_API_URL is not defined');
             }
         }
         $url = $orig_url . $this->getFunc();
         if ($method == Request::DELETE || $method == Request::PUT) {
             if (isset($params['_id'])) {
                 $url .= '/' . (isset($params['_id']) ? (int) $params['_id'] : 0);
             }
         }
         // remove any routing to prevent overwritting the url
         if ($remove_unsafe_params) {
             if (isset($params['module'])) {
                 unset($params['module']);
             }
             if (isset($params['controller'])) {
                 unset($params['controller']);
             }
             if (isset($params['action'])) {
                 unset($params['action']);
             }
             if (isset($params['func'])) {
                 unset($params['func']);
             }
         }
         // gots to do this so that transfer-encoding: chunked comes through properly
         $curl_adapter = new \Zend\Http\Client\Adapter\Curl();
         // Enforce a 30 second timeout (default is unlimited)
         if ($this->getTimeout() > 0) {
             $curl_adapter->setCurlOption(CURLOPT_TIMEOUT, $this->getTimeout());
             $curl_adapter->setCurlOption(CURLOPT_CONNECTTIMEOUT, $this->getTimeout());
         }
         //$curl_adapter->setCurlOption(CURLOPT_ENCODING , "gzip");
         $curl_adapter->setCurlOption(CURLOPT_SSL_VERIFYPEER, false);
         $curl_adapter->setCurlOption(CURLOPT_USERAGENT, 'Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10');
         $http_client = new \Zend\Http\Client();
         $http_client->setAdapter($curl_adapter);
         $http_client->setUri($url);
         $http_client->setArgSeparator('&');
         $request = new \Zend\Http\Request();
         $request->setUri($url);
         //$http_client->setCookieJar($this->getHttpCookieJar());
         // Set the token authentication
         $request->getHeaders()->addHeaderLine('Accept-Encoding', 'gzip,deflate');
         $request->getHeaders()->addHeaderLine('Content-Type', \Zend\Http\Client::ENC_URLENCODED);
         if (is_array($headers)) {
             foreach ($headers as $key => $header) {
                 $request->getHeaders()->addHeaderLine($key, $header);
             }
         }
         if ($request->getUri() === null) {
             throw new \Exception('No URI given. Param \'func\' is required.');
         }
         /* @var $response Zend_Http_Response */
         $response = false;
         if ($method == \Mojavi\Request\Request::GET) {
             if (is_array($params)) {
                 $request->getQuery()->fromArray($params);
             }
             $request->setMethod(\Zend\Http\Request::METHOD_GET);
             $response = $http_client->send($request);
         } else {
             if ($method == \Mojavi\Request\Request::POST) {
                 // If we uploaded files, we have to send them differently
                 if (count($_FILES) > 0) {
                     $request->getFiles()->fromArray($_FILES);
                     $http_client->setEncType(\Zend\Http\Client::ENC_FORMDATA);
                 } else {
                     $http_client->setEncType(\Zend\Http\Client::ENC_URLENCODED);
                 }
                 if (is_array($params)) {
                     $request->getPost()->fromArray($params);
                 }
                 $request->setMethod(\Zend\Http\Request::METHOD_POST);
                 $response = $http_client->send($request);
             } else {
                 if ($method == \Mojavi\Request\Request::DELETE) {
                     $request->setMethod(\Zend\Http\Request::METHOD_DELETE);
                     $response = $http_client->send($request);
                 } else {
                     if ($method == \Mojavi\Request\Request::PUT) {
                         if (count($_FILES) > 0) {
                             $request->getFiles()->fromArray($_FILES);
                             $http_client->setEncType(\Zend\Http\Client::ENC_FORMDATA);
                         } else {
                             $http_client->setEncType(\Zend\Http\Client::ENC_FORMDATA);
                         }
                         if (is_array($params)) {
                             $request->getQuery()->fromArray($params);
                         }
                         $request->setMethod(\Zend\Http\Request::METHOD_PUT);
                         $response = $http_client->send($request);
                     }
                 }
             }
         }
         return $response;
     } catch (\Exception $e) {
         if (strpos($e->getMessage(), 'connect() timed out!') !== false && $retry_count < 3) {
             return $this->curl($orig_url, $params, $method, $headers, $remove_unsafe_params, ++$retry_count);
         } else {
             if (strpos($e->getMessage(), 'couldn\'t connect to host') !== false && $retry_count < 3) {
                 return $this->curl($orig_url, $params, $method, $headers, $remove_unsafe_params, ++$retry_count);
             } else {
                 if (strpos($e->getMessage(), 'Operation timed out') !== false && $retry_count < 3) {
                     return $this->curl($orig_url, $params, $method, $headers, $remove_unsafe_params, ++$retry_count);
                 }
             }
         }
         throw $e;
     }
 }
예제 #12
0
<?php

require "vendor/autoload.php";
$route = \Zend\Mvc\Router\Http\Segment::factory(array('route' => '/:controller[/:toto]', 'constraints' => array('controller' => '[a-zA-Z][a-zA-Z0-9_-]+', 'toto' => '[a-zA-Z][a-zA-Z0-9_-]+'), 'defaults' => array('controller' => 'Application\\Controller\\IndexController', 'action' => 'index')));
$req = new \Zend\Http\Request();
$req->setUri('http://monsite/stock/inventaire');
$match = $route->match($req);
if ($match !== null) {
    echo $match->getParam('toto') . "\n";
} else {
    echo "ressource non connue \n";
}
 public function setUp()
 {
     $httpRequest = new \Zend\Http\Request('https://dummy/userinfo');
     $httpRequest->getHeaders()->addHeaders(array('Authorization' => 'Bearer access_token_123'));
     $this->request = new Request\UserInfo($httpRequest);
 }
예제 #14
0
 /**
  * Support method -- turn an array into a request populated for use by the
  * authentication class.
  *
  * @param array $post Associative array of POST parameters.
  *
  * @return \Zend\Http\Request
  */
 protected function getRequest($post)
 {
     $request = new \Zend\Http\Request();
     $request->setPost(new \Zend\Stdlib\Parameters($post));
     return $request;
 }
예제 #15
0
 /**
  * @return \Zend\Http\Request a base request object
  */
 private function createBasicRequest()
 {
     $request = new \Zend\Http\Request();
     return $request->setUri('http://' . $this->getHostInfo() . '/');
 }
 */
$client->resetParameters();
$client->setMethod('POST');
$request = new \Zend\Http\Request();
$request->setUri($tokenUri);
$request->setMethod('POST');
$request->getPost()->fromArray(array('grant_type' => 'authorization_code', 'code' => $data['code'], 'redirect_uri' => 'https://dummy', 'client_id' => $clientId));
// Client authentication
$request->getHeaders()->addHeaders(array('Authorization' => $clientAuthorization));
_dumpRequest($request);
$client->setMethod('POST');
$response = $client->send($request);
_dumpResponse($response);
$tokenData = \Zend\Json\Json::decode($response->getContent(), \Zend\Json\Json::TYPE_ARRAY);
_dump($tokenData);
if (isset($tokenData['error'])) {
    die("ERROR\n");
}
/*
 * User info request
 */
$request = new \Zend\Http\Request();
$request->setUri($userInfoUri);
$request->getQuery()->fromArray(array('schema' => 'openid'));
$request->getHeaders()->addHeaders(array('Authorization' => sprintf("Bearer %s", $tokenData['access_token'])));
_dumpRequest($request);
$client->setMethod('GET');
$response = $client->send($request);
_dumpResponse($response);
$userData = \Zend\Json\Json::decode($response->getContent(), \Zend\Json\Json::TYPE_ARRAY);
_dump($userData);
 public function setUp()
 {
     $httpRequest = new \Zend\Http\Request();
     $httpRequest->getPost()->fromArray(array(Request\Token::FIELD_CODE => 'authorization_code_123', Request\Token::FIELD_CLIENT_ID => 'testclient', Request\Token::FIELD_GRANT_TYPE => 'authorization_code', Request\Token::FIELD_REDIRECT_URI => 'http://dummy'));
     $this->request = new Request\Token($httpRequest);
 }
예제 #18
0
 /**
  * Support method for forceLogin() -- convert a lightbox URL to a non-lightbox
  * URL.
  *
  * @param string $url URL to convert
  *
  * @return string
  */
 protected function delightboxURL($url)
 {
     // If this isn't a lightbox URL, we don't want to mess with it!
     $parts = parse_url($url);
     parse_str($parts['query'], $query);
     if (false === strpos($parts['path'], '/AJAX/JSON')) {
         return $url;
     }
     // Build the route name:
     $routeName = strtolower($query['submodule']) . '-' . strtolower($query['subaction']);
     // Eliminate lightbox-specific parameters that might confuse the router:
     unset($query['method'], $query['subaction'], $query['submodule']);
     // Get a preliminary URL that we'll need to analyze in order to build
     // the final URL:
     $url = $this->url()->fromRoute($routeName, $query);
     // Using the URL generated above, figure out which parameters are route
     // params and which are GET params:
     $request = new \Zend\Http\Request();
     $request->setUri($url);
     $router = $this->getEvent()->getRouter();
     $matched = $router->match($request)->getParams();
     $getParams = $routeParams = [];
     foreach ($query as $current => $val) {
         if (isset($matched[$current])) {
             $routeParams[$current] = $val;
         } else {
             $getParams[$current] = $val;
         }
     }
     // Now build the final URL:
     return $this->url()->fromRoute($routeName, $routeParams, ['query' => $getParams]);
 }
 public function setUp()
 {
     $httpRequest = new \Zend\Http\Request();
     $httpRequest->getQuery()->fromArray(array(Authorize\Field::CLIENT_ID => 'client_id_123', Authorize\Field::STATE => '123456', Authorize\Field::RESPONSE_TYPE => 'code', Authorize\Field::REDIRECT_URI => 'http://redirect', Authorize\Field::NONCE => 'nonce_123'));
     $this->_request = new Authorize\Simple($httpRequest);
 }
예제 #20
0
<?php

require "./vendor/autoload.php";
$route = \Zend\Mvc\Router\Http\Segment::factory(array('route' => '/:controller', 'constraints' => array('controller' => '[A-Za-z]+')));
$req = new \Zend\Http\Request();
$req->setUri($argv[1]);
$match = $route->match($req);
if ($match != null) {
    echo "OK";
} else {
    echo "NOn ok";
}
예제 #21
0
 protected function _replace($filePath, $photoId, $async = 0)
 {
     $params['async'] = $async;
     $params['photo_id'] = $photoId;
     $finalParams = $this->_httpUtility->assembleParams($this->_endpointReplace, $this->_configOAuth, $params);
     $request = new \Zend\Http\Request();
     $request->setUri($this->_endpointReplace)->setMethod('POST')->setPost(new Parameters($finalParams));
     $this->_httpClient->reset();
     $this->_httpClient->setRequest($request);
     $this->_httpClient->setEncType(\Zend\Http\Client::ENC_FORMDATA, 'ITSCARO');
     $this->_httpClient->setFileUpload($filePath, 'photo');
     $response = $this->_httpClient->dispatch($request);
     $decodedResponse = simplexml_load_string($response->getBody());
     if (!$decodedResponse instanceof \SimpleXMLElement) {
         throw new \Exception('Could not decode response: ' . $response->getBody(), self::ERR_RESPONSE_NOT_XML);
     } else {
         if ($decodedResponse['stat'] == 'ok') {
             if ($async) {
                 return (string) $decodedResponse->ticketid;
             } else {
                 return (string) $decodedResponse->photoid;
             }
         } else {
             throw new \Exception((string) $decodedResponse->err['msg'], (int) $decodedResponse->err['code']);
         }
     }
 }
예제 #22
0
 /**
  * Creates a basic HTTP request
  * @param string $relativeUrl the relative API URL
  * @return \Zend\Http\Request
  */
 protected function createBaseRequest($relativeUrl)
 {
     $baseUrl = $this->getBaseUrl(false);
     $request = new \Zend\Http\Request();
     $request->setUri($baseUrl . $relativeUrl);
     $request->setMethod(\Zend\Http\Request::METHOD_POST);
     $request->getHeaders()->addHeaders(array('Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8', 'Accept-Encoding' => 'identity'));
     // plain text
     $this->addDefaultParameters($request);
     return $request;
 }
예제 #23
0
 /**
  * @param \Zend\Mvc\MvcEvent $event
  * @param $widgets
  */
 public function attachWidgets(\Zend\Mvc\MvcEvent $event, $widgets)
 {
     if (!empty($widgets)) {
         $locator = $event->getTarget()->getLocator();
         /* @var $service \Sysmap\Service\Map */
         $service = $locator->get('sysmap-service');
         foreach ($widgets as $widget) {
             $routeMatch = $service->getRequestByIdentifier($widget->getMapId());
             if (!empty($routeMatch)) {
                 $widgetEvent = new \Zend\Mvc\MvcEvent();
                 $request = new \Zend\Http\Request();
                 $request->setMetadata($routeMatch->getParams());
                 $widgetEvent->setRouteMatch($routeMatch);
                 $widgetEvent->setResponse(new HttpResponse());
                 $controllerName = $routeMatch->getParam('controller');
                 /* @var $controller \Zend\Mvc\Controller\ActionController */
                 $controller = $locator->get($controllerName);
                 $controller->setEvent($widgetEvent);
                 $controller->dispatch($request);
                 $content = $this->renderView($widgetEvent);
                 $this->_layout->setVar($widget->getPlaceholder(), $content);
             }
         }
     }
 }
예제 #24
0
 /**
  * Return browse action from the request.
  *
  * @param Zend\Http\Request $request Request
  *
  * @return null|string Browse action or null if request is not a browse action
  */
 protected function getBrowseAction($request)
 {
     $referer = $request->getServer()->get('HTTP_REFERER');
     $match = null;
     $regex = '/^http[s]?:.*\\/Browse\\/(Database|Journal)[\\/.*]?/';
     if (preg_match($regex, $referer, $match)) {
         return $match[1];
     }
     return null;
 }
 public function getToken($data = null)
 {
     $config = $this->getConfig();
     $request = new \Zend\Http\Request();
     $request->setUri($config['zf-oauth2']['oauthServerUri']);
     $request->setMethod('POST');
     $client = new \Zend\Http\Client();
     $adapter = new \Zend\Http\Client\Adapter\Curl();
     $client->setAdapter($adapter);
     $adapter->setOptions(array('curloptions' => array(CURLOPT_POST => 1, CURLOPT_POSTFIELDS => 'grant_type=client_credentials', CURLOPT_HTTPAUTH => CURLAUTH_BASIC, CURLOPT_USERPWD => $config['zf-oauth2']['client'] . ':' . $config['zf-oauth2']['client_pwd'], CURLOPT_RETURNTRANSFER => 1, CURLOPT_SSL_VERIFYPEER => FALSE, CURLOPT_SSL_VERIFYHOST => FALSE)));
     $response = $client->dispatch($request);
     // I need to extract only the JSon content
     preg_match('~\\{(?:[^{}]|(?R))*\\}~', $response->getContent(), $jsonArray);
     // From the JSonArray I only need the first element - 0
     $response = json_decode($jsonArray[0], true);
     $token = $response['access_token'];
     // Instantiate the AccessTokens Controller in order to be able to update the record
     $OauthAccessTokensController = $this->getServiceLocator()->get('OauthAccessTokensController');
     $OauthAccessTokensController->setValidateOAuth(false);
     $responseOAT = $OauthAccessTokensController->update($token, array(USERID => $data[USERID] . ''));
     if ($responseOAT->getVariable('status') == STATUS_FAILED) {
         // TODO - Log to admin, Something bad happened, this should work without any problem
         throw new \Exception($responseOAT->getVariable('msg'));
     } else {
         $response[USERID] = $data[USERID];
     }
     /*
             if ( $OauthAccessTokensController->getResponse( )->getStatusCode( ) !== 200 ) {
                 // TODO - Log to admin, Something bad happened, this should work without any problem
     			throw new CommonException ( 
     			    array( 
     			        'messageId' => 'globals.query.record_not_found'
     			        ,'parms' => array( 'id' => $token )
     			        ,EXCEPTION_ERRORKEY => 404
     			     ) 
     			 );
             } else {
                 $response[ USERID ] = $data[ USERID ];
             }
     */
     return $response;
 }