コード例 #1
0
ファイル: OauthPresenter.php プロジェクト: osmcz/website
 public function startup()
 {
     parent::startup();
     $this->config = $this->context->parameters['osm_oauth'];
     $this->oauth = new OAuth($this->config['consumer_key'], $this->config['consumer_secret'], OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
     $this->oauth->disableSSLChecks();
 }
コード例 #2
0
 function do_recharge_request($param)
 {
     $random_number = rand(5, 10);
     $transaction_id = "abc" . $random_number;
     // string. Number not allowed
     //$db->insert("recharge_test_table",array("trans_id" => $transaction_id,"time"=>time()));
     $oauth_consumer_key = $client_id = $consumer_key = "spacepoint_nigeria_demo_user1";
     $oauth_consumer_secret = $client_secret = $consumer_secret = "wltJSD3ztLKfBQmIW32iSGfcrwe3okS0";
     $username = "******";
     //		$msisdn = "2348059827239"; // mobile number +234-8059827239
     //		$msisdn = "2340123456789";
     $msisdn = "234" . $param['mobile_no'];
     //		$face_value = 5000;
     $face_value = (int) $param['amount'];
     //$face_value *= 100;
     $supplier_api = "ttdemo_v1";
     $product_info = array("product" => "airtime");
     //	echo $face_value;
     //	echo " ";
     //	echo $msisdn;exit;
     try {
         $params = array("username" => $username, "msisdn" => $msisdn, "transaction_id" => $transaction_id, "face_value" => $face_value, "supplier_api" => $supplier_api, "product_info" => $product_info);
         $request = new OAuth($oauth_consumer_key, $oauth_consumer_secret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
         //print_r($request);
         $request->disableSSLChecks();
         $request->fetch("https://hsc16.miranetworks.net:16000/v1/recharge", json_encode($params), OAUTH_HTTP_METHOD_POST, array("Content-Type" => "application/json"));
         return $response = $request->getLastResponse();
         //echo $response;
         //			echo "<pre>";
         //			print_r($response);
         //			return $response;
     } catch (Exception $e) {
         return 'Message: ' . $e->getMessage();
     }
 }
コード例 #3
0
 public function REST_Request($callbackUrl, $url, $method, $data = array())
 {
     /**
      * Example of simple product POST using Admin account via Magento REST API. OAuth authorization is used
      */
     $callbackUrl = $callbackUrl;
     $temporaryCredentialsRequestUrl = $this->conf['magento_host'] . "/oauth/initiate?oauth_callback=" . urlencode($callbackUrl);
     $adminAuthorizationUrl = $this->conf['magento_host'] . '/admin/oauth_authorize';
     $accessTokenRequestUrl = $this->conf['magento_host'] . '/oauth/token';
     $apiUrl = $this->conf['magento_host'] . '/api/rest';
     $consumerKey = $this->conf['magentosoap_consumerKey'];
     $consumerSecret = $this->conf['magentosoap_consumerSecret'];
     $AccessToken = $this->conf["magentosoap_AccessToken"];
     $AccessSecret = $this->conf["magentosoap_AccessSecret"];
     try {
         //$_SESSION['state'] = 2;
         $authType = 2 == 2 ? OAUTH_AUTH_TYPE_AUTHORIZATION : OAUTH_AUTH_TYPE_URI;
         $oauthClient = new OAuth($consumerKey, $consumerSecret, OAUTH_SIG_METHOD_HMACSHA1, $authType);
         $oauthClient->enableDebug();
         $oauthClient->disableSSLChecks();
         $oauthClient->setToken($AccessToken, $AccessSecret);
         $resourceUrl = $apiUrl . $url;
         $oauthClient->fetch($resourceUrl, $data, strtoupper($method), array("Content-Type" => "application/json", "Accept" => "*/*"));
         //$oauthClient->fetch($resourceUrl);
         $ret = json_decode($oauthClient->getLastResponse());
         $ret = array("error" => 0, "data" => $ret);
         return $ret;
     } catch (OAuthException $e) {
         $ret = array("error" => 1, "message" => "Checking quantity failed");
         return $ret;
     }
 }
 public function GetReportsResponse($requestParameters, $requestBody, $oauthRequestUri)
 {
     $this->context->IppConfiguration->Logger->CustomLogger->Log(TraceLevel::Info, "Called PrepareRequest method");
     // This step is required since the configuration settings might have been changed.
     $this->RequestCompressor = CoreHelper::GetCompressor($this->context, true);
     $this->ResponseCompressor = CoreHelper::GetCompressor($this->context, false);
     $this->RequestSerializer = CoreHelper::GetSerializer($this->context, true);
     $this->ResponseSerializer = CoreHelper::GetSerializer($this->context, false);
     // Determine dest URI
     $requestUri = '';
     if ($requestParameters->ApiName) {
         // Example: "https://appcenter.intuit.com/api/v1/Account/AppMenu"
         $requestUri = $this->context->baseserviceURL . $requestParameters->ApiName;
     } else {
         if ($oauthRequestUri) {
             // Prepare the request Uri from base Uri and resource Uri.
             $requestUri = $oauthRequestUri;
         } else {
             if ($requestParameters->ResourceUri) {
                 $requestUri = $this->context->baseserviceURL . $requestParameters->ResourceUri;
             } else {
             }
         }
     }
     $oauth = new OAuth($this->context->requestValidator->ConsumerKey, $this->context->requestValidator->ConsumerSecret);
     $oauth->setToken($this->context->requestValidator->AccessToken, $this->context->requestValidator->AccessTokenSecret);
     $oauth->enableDebug();
     $oauth->setAuthType(OAUTH_AUTH_TYPE_AUTHORIZATION);
     $oauth->disableSSLChecks();
     $httpHeaders = array();
     if ('QBO' == $this->context->serviceType || 'QBD' == $this->context->serviceType) {
         // IDS call
         $httpHeaders = array('accept' => 'application/json');
         // Log Request Body to a file
         $this->RequestLogging->LogPlatformRequests($requestBody, $requestUri, $httpHeaders, TRUE);
         if ($this->ResponseCompressor) {
             $this->ResponseCompressor->PrepareDecompress($httpHeaders);
         }
     } else {
         // IPP call
         $httpHeaders = array('accept' => 'application/json');
     }
     try {
         $OauthMethod = OAUTH_HTTP_METHOD_GET;
         $oauth->fetch($requestUri, $requestBody, $OauthMethod, $httpHeaders);
     } catch (OAuthException $e) {
         //echo "ERROR:\n";
         //print_r($e->getMessage()) . "\n";
         list($response_code, $response_xml, $response_headers) = $this->GetOAuthResponseHeaders($oauth);
         $this->RequestLogging->LogPlatformRequests($response_xml, $requestUri, $response_headers, FALSE);
         return FALSE;
     }
     list($response_code, $response_xml, $response_headers) = $this->GetOAuthResponseHeaders($oauth);
     // Log Request Body to a file
     $this->RequestLogging->LogPlatformRequests($response_xml, $requestUri, $response_headers, FALSE);
     return array($response_code, $response_xml);
 }
コード例 #5
0
ファイル: get_request_token.php プロジェクト: noxfate/gtc
            if ($_GET['scope'] == 'none') {
                $scope = array();
            }
        }
    }
    $scope = json_encode($scope);
    $requestURL .= '?scope=' . urlencode($scope);
}
session_start();
$tokenInfo = null;
try {
    $OAuth = new OAuth($consumerKey, $consumerSecret);
    $OAuth->enableDebug();
    // SSL CA Signed
    if ($self_signed) {
        $OAuth->disableSSLChecks();
    }
    $tokenInfo = $OAuth->getRequestToken($requestURL, $callbackURL);
} catch (Exception $E) {
    echo '<h1>There was an error getting the Request Token</h1>';
    echo '<pre>';
    echo "Message:\n";
    print_r($E->getMessage());
    echo "\n\nLast Response:\n";
    print_r($OAuth->getLastResponse());
    echo "\n\nLast Response Info:\n";
    print_r($OAuth->getLastResponseInfo());
    echo "\n\nDebug Info:\n";
    print_r($OAuth->debugInfo);
    // get info about headers
    echo '</pre>';
コード例 #6
0
 a- Get a 'request token' from the system
 b- Authorize the received token. Note here that Autodesk currently require you to manual log on Oxygen
      for authorization. This is why the sample is using your default browser for logging.
 c- Get an 'access token' and a session
 The sample also does a log-out at the end to complete the sample.
*/
define('DefaultBrowser', '"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe" ');
define('ConsumerKey', 'Your Consumer Key');
define('ConsumerSecret', 'Your Consumer Secret Key');
define('BaseUrl', 'The Oauth server URL');
// https://accounts.autodesk.com/ or https://accounts-staging.autodesk.com/
//- Prepare the PHP OAuth for consuming our Oxygen service
//- Disable the SSL check to avoid an exception with invalidate certificate on the server
$oauth = new OAuth(ConsumerKey, ConsumerSecret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
$oauth->enableDebug();
$oauth->disableSSLChecks();
//- 1st leg: Get the 'request token'
$token = '';
try {
    $token = $oauth->getRequestToken(BaseUrl . "OAuth/RequestToken");
    echo "OAuth/RequestToken response\n", "\toauth_token: {$token['oauth_token']}\n", "\toauth_token_secret: {$token['oauth_token_secret']}\n", "-----------------------\n\n";
    //- Set the token and secret for subsequent requests.
    $oauth->setToken($token['oauth_token'], $token['oauth_token_secret']);
} catch (OAuthException $e) {
    echo "OAuth/RequestToken\n", 'Caught exception: ', $e->getMessage(), "\n";
    exit;
}
//- 2nd leg: Authorize the token
//- Currently, Autodesk Oxygen service requires you to manually log into the system, so we are using your default browser
try {
    $url = BaseUrl . "OAuth/Authorize" . "?oauth_token=" . urlencode(stripslashes($token['oauth_token']));
コード例 #7
0
 /**
  * Returns the response by calling REST service.
  *
  * @param ServiceContext $requestParameters The parameters
  * @param string $requestBody The request body
  * @param string $oauthRequestUri The OAuth request uri
  * @return array elements are 0: HTTP response code; 1: HTTP response body
  */
 public function GetResponse($requestParameters, $requestBody, $oauthRequestUri)
 {
     $this->context->IppConfiguration->Logger->CustomLogger->Log(TraceLevel::Info, "Called PrepareRequest method");
     // This step is required since the configuration settings might have been changed.
     $this->RequestCompressor = CoreHelper::GetCompressor($this->context, true);
     $this->ResponseCompressor = CoreHelper::GetCompressor($this->context, false);
     $this->RequestSerializer = CoreHelper::GetSerializer($this->context, true);
     $this->ResponseSerializer = CoreHelper::GetSerializer($this->context, false);
     // Determine dest URI
     $requestUri = '';
     if ($requestParameters->ApiName) {
         // Example: "https://appcenter.intuit.com/api/v1/Account/AppMenu"
         $requestUri = $this->context->baseserviceURL . $requestParameters->ApiName;
     } else {
         if ($oauthRequestUri) {
             // Prepare the request Uri from base Uri and resource Uri.
             $requestUri = $oauthRequestUri;
         } else {
             if ($requestParameters->ResourceUri) {
                 $requestUri = $this->context->baseserviceURL . $requestParameters->ResourceUri;
             } else {
             }
         }
     }
     //minorVersion support
     if ($this->context->minorVersion) {
         if ($this->queryToArray($requestUri) == false) {
             $requestUri .= "?minorversion=" . $this->context->minorVersion;
         } else {
             $requestUri .= "&minorversion=" . $this->context->minorVersion;
         }
     }
     $oauth = new OAuth($this->context->requestValidator->ConsumerKey, $this->context->requestValidator->ConsumerSecret);
     $oauth->setToken($this->context->requestValidator->AccessToken, $this->context->requestValidator->AccessTokenSecret);
     $oauth->enableDebug();
     $oauth->setAuthType(OAUTH_AUTH_TYPE_AUTHORIZATION);
     $oauth->disableSSLChecks();
     $httpHeaders = array();
     if ('QBO' == $this->context->serviceType || 'QBD' == $this->context->serviceType) {
         // IDS call
         $httpHeaders = array('host' => parse_url($requestUri, PHP_URL_HOST), 'user-agent' => CoreConstants::USERAGENT, 'accept' => '*/*', 'connection' => 'close', 'content-type' => $requestParameters->ContentType, 'content-length' => strlen($requestBody));
         // Log Request Body to a file
         $this->RequestLogging->LogPlatformRequests($requestBody, $requestUri, $httpHeaders, TRUE);
         if ($requestBody && $this->RequestCompressor) {
             $this->RequestCompressor->Compress($httpHeaders, $requestBody);
         }
         if ($this->ResponseCompressor) {
             $this->ResponseCompressor->PrepareDecompress($httpHeaders);
         }
     } else {
         // IPP call
         $httpHeaders = array('user-agent' => CoreConstants::USERAGENT);
     }
     try {
         if ('POST' == $requestParameters->HttpVerbType) {
             $OauthMethod = OAUTH_HTTP_METHOD_POST;
         } else {
             if ('GET' == $requestParameters->HttpVerbType) {
                 $OauthMethod = OAUTH_HTTP_METHOD_GET;
             }
         }
         $oauth->fetch($requestUri, $requestBody, $OauthMethod, $httpHeaders);
     } catch (OAuthException $e) {
         //echo "ERROR:\n";
         //print_r($e->getMessage()) . "\n";
         list($response_code, $response_xml, $response_headers) = $this->GetOAuthResponseHeaders($oauth);
         $this->RequestLogging->LogPlatformRequests($response_xml, $requestUri, $response_headers, FALSE);
         //echo "Response: {$response_code} - {$response_xml} \n";
         //var_dump($oauth->debugInfo);
         //echo "\n";
         //echo "ERROR MESSAGE: " . $oauth->debugInfo['body_recv'] . "\n"; // Useful info from Intuit
         //echo "\n";
         return FALSE;
     }
     list($response_code, $response_xml, $response_headers) = $this->GetOAuthResponseHeaders($oauth);
     // Log Request Body to a file
     $this->RequestLogging->LogPlatformRequests($response_xml, $requestUri, $response_headers, FALSE);
     return array($response_code, $response_xml);
 }
コード例 #8
0
ファイル: OAuth1.php プロジェクト: odesk/php-odesk
 /**
  * Get OAuth instance
  *
  * @param   integer $authType Auth type
  * @access  protected
  * @return  object
  */
 protected function _getOAuthInstance($authType)
 {
     ApiDebug::p('get OAuth instance');
     $oauth = new \OAuth(self::$_apiKey, self::$_secret, self::$_sigMethod, $authType);
     if (ApiConfig::get('debug')) {
         $oauth->enableDebug();
     }
     if (!self::$_verifySsl) {
         $oauth->disableSSLChecks();
     }
     return $oauth;
 }
コード例 #9
0
 /**
  * Get the instance of fully configured OAuth class
  *
  * @access private
  * @return OAuth
  */
 private function getOauth()
 {
     if (!$this->oauth) {
         $oauth = new OAuth($this->context->requestValidator->ConsumerKey, $this->context->requestValidator->ConsumerSecret);
         $oauth->setToken($this->context->requestValidator->AccessToken, $this->context->requestValidator->AccessTokenSecret);
         $oauth->enableDebug();
         $oauth->setAuthType(OAUTH_AUTH_TYPE_AUTHORIZATION);
         $oauth->disableSSLChecks();
         $this->setOauth($oauth);
     }
     return $this->oauth;
 }
コード例 #10
0
ファイル: CopyInterface.php プロジェクト: noxfate/gathercloud
 private function requestAccessToken($oauth_token)
 {
     // URL
     $accessURL = "https://{$this->server}/oauth/access";
     // Get Access Token Flow
     session_start();
     try {
         $OAuth = new \OAuth($this->consumerKey, $this->consumerSecret);
         if ($this->self_signed) {
             $OAuth->disableSSLChecks();
         }
         $OAuth->setToken($oauth_token, $_SESSION['oauth_token_secret']);
         $OAuth->enableDebug();
         $tokenInfo = $OAuth->getAccessToken($accessURL);
         $response_body = $OAuth->getLastResponse();
         $response = $OAuth->getLastResponseInfo();
         $debug = $OAuth->debugInfo;
         // Open and decode the file
         //            $data = json_decode(file_get_contents('keys.json'));
         //
         //            if (!isset($data->consumer) || !isset($data->access)) {
         //                die("Someone has deleted the consumer field during the OAuth handshake.");
         //            }
         //
         //            // Setting new data
         //            $data->access->token = $tokenInfo['oauth_token'];
         //            $data->access->secret = $tokenInfo['oauth_token_secret'];
         //
         //            // encode
         //            $new_data = json_encode($data);
         //
         //            // write contents to the file
         //            $handle = fopen('keys.json', 'w');
         //            fwrite($handle, $new_data);
         //            fclose($handle);
         $access = array("token" => $tokenInfo['oauth_token'], "secret" => $tokenInfo['oauth_token_secret']);
     } catch (Exception $E) {
         echo "<pre>OAuth ERROR MESSAGE:\n";
         echo $E->getMessage();
         echo "\nRESPONSE:\n";
         var_dump($OAuth->getLastResponse());
         echo "\nRESPONSE INFO:\n";
         var_dump($OAuth->getLastResponseInfo());
         echo '</pre>';
     }
     return $access;
 }