/** * * @param <uri> $requestUrl * @return <array> */ public function GetSingedHeaders($requestUrl) { try { return $this->_acsUtil->GetSingedHeaders(); } catch (ACSUtilException $exception) { //re-throw the exception, client should handle this. throw $exception; } }
/** * CallBack fnction, this will be invoked before making request to * OData service. * * @param <type> $httpRequest * @throws ACSUtilException */ function OnBeforeCallBack($httpRequest) { $proxy = new HttpProxy(PROXY_HOST, PROXY_PORT); $acsutil = new ACSUtil(SERVICE_NAMESPACE, ACS_USER, ACS_PWD, ACS_APPLIESTO, array(), $proxy); try { echo 'In callback function' . "<br/>"; //Get the ACS Token $token = $acsutil->GetACSToken(); echo 'Got ACS token:' . "<br/>"; echo $token . "<br/>"; //Format the token in the way ODataService Expects $authHeaderValue = 'WRAP access_token="' . urldecode($token) . '"'; //Add the acs auth header $httpRequest->Headers->Add('authorization', $authHeaderValue); } catch (ACSUtilException $ex) { echo 'Failed to get the ACS token' . "<br/>"; echo $ex->getError(); exit; } }
/** * To retrive the service metadata using Curl. * * @return string */ protected function _getMetaDataOverCurl() { $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $this->_options['/uri_withoutSlash'] . '/' . '$metadata'); curl_setopt($curlHandle, CURLOPT_HEADER, true); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, false); if (isset($this->_options['/auth'])) { switch ($this->_options['/auth']) { case 'windows': curl_setopt($curlHandle, CURLOPT_HTTPAUTH, CURLAUTH_ANY); curl_setopt($curlHandle, CURLOPT_USERPWD, $this->_options['/u'] . ":" . $this->_options['/p']); break; case 'acs': try { $proxy = null; if (isset($this->_options['/ph'])) { $proxy = new HttpProxy($this->_options['/ph'], $this->_options['/pp'], $this->_options['/pu'], $this->_options['/ppwd']); } $acsutil = new ACSUtil($this->_options['/sn'], $this->_options['/u'], $this->_options['/p'], $this->_options['/at'], array(), $proxy); $token = $acsutil->GetACSToken(); $authHeaderValue = 'WRAP access_token="' . urldecode($token) . '"'; curl_setopt($curlHandle, CURLOPT_HTTPHEADER, array('authorization: ' . $authHeaderValue)); } catch (ACSUtilException $exception) { $error = str_replace("<br/>", "\n", $exception->getError()); throw new Exception($error); } break; } } if (isset($this->_options['/ph']) && $this->_options['/ups'] == 'yes') { curl_setopt($curlHandle, CURLOPT_PROXY, $this->_options['/ph'] . ":" . $this->_options['/pp']); if (isset($this->_options['/pu'])) { curl_setopt($curlHandle, CURLOPT_PROXYUSERPWD, $this->_options['/pu'] . ":" . $this->_options['/ppwd']); curl_setopt($curlHandle, CURLOPT_HTTPPROXYTUNNEL, 1); } } $httpRawResponse = curl_exec($curlHandle); if (!$httpRawResponse) { throw new Exception(self::$_messages['Request_Error'] . curl_error($curlHandle)); } $httpResponse = HttpResponse::fromString($httpRawResponse); if ($httpResponse->isError()) { $exception = 'Message:' . $httpResponse->getMessage(); $exception .= "\n\n"; $exception .= $httpResponse->getBody(); throw new Exception($exception); } return $httpResponse->getBody(); }