Пример #1
0
 /**
  * @static
  * @throws 	DataStoreReadException
  * @param 	$consumerKey
  * @param 	$DataStore
  * @return 	OAuthConsumerModel
  */
 public static function loadFromConsumerKey($consumerKey, $DataStore)
 {
     $OAuthConsumer = new OAuthConsumerModel($DataStore);
     $sql = "SELECT *\n\t\t\t\tFROM `oauth_provider_consumer`\n\t\t\t\tWHERE `consumer_key` = '" . $DataStore->real_escape_string($consumerKey) . "'";
     $result = $DataStore->query($sql);
     if (!$result || $result->num_rows < 1) {
         throw new DataStoreReadException("Couldn't read the consumer data from the datastore");
     }
     $data = $result->fetch_assoc();
     $result->close();
     $OAuthConsumer->setId($data['consumer_id']);
     $OAuthConsumer->setConsumerKey($data['consumer_key']);
     $OAuthConsumer->setConsumerSecret($data['consumer_secret']);
     $OAuthConsumer->setConsumerCreateDate($data['consumer_create_date']);
     return $OAuthConsumer;
 }
Пример #2
0
<?php

/**
 * @Author	Freek Lijten
 */
require_once __DIR__ . '/../../lib/AutoLoader.php';
new AutoLoader();
//create consumer model
$Consumer = new OAuthConsumerModel(Configuration::getDataStore());
$Consumer->setConsumerCreateDate(time());
$Consumer->setConsumerKey(OAuthProviderWrapper::generateToken());
$Consumer->setConsumerSecret(OAuthProviderWrapper::generateToken());
try {
    $Consumer->save();
} catch (DataStoreCreateException $Exception) {
    echo $Exception->getMessage();
    exit;
}
echo "Consumer key: " . $Consumer->getConsumerKey() . "<br />Consumer secret: " . $Consumer->getConsumerSecret();
 /**
  * Checks if the provided consumer key is valid and sets the corresponding
  * consumer secret. Used as a callback function.
  *
  * @static
  * @param 	$Provider
  * @return 	int
  */
 public static function consumerHandler($Provider)
 {
     try {
         $DataStore = Configuration::getDataStore();
     } catch (DataStoreConnectException $Exception) {
         // Ideally this exception should be rethrown here but the internals of PECL's OAuth class throw an exception
         // when a non-accepted return value (or no return value) is received. This seems to be winning from exceptions
         // thrown at this point.
         return OAUTH_CONSUMER_KEY_UNKNOWN;
     }
     try {
         $OAuthConsumer = OAuthConsumerModel::loadFromConsumerKey($Provider->consumer_key, $DataStore);
     } catch (DataStoreReadException $Exception) {
         return OAUTH_CONSUMER_KEY_UNKNOWN;
     }
     $Provider->consumer_secret = $OAuthConsumer->getConsumerSecret();
     return OAUTH_OK;
 }