コード例 #1
0
ファイル: TokenCommand.php プロジェクト: cultuurnet/auth
 public function execute(InputInterface $in, OutputInterface $out)
 {
     parent::execute($in, $out);
     $consumer = $this->session->getConsumerCredentials();
     $authBaseUrl = $this->resolveBaseUrl('auth', $in);
     $authService = $this->authServiceFactory->createService($in, $out, $authBaseUrl, $consumer);
     $temporaryCredentials = $authService->getRequestToken();
     $out->writeln($temporaryCredentials->getToken());
 }
コード例 #2
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     parent::execute($input, $output);
     $baseUrl = $this->resolveBaseUrl('auth', $input);
     $consumerCredentials = $this->session->getConsumerCredentials();
     $fetcher = new UitidCredentialsFetcher($baseUrl, $consumerCredentials);
     $consumerKey = $input->getArgument('consumer');
     $consumer = $fetcher->getConsumer($consumerKey);
     $output->writeln('consumer key: ' . $consumer->getKey());
     $output->writeln('consumer name: ' . $consumer->getName());
     $output->writeln('consumer secret: ' . $consumer->getSecret());
 }
コード例 #3
0
ファイル: SuggestCommand.php プロジェクト: cultuurnet/search
 public function execute(InputInterface $in, OutputInterface $out)
 {
     parent::execute($in, $out);
     $searchBaseUrl = $this->resolveBaseUrl('search', $in);
     $user = $this->session->getUser();
     $tokenCredentials = NULL !== $user ? $user->getTokenCredentials() : NULL;
     $service = new Service($searchBaseUrl, $this->session->getConsumerCredentials(), $tokenCredentials);
     $query = $in->getArgument('query');
     $types = $in->getOption('type');
     $suggestionsResult = $service->searchSuggestions($query, $types);
     $suggestions = $suggestionsResult->getSuggestions();
     $out->writeln($suggestions);
 }
コード例 #4
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     parent::execute($input, $output);
     $baseUrl = $this->resolveBaseUrl('auth', $input);
     $consumerCredentials = $this->session->getConsumerCredentials();
     $fetcher = new UitidCredentialsFetcher($baseUrl, $consumerCredentials);
     $tokenKey = $input->getArgument('token');
     $token = $fetcher->getAccessToken($tokenKey);
     $output->writeln('token: ' . $token->getToken());
     $output->writeln('token secret: ' . $token->getTokenSecret());
     $output->writeln('consumer key: ' . $token->getConsumer()->getKey());
     $output->writeln('consumer name: ' . $token->getConsumer()->getName());
     $output->writeln('consumer secret: ' . $token->getConsumer()->getSecret());
     $output->writeln('user uid: ' . $token->getUser()->getUid());
     $output->writeln('user nick: ' . $token->getUser()->getNick());
     $output->writeln('user email: ' . $token->getUser()->getEmail());
 }
