Beispiel #1
0
 protected function execute(InputInterface $in, OutputInterface $out)
 {
     $sessionFile = $in->getOption('session');
     if (NULL !== $sessionFile) {
         // @todo Catch JsonValidationException and show errors.
         $fileUtility = $this->getFileUtility();
         $sessionFile = $fileUtility->expandPath($sessionFile);
         $this->session = JsonSessionFile::read($sessionFile);
     } else {
         $this->session = new Session();
     }
     $defaults = $this->getDefaults();
     $consumer = $this->session->getConsumerCredentials();
     if (!$consumer) {
         $consumer = new ConsumerCredentials();
         $this->session->setConsumerCredentials($consumer);
     }
     $consumerKey = $in->getOption('consumer-key');
     if ($consumerKey) {
         $consumer->setKey($consumerKey);
     } elseif ('' == $consumer->getKey() && isset($defaults['consumer-key'])) {
         $consumer->setKey($defaults['consumer-key']);
     }
     $consumerSecret = $in->getOption('consumer-secret');
     if ($consumerSecret) {
         $consumer->setSecret($consumerSecret);
     } else {
         if ('' == $consumer->getSecret() && isset($defaults['consumer-secret'])) {
             $consumer->setSecret($defaults['consumer-secret']);
         }
     }
 }
 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);
     }
 }