/**
  * @param Application $app
  */
 public function register(Application $app)
 {
     $app['culturefeed_token_credentials'] = $app->share(function (Application $app) {
         /* @var UserSessionService $userSessionService */
         $userSessionService = $app['uitid_user_session_service'];
         $user = $userSessionService->getMinimalUserInfo();
         if (!is_null($user)) {
             return $user->getTokenCredentials();
         } else {
             return null;
         }
     });
     $app['culturefeed_consumer_credentials'] = $app->share(function (Application $app) {
         return new ConsumerCredentials($app['culturefeed.consumer.key'], $app['culturefeed.consumer.secret']);
     });
     $app['culturefeed'] = $app->share(function (Application $app) {
         return new \CultureFeed($app['culturefeed_oauth_client']);
     });
     $app['culturefeed_oauth_client'] = $app->share(function (Application $app) {
         /* @var ConsumerCredentials $consumerCredentials */
         $consumerCredentials = $app['culturefeed_consumer_credentials'];
         /* @var TokenCredentials $tokenCredentials */
         $tokenCredentials = $app['culturefeed_token_credentials'];
         $userCredentialsToken = null;
         $userCredentialsSecret = null;
         if ($tokenCredentials) {
             $userCredentialsToken = $tokenCredentials->getToken();
             $userCredentialsSecret = $tokenCredentials->getSecret();
         }
         $oauthClient = new \CultureFeed_DefaultOAuthClient($consumerCredentials->getKey(), $consumerCredentials->getSecret(), $userCredentialsToken, $userCredentialsSecret);
         $oauthClient->setEndpoint($app['culturefeed.endpoint']);
         return $oauthClient;
     });
 }
 /**
  * @param Application $app
  */
 public function register(Application $app)
 {
     $app['culturefeed_consumer_credentials'] = $app->share(function (Application $app) {
         return new ConsumerCredentials($app['culturefeed.consumer.key'], $app['culturefeed.consumer.secret']);
     });
     $app['culturefeed_token_credentials'] = $app->share(function (Application $app) {
         // Check first if we're impersonating someone.
         /* @var Impersonator $impersonator */
         $impersonator = $app['impersonator'];
         if ($impersonator->getTokenCredentials()) {
             return $impersonator->getTokenCredentials();
         }
         $jwt = $app['jwt'];
         if (is_null($jwt)) {
             // Not authenticated.
             return null;
         }
         /* @var UiTIDCredentialsFetcher $uitidCredentialsFetcher */
         $uitidCredentialsFetcher = $app['oauth.fetcher'];
         $accessToken = $uitidCredentialsFetcher->getAccessTokenFromJwt((string) $jwt);
         return new TokenCredentials($accessToken->getToken(), $accessToken->getTokenSecret());
     });
     $app['culturefeed'] = $app->share(function (Application $app) {
         return new \CultureFeed($app['culturefeed_oauth_client']);
     });
     $app['culturefeed_oauth_client'] = $app->share(function (Application $app) {
         /* @var ConsumerCredentials $consumerCredentials */
         $consumerCredentials = $app['culturefeed_consumer_credentials'];
         /* @var TokenCredentials $tokenCredentials */
         $tokenCredentials = $app['culturefeed_token_credentials'];
         $userCredentialsToken = null;
         $userCredentialsSecret = null;
         if ($tokenCredentials) {
             $userCredentialsToken = $tokenCredentials->getToken();
             $userCredentialsSecret = $tokenCredentials->getSecret();
         }
         $oauthClient = new \CultureFeed_DefaultOAuthClient($consumerCredentials->getKey(), $consumerCredentials->getSecret(), $userCredentialsToken, $userCredentialsSecret);
         $oauthClient->setEndpoint($app['culturefeed.endpoint']);
         return $oauthClient;
     });
 }
