Example #1
0
 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());
 }
Example #2
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);
     }
 }