コード例 #5
0
 protected function execute(InputInterface $in, OutputInterface $out)
 {
     parent::execute($in, $out);
     $consumer = $this->session->getConsumerCredentials();
     $authBaseUrl = $this->resolveBaseUrl('auth', $in);
     $authService = $this->authenticateServiceFactory->createService($in, $out, $authBaseUrl, $consumer);
     $callback = $in->getOption('callback');
     $temporaryCredentials = $authService->getRequestToken($callback);
     $client = new Client($authBaseUrl, array('redirect.disable' => true));
     // @todo check if logging in on UiTiD requires cookies?
     $cookiePlugin = new CookiePlugin(new ArrayCookieJar());
     $client->addSubscriber($cookiePlugin);
     $user = $in->getOption('username');
     $password = $in->getOption('password');
     $dialog = $this->getHelperSet()->get('dialog');
     /* @var \Symfony\Component\Console\Helper\DialogHelper $dialog */
     while (NULL === $user) {
         $user = $dialog->ask($out, 'User name: ');
     }
     while (NULL === $password) {
         $password = $dialog->askHiddenResponse($out, 'Password: '******'email' => $user, 'password' => $password, 'submit' => 'Aanmelden', 'token' => $temporaryCredentials->getToken());
     $response = $client->post('auth/login', NULL, $postData)->send();
     // @todo check what happens if the app is already authorized
     $postData = array('allow' => 'true', 'token' => $temporaryCredentials->getToken());
     $response = $client->post('auth/authorize', NULL, $postData)->send();
     $location = $response->getHeader('Location', true);
     $url = Url::factory($location);
     $oAuthVerifier = $url->getQuery()->get('oauth_verifier');
     $user = $authService->getAccessToken($temporaryCredentials, $oAuthVerifier);
     $this->session->setUser($user);
     $out->writeln('user id: ' . $user->getId());
     $out->writeln('access token: ' . $user->getTokenCredentials()->getToken());
     $out->writeln('access token secret: ' . $user->getTokenCredentials()->getSecret());
     $sessionFile = $in->getOption('session');
     if (NULL !== $sessionFile) {
         JsonSessionFile::write($this->session, $sessionFile);
     }
 }
コード例 #6
0
ファイル: GetCommand.php プロジェクト: cultuurnet/search
 public function execute(InputInterface $input, OutputInterface $output)
 {
     parent::execute($input, $output);
     $searchBaseUrl = $this->resolveBaseUrl('search', $input);
     $user = $this->session->getUser();
     $tokenCredentials = NULL !== $user ? $user->getTokenCredentials() : NULL;
     $clientFactory = new DefaultHttpClientFactory();
     $client = $clientFactory->createClient($searchBaseUrl, $this->session->getConsumerCredentials(), $tokenCredentials);
     $request = $client->get($input->getArgument('path'));
     // @todo add query parameters, from JSON and/or yaml file or from simple CLI options
     //$getRequest->getQuery()->set($key, $value);
     $queryFile = $input->getOption('query-file');
     if (NULL !== $queryFile) {
         $json = file_get_contents($queryFile);
         $config = json_decode($json, TRUE);
         foreach ($config as $key => $value) {
             $request->getQuery()->add($key, $value);
         }
     }
     try {
         $response = $request->send();
         $output->writeln('');
         $output->writeln('');
         $output->writeln('Request');
         $output->writeln('');
         $output->writeln((string) $request);
         $output->writeln('');
         $output->writeln('');
         $output->writeln('Response');
         $output->writeln('');
         $output->writeln((string) $response);
         $output->writeln('');
         $output->writeln('');
     } catch (ClientErrorResponseException $e) {
         $output->writeln((string) $e->getRequest());
         $output->writeln((string) $e->getResponse());
     }
 }
コード例 #7
0
ファイル: SearchCommand.php プロジェクト: cultuurnet/search
 public function execute(InputInterface $in, OutputInterface $out)
 {
     parent::execute($in, $out);
     $searchBaseUrl = $this->resolveBaseUrl('search', $in);
     $user = $this->session->getUser();
     $tokenCredentials = NULL !== $user ? $user->getTokenCredentials() : NULL;
     $consumerCredentials = $this->session->getConsumerCredentials();
     $service = $this->searchServiceFactory->createService($in, $out, $searchBaseUrl, $consumerCredentials, $tokenCredentials);
     $query = new Parameter\Query($in->getArgument('query'));
     $parameters = array($query);
     $facets = $in->getOption('facetField');
     if (!empty($facets)) {
         $facetComponent = new FacetComponent();
         foreach ($facets as $facet) {
             $parameters[] = $facetComponent->facetField($facet);
         }
     }
     $fq = $in->getOption('fq');
     if ($fq) {
         $parameters[] = new Parameter\FilterQuery($fq);
     }
     if ($in->getOption('group')) {
         $parameters[] = new Parameter\Group();
     }
     if ($in->getOptions('rows')) {
         $parameters[] = new Parameter\Rows($in->getOption('rows'));
     }
     if ($in->getOption('start')) {
         $parameters[] = new Parameter\Start($in->getOption('start'));
     }
     $sorts = $in->getOption('sort');
     foreach ($sorts as $sort) {
         // @todo validate the given sort option
         $sort_args = explode(' ', $sort);
         if (count($sort_args) < 2) {
             $sort_args[] = 'asc';
         }
         list($field, $direction) = $sort_args;
         $parameters[] = new Parameter\Sort($field, $direction);
     }
     $result = $service->search($parameters);
     $out->writeln('total: ' . $result->getTotalCount());
     $out->writeln('current: ' . $result->getCurrentCount());
     // @todo consider registering the facet component up-front
     // as a listener to the service, to avoid the need to actively
     // obtain the results afterwards
     if (isset($facetComponent)) {
         $facetComponent->obtainResults($result);
         foreach ($facetComponent->getFacets() as $facet) {
             $out->writeln(str_repeat('-', 10));
             $out->writeln('Facet: ' . $facet->getKey());
             $out->writeln('Results:');
             foreach ($facet->getResult()->getItems() as $name => $number) {
                 $out->writeln("{$name} ({$number})");
             }
             $out->writeln(str_repeat('-', 10));
         }
     }
     $currentCount = $result->getCurrentCount();
     if (0 === $currentCount) {
         return;
     }
     $dialog = $this->getHelperSet()->get('dialog');
     /* @var \Symfony\Component\Console\Helper\DialogHelper $dialog */
     // @todo provide misc. interactive options, like showing summary of all results
     //   and to show details of 1 item (implemented now)
     //   repeat till 'exit' option is used
     do {
         $answer = $dialog->askAndValidate($out, "Specify a number (1 to {$currentCount}) to show details, or 'exit' to quit: ", function ($answer) use($currentCount) {
             if (!(ctype_digit($answer) && $answer > 0 && $answer <= $currentCount) && 'exit' !== $answer) {
                 throw new \RuntimeException('Invalid value');
             }
             return $answer;
         });
         if (ctype_digit($answer)) {
             $items = $result->getItems();
             $item = $items[(int) $answer - 1];
             /* @var \CultureFeed_Cdb_Item_Event $entity */
             $entity = $item->getEntity();
             $details = $entity->getDetails();
             foreach ($details as $detail) {
                 // @todo introduce a command line option to specify the language
                 if ('nl' === $detail->getLanguage()) {
                     $out->writeln($detail->getTitle());
                 }
             }
             $out->writeln($entity->getCdbId());
         }
     } while ('exit' !== $answer);
 }