date_default_timezone_set('Europe/Brussels');
// require the third-party oauth library which is not properly structured to be autoloaded
require_once dirname(__FILE__) . '/../../OAuth/OAuth.php';
function culturefeed_autoload($class)
{
    $file = str_replace('_', '/', $class) . '.php';
    require_once $file;
}
spl_autoload_register('culturefeed_autoload');
try {
    $endpoint = $_SERVER['argv'][1];
    $consumer_key = $_SERVER['argv'][2];
    $consumer_secret = $_SERVER['argv'][3];
    $query = new CultureFeed_Uitpas_Passholder_Query_SearchPromotionPointsOptions();
    $oc = new CultureFeed_DefaultOAuthClient($consumer_key, $consumer_secret);
    $oc->setEndpoint($endpoint);
    $c = new CultureFeed($oc);
    $promotions = $c->uitpas()->getPromotionPoints($query);
    print_r($promotions);
} catch (Exception $e) {
    $eol = PHP_EOL;
    $type = get_class($e);
    print "An exception of type {$type} was thrown." . PHP_EOL;
    print "Code: {$e->getCode()}" . PHP_EOL;
    if ($e instanceof CultureFeed_Exception) {
        print "CultureFeed error code: {$e->error_code}" . PHP_EOL;
    }
    print "Message: {$e->getMessage()}" . PHP_EOL;
    print "Stack trace: {$eol}{$e->getTraceAsString()}" . PHP_EOL;
    exit(1);
}
 //$_SESSION['oauth_token'] = $token['oauth_token'];
 //$_SESSION['oauth_token_secret'] = $token['oauth_token_secret'];
 // Fetch the authorisation url...
 $auth_url = $c->getUrlAuthorize($token, $callback_url, CultureFeed::AUTHORIZE_TYPE_REGULAR);
 print "Now open the following URL in your browser: {$auth_url}" . PHP_EOL;
 print "After logging in with your UiTID you should inspect your RequestBin and find there the last request with an oauth_token and oauth_verifier." . PHP_EOL;
 print "Make sure the you have identified the right request, containing the oauth token: {$token['oauth_token']}" . PHP_EOL;
 print "Give me the oauth_verifier value now: ";
 $oauth_verifier = fgets(STDIN);
 $oauth_verifier = trim($oauth_verifier);
 $user_oauth_client = new CultureFeed_DefaultOAuthClient($consumer_key, $consumer_secret, $token['oauth_token'], $token['oauth_token_secret']);
 $user_oauth_client->setEndpoint($endpoint);
 $user_c = new CultureFeed($user_oauth_client);
 $new_token = $user_c->getAccessToken($oauth_verifier);
 $new_user_oauth_client = new CultureFeed_DefaultOAuthClient($consumer_key, $consumer_secret, $new_token['oauth_token'], $new_token['oauth_token_secret']);
 $new_user_oauth_client->setEndpoint($endpoint);
 $new_user_c = new CultureFeed($new_user_oauth_client);
 $account = $new_user_c->getUser($new_token['userId']);
 print "You have succesfully logged in with the following account: {$account->nick} [{$account->id}]" . PHP_EOL;
 print "Setting user preferences" . PHP_EOL;
 $preferences = new CultureFeed_Preferences();
 $preferences->activityPrivacyPreferences[] = new CultureFeed_ActivityPrivacyPreference(CultureFeed_Activity::TYPE_UITPAS, FALSE);
 $preferences = $new_user_c->setUserPreferences($account->id, $preferences);
 if (count($preferences->activityPrivacyPreferences) == 0) {
     print "No user preferences found" . PHP_EOL;
 } else {
     print "User preferences:" . PHP_EOL;
     foreach ($preferences->activityPrivacyPreferences as $preference) {
         $private = $preference->private ? "private" : "public";
         print "{$preference->activityType}: {$private}" . PHP_EOL;
     }
Ejemplo n.º 5
0
    $delay = 4;
    $eventBusForwardingConsumer = new \CultuurNet\UDB3\UDB2\AMQP\EventBusForwardingConsumer($connection, $app['event_bus'], $deserializerLocator, new String($amqpConfig['consumer_tag']), new String($consumeConfig['exchange']), new String($consumeConfig['queue']), $delay);
    $logger = new Monolog\Logger('amqp.event_bus_forwarder');
    $logger->pushHandler(new \Monolog\Handler\StreamHandler('php://stdout'));
    $logFileHandler = new \Monolog\Handler\StreamHandler(__DIR__ . '/log/amqp.log', \Monolog\Logger::DEBUG);
    $logger->pushHandler($logFileHandler);
    $eventBusForwardingConsumer->setLogger($logger);
    return $connection;
});
$app['culturefeed'] = $app->share(function (Application $app) {
    $uitidConfig = $app['config']['uitid'];
    $baseUrl = $uitidConfig['base_url'];
    /** @var \CultuurNet\Auth\ConsumerCredentials $consumerCredentials */
    $consumerCredentials = $app['uitid_consumer_credentials'];
    $oauthClient = new \CultureFeed_DefaultOAuthClient($consumerCredentials->getKey(), $consumerCredentials->getSecret());
    $oauthClient->setEndpoint($baseUrl);
    $cultureFeed = new \CultureFeed($oauthClient);
    return $cultureFeed;
});
$app['uitpas'] = $app->share(function (Application $app) {
    /** @var CultureFeed $culturefeed */
    $cultureFeed = $app['culturefeed'];
    return $cultureFeed->uitpas();
});
$app['logger.uitpas'] = $app->share(function (Application $app) {
    $logger = new Monolog\Logger('uitpas');
    $logger->pushHandler(new \Monolog\Handler\StreamHandler(__DIR__ . '/log/uitpas.log'));
    return $logger;
});
// This service is used by the background worker to impersonate the user
// who initially queued the command.
 /**
  * Get an OAuthClient instance for CultureFeed.
  * @param string $endpoint
  *   Endpoint for the client.
  */
 public static function getOAuthClient($endpoint, $token, $secret, $application_key = NULL, $shared_secret = NULL)
 {
     if (!$application_key) {
         $application_key = variable_get('culturefeed_api_application_key', '');
         $shared_secret = variable_get('culturefeed_api_shared_secret', '');
     }
     $oauth_client = new CultureFeed_DefaultOAuthClient($application_key, $shared_secret, $token, $secret);
     $oauth_client->setEndpoint($endpoint);
     $http_client_factory = static::getHttpClientFactory();
     if (!$http_client_factory) {
         $http_client = new CultureFeed_DefaultHttpClient();
         // Enable the logging.
         // We only do this when the default HTTP client is used, because
         // the HttpClient interface does not have a enableLogging() method
         // and a logger is actually something that should be injected through
         // dependency injection.
         if (module_exists('culturefeed_devel')) {
             $http_client->enableLogging();
         }
     } else {
         $http_client = $http_client_factory->createHttpClient();
     }
     $http_client->setTimeout(variable_get('culturefeed_http_client_timeout', 10));
     if ($http_client instanceof CultureFeed_ProxySupportingClient) {
         $uri = @parse_url($endpoint);
         $proxy_server = variable_get('proxy_server', '');
         if ($proxy_server && (!is_callable('_drupal_http_use_proxy') || _drupal_http_use_proxy($uri['host']))) {
             $http_client->setProxyServer($proxy_server);
             $http_client->setProxyPort(variable_get('proxy_port', 8080));
             $http_client->setProxyUsername(variable_get('proxy_username', ''));
             $http_client->setProxyPassword(variable_get('proxy_password', ''));
         }
     }
     $oauth_client->setHttpClient($http_client);
     return $oauth_client;
